Skip to content

Commit

Permalink
update e2e tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Jun 21, 2023
1 parent 806a005 commit 2c796cd
Showing 1 changed file with 22 additions and 61 deletions.
83 changes: 22 additions & 61 deletions tests/integration/misbehaviour.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package integration

import (
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -11,12 +10,6 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
)

const (
trustingPeriod time.Duration = time.Hour * 24 * 7 * 2
ubdPeriod time.Duration = time.Hour * 24 * 7 * 3
maxClockDrift time.Duration = time.Second * 10
)

func (s *CCVTestSuite) TestHandleConsumerMisbehaviour() {
s.SetupCCVChannel(s.path)
// required to have the consumer client revision height greater than 0
Expand Down Expand Up @@ -72,18 +65,9 @@ func (s *CCVTestSuite) TestHandleConsumerMisbehaviour() {
s.Require().True(val.Jailed)
s.Require().True(s.providerApp.GetTestSlashingKeeper().IsTombstoned(s.providerCtx(), provAddr.Address))
}

}

func (s *CCVTestSuite) TestConstructLigthClientEvidence() {

// test cases
// misbehaviour nil
// misbheaviour header 1 nil
// misbehaviour header 2 nil

// misbehaviour no common height

s.SetupCCVChannel(s.path)
// required to have the consumer client revision height greater than 0
s.SendEmptyVSCPacket()
Expand All @@ -94,38 +78,11 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
clientTMValset := tmtypes.NewValidatorSet(s.consumerChain.Vals.Validators)
clientSigners := s.consumerChain.Signers

altValset := tmtypes.NewValidatorSet(s.consumerChain.Vals.Validators[0:2])
altValset := tmtypes.NewValidatorSet(s.consumerChain.Vals.Validators[0:3])
altSigners := make(map[string]tmtypes.PrivValidator, 1)
altSigners[clientTMValset.Validators[0].Address.String()] = clientSigners[clientTMValset.Validators[0].Address.String()]
altSigners[clientTMValset.Validators[1].Address.String()] = clientSigners[clientTMValset.Validators[1].Address.String()]

misb := &ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Header1: s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
altTime,
clientTMValset,
clientTMValset,
clientTMValset,
clientSigners,
),
Header2: s.consumerChain.CreateTMClientHeader(
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
altTime,
altValset,
altValset,
clientTMValset,
altSigners,
),
}

_ = misb

// emptyHeader := &ibctmtypes.Header{}
altSigners[clientTMValset.Validators[2].Address.String()] = clientSigners[clientTMValset.Validators[2].Address.String()]

testCases := []struct {
name string
Expand All @@ -145,9 +102,11 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
altValset,
clientTMValset,
altSigners,
)},
),
},
false,
}, {
},
{
"invalid misbehaviour - Header2 is empty",
&ibctmtypes.Misbehaviour{
Header1: s.consumerChain.CreateTMClientHeader(
Expand All @@ -163,7 +122,8 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
Header2: &ibctmtypes.Header{},
},
false,
}, {
},
{
"invalid misbehaviour - ClientId is empty",
&ibctmtypes.Misbehaviour{
ClientId: "unknown-client-id",
Expand Down Expand Up @@ -216,7 +176,8 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
),
},
true,
}, {
},
{
"light client attack - equivocation",
&ibctmtypes.Misbehaviour{
ClientId: s.path.EndpointA.ClientID,
Expand All @@ -234,7 +195,7 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
altTime,
altTime.Add(time.Minute),
clientTMValset,
clientTMValset,
clientTMValset,
Expand All @@ -245,8 +206,6 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
},
}

// check how it's tested on CometBFTNewExtensionOptionsDecorator

for _, tc := range testCases {
s.Run(tc.name, func() {
ev, err := s.providerApp.GetProviderKeeper().ConstructLigthClientEvidence(
Expand All @@ -255,21 +214,23 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
)
if tc.expPass {
s.NoError(err)
s.Require().Equal(len(altValset.Validators), len(ev.ByzantineValidators))
fmt.Println("headers 2 validators")
// For both lunatic and equivocation attack all the validators
// who signed the bad header (Header2) should be in returned in the evidence
h2Valset := tc.misbehaviour.Header2.ValidatorSet

s.Equal(len(h2Valset.Validators), len(ev.ByzantineValidators))

vs, err := tmtypes.ValidatorSetFromProto(tc.misbehaviour.Header2.ValidatorSet)
s.NoError(err)

for _, v := range tc.misbehaviour.Header2.ValidatorSet.Validators {
fmt.Println(v.String())
}
fmt.Println("byzantine validators")
for _, v := range ev.ByzantineValidators {
fmt.Println(v.String())
idx, _ := vs.GetByAddress(v.Address)
s.True(idx >= 0)
}
// TODO: check that the byzantine validators == altValset.Validators

} else {
s.Error(err)
}
})
}

}

0 comments on commit 2c796cd

Please sign in to comment.