Skip to content

Commit

Permalink
chore: fix message_handler_integration_test
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Nov 13, 2023
1 parent 866a75a commit cb6b957
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/grandpa/message_handler_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,11 @@ func TestMessageHandler_VerifyBlockJustification_WithEquivocatoryVotes(t *testin
just := newJustification(round, testHash, number, precommits)
data, err := scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)

gotRound, gotSetID, err := gs.VerifyBlockJustification(testHash, data)
require.NoError(t, err)
require.Equal(t, round, gotRound)
require.Equal(t, setID, gotSetID)
}

func TestMessageHandler_VerifyBlockJustification(t *testing.T) {
Expand Down Expand Up @@ -840,16 +843,18 @@ func TestMessageHandler_VerifyBlockJustification(t *testing.T) {
just := newJustification(round, testHash, number, precommits)
data, err := scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
gotRound, gotSetID, err := gs.VerifyBlockJustification(testHash, data)
require.NoError(t, err)
require.Equal(t, round, gotRound)
require.Equal(t, setID, gotSetID)

// use wrong hash, shouldn't verify
precommits = buildTestJustification(t, 2, round+1, setID, kr, precommit)
just = newJustification(round+1, testHash, number, precommits)
just.Commit.Precommits[0].Vote.Hash = testHeader2.Hash()
data, err = scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
_, _, err = gs.VerifyBlockJustification(testHash, data)
require.Equal(t, ErrPrecommitBlockMismatch, err)
}

Expand Down Expand Up @@ -899,31 +904,31 @@ func TestMessageHandler_VerifyBlockJustification_invalid(t *testing.T) {
just.Commit.Precommits[0].Vote.Hash = genhash
data, err := scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
_, _, err = gs.VerifyBlockJustification(testHash, data)
require.Equal(t, ErrPrecommitBlockMismatch, err)

// use wrong round, shouldn't verify
precommits = buildTestJustification(t, 2, round+1, setID, kr, precommit)
just = newJustification(round+2, testHash, number, precommits)
data, err = scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
_, _, err = gs.VerifyBlockJustification(testHash, data)
require.Equal(t, ErrInvalidSignature, err)

// add authority not in set, shouldn't verify
precommits = buildTestJustification(t, len(auths)+1, round+1, setID, kr, precommit)
just = newJustification(round+1, testHash, number, precommits)
data, err = scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
_, _, err = gs.VerifyBlockJustification(testHash, data)
require.Equal(t, ErrAuthorityNotInSet, err)

// not enough signatures, shouldn't verify
precommits = buildTestJustification(t, 1, round+1, setID, kr, precommit)
just = newJustification(round+1, testHash, number, precommits)
data, err = scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
_, _, err = gs.VerifyBlockJustification(testHash, data)
require.Equal(t, ErrMinVotesNotMet, err)

// mismatch justification header and block header
Expand All @@ -932,7 +937,7 @@ func TestMessageHandler_VerifyBlockJustification_invalid(t *testing.T) {
data, err = scale.Marshal(*just)
require.NoError(t, err)
otherHeader := types.NewEmptyHeader()
err = gs.VerifyBlockJustification(otherHeader.Hash(), data)
_, _, err = gs.VerifyBlockJustification(otherHeader.Hash(), data)
require.ErrorIs(t, err, ErrJustificationMismatch)

expectedErr := fmt.Sprintf("%s: justification %s and block hash %s", ErrJustificationMismatch,
Expand Down Expand Up @@ -1001,7 +1006,7 @@ func TestMessageHandler_VerifyBlockJustification_ErrFinalisedBlockMismatch(t *te
just := newJustification(round, testHash, number, precommits)
data, err := scale.Marshal(*just)
require.NoError(t, err)
err = gs.VerifyBlockJustification(testHash, data)
_, _, err = gs.VerifyBlockJustification(testHash, data)
require.ErrorIs(t, err, errFinalisedBlocksMismatch)
}

Expand Down Expand Up @@ -1578,7 +1583,7 @@ func TestService_VerifyBlockJustification(t *testing.T) { //nolint
blockState: tt.fields.blockStateBuilder(ctrl),
grandpaState: tt.fields.grandpaStateBuilder(ctrl),
}
err := s.VerifyBlockJustification(tt.args.hash, tt.args.justification)
_, _, err := s.VerifyBlockJustification(tt.args.hash, tt.args.justification)
if tt.wantErr != nil {
assert.ErrorContains(t, err, tt.wantErr.Error())
} else {
Expand Down

0 comments on commit cb6b957

Please sign in to comment.