Skip to content

Commit

Permalink
splitting tests for verify header and misbehaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Mar 11, 2022
1 parent 63f3a4f commit d6d9920
Showing 1 changed file with 66 additions and 34 deletions.
100 changes: 66 additions & 34 deletions modules/light-clients/06-solomachine/types/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ func (suite *SoloMachineTestSuite) TestCheckHeaderAndUpdateState() {
}
}

func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
func (suite *SoloMachineTestSuite) TestVerifyClientMessageHeader() {
var (
clientState *types.ClientState
clientMsg exported.Header // TODO: Update to ClientMessage interface
clientState *types.ClientState
)

// test singlesig and multisig public keys
Expand All @@ -198,31 +198,27 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"successful header",
func() {
clientState = solomachine.ClientState()
clientMsg = solomachine.CreateHeader()
},
true,
},
{
"successful misbehaviour",
func() {
clientState = solomachine.ClientState()
clientMsg = solomachine.CreateMisbehaviour()
},
true,
},
{
"invalid client message type",
func() {
clientState = solomachine.ClientState()
clientMsg = &ibctmtypes.Header{}
},
false,
},
{
"wrong sequence in header",
func() {
clientState = solomachine.ClientState()
// store in temp before assigning to interface type
h := solomachine.CreateHeader()
h.Sequence++
Expand All @@ -233,7 +229,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid header Signature",
func() {
clientState = solomachine.ClientState()
h := solomachine.CreateHeader()
h.Signature = suite.GetInvalidProof()
clientMsg = h
Expand All @@ -242,7 +237,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid timestamp in header",
func() {
clientState = solomachine.ClientState()
h := solomachine.CreateHeader()
h.Timestamp--
clientMsg = h
Expand All @@ -251,7 +245,7 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"signature uses wrong sequence",
func() {
clientState = solomachine.ClientState()

solomachine.Sequence++
clientMsg = solomachine.CreateHeader()
},
Expand Down Expand Up @@ -316,19 +310,75 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
false,
},
{
"consensus state public key is nil",
"consensus state public key is nil - header",
func() {
cs := solomachine.ClientState()
cs.ConsensusState.PublicKey = nil
clientState = cs
clientState.ConsensusState.PublicKey = nil
clientMsg = solomachine.CreateHeader()
},
false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
clientState = solomachine.ClientState()

// setup test
tc.setup()

err := clientState.VerifyClientMessage(suite.chainA.Codec, clientMsg)

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}
}
}

func (suite *SoloMachineTestSuite) TestVerifyClientMessageMisbehaviour() {
var (
clientMsg exported.Header // TODO: Update to ClientMessage interface
clientState *types.ClientState
)

// test singlesig and multisig public keys
for _, solomachine := range []*ibctesting.Solomachine{suite.solomachine, suite.solomachineMulti} {

testCases := []struct {
name string
setup func()
expPass bool
}{
{
"successful misbehaviour",
func() {
clientMsg = solomachine.CreateMisbehaviour()
},
true,
},
{
"invalid client message type",
func() {
clientMsg = &ibctmtypes.Header{}
},
false,
},
{
"consensus state pubkey is nil",
func() {
clientState.ConsensusState.PublicKey = nil
clientMsg = solomachine.CreateMisbehaviour()
},
false,
},
{
"invalid SignatureOne SignatureData",
func() {
clientState = solomachine.ClientState()
m := solomachine.CreateMisbehaviour()

m.SignatureOne.Signature = suite.GetInvalidProof()
Expand All @@ -338,7 +388,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid SignatureTwo SignatureData",
func() {
clientState = solomachine.ClientState()
m := solomachine.CreateMisbehaviour()

m.SignatureTwo.Signature = suite.GetInvalidProof()
Expand All @@ -348,7 +397,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid SignatureOne timestamp",
func() {
clientState = solomachine.ClientState()
m := solomachine.CreateMisbehaviour()

m.SignatureOne.Timestamp = 1000000000000
Expand All @@ -358,7 +406,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid SignatureTwo timestamp",
func() {
clientState = solomachine.ClientState()
m := solomachine.CreateMisbehaviour()

m.SignatureTwo.Timestamp = 1000000000000
Expand All @@ -368,8 +415,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid first signature data",
func() {
clientState = solomachine.ClientState()

// store in temp before assigning to interface type
m := solomachine.CreateMisbehaviour()

Expand All @@ -396,8 +441,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"invalid second signature data",
func() {
clientState = solomachine.ClientState()

// store in temp before assigning to interface type
m := solomachine.CreateMisbehaviour()

Expand All @@ -424,7 +467,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"wrong pubkey generates first signature",
func() {
clientState = solomachine.ClientState()
badMisbehaviour := solomachine.CreateMisbehaviour()

// update public key to a new one
Expand All @@ -439,7 +481,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"wrong pubkey generates second signature",
func() {
clientState = solomachine.ClientState()
badMisbehaviour := solomachine.CreateMisbehaviour()

// update public key to a new one
Expand All @@ -454,7 +495,6 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
{
"signatures sign over different sequence",
func() {
clientState = solomachine.ClientState()

// store in temp before assigning to interface type
m := solomachine.CreateMisbehaviour()
Expand Down Expand Up @@ -501,22 +541,14 @@ func (suite *SoloMachineTestSuite) TestVerifyClientMessage() {
},
false,
},
{
"consensus state pubkey is nil",
func() {
cs := solomachine.ClientState()
cs.ConsensusState.PublicKey = nil
clientState = cs
clientMsg = solomachine.CreateMisbehaviour()
},
false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
clientState = solomachine.ClientState()

// setup test
tc.setup()

Expand Down

0 comments on commit d6d9920

Please sign in to comment.