From d199b75d8d831efd4c2a015635038ace10bc517e Mon Sep 17 00:00:00 2001 From: Simon Noetzlin Date: Wed, 21 Jun 2023 14:30:21 +0200 Subject: [PATCH] update e2e tests' --- tests/e2e/misbehaviour.go | 70 ++++++++++----------------------------- 1 file changed, 17 insertions(+), 53 deletions(-) diff --git a/tests/e2e/misbehaviour.go b/tests/e2e/misbehaviour.go index 5c6347dd5c..6fcffb7066 100644 --- a/tests/e2e/misbehaviour.go +++ b/tests/e2e/misbehaviour.go @@ -1,7 +1,6 @@ package e2e import ( - "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -67,22 +66,14 @@ func (s *CCVTestSuite) TestHandleConsumerMisbehaviour() { consuAddr := sdk.ConsAddress(v.Address.Bytes()) provAddr := s.providerApp.GetProviderKeeper().GetProviderAddrFromConsumerAddr(s.providerCtx(), s.consumerChain.ChainID, consuAddr) val, ok := s.providerApp.GetE2eStakingKeeper().GetValidatorByConsAddr(s.providerCtx(), provAddr) - s.Require().True(ok) - s.Require().True(val.Jailed) - s.Require().True(s.providerApp.GetE2eSlashingKeeper().IsTombstoned(s.providerCtx(), provAddr)) + s.True(ok) + s.True(val.Jailed) + s.True(s.providerApp.GetE2eSlashingKeeper().IsTombstoned(s.providerCtx(), provAddr)) } } 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() @@ -93,38 +84,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 @@ -233,7 +197,7 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() { s.consumerChain.ChainID, int64(clientHeight.RevisionHeight+1), clientHeight, - altTime, + altTime.Add(time.Minute), clientTMValset, clientTMValset, clientTMValset, @@ -244,8 +208,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( @@ -254,21 +216,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) } }) } - }