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 573d239 commit d199b75
Showing 1 changed file with 17 additions and 53 deletions.
70 changes: 17 additions & 53 deletions tests/e2e/misbehaviour.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package e2e

import (
"fmt"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -233,7 +197,7 @@ func (s *CCVTestSuite) TestConstructLigthClientEvidence() {
s.consumerChain.ChainID,
int64(clientHeight.RevisionHeight+1),
clientHeight,
altTime,
altTime.Add(time.Minute),
clientTMValset,
clientTMValset,
clientTMValset,
Expand All @@ -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(
Expand All @@ -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)
}
})
}

}

0 comments on commit d199b75

Please sign in to comment.