(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestLightBlockValidateBasic(t *testing.T) { |
| 15 | header := MakeRandHeader() |
| 16 | commit := randCommit(time.Now()) |
| 17 | vals, _ := randValidatorPrivValSet(5, 1) |
| 18 | header.Height = commit.Height |
| 19 | header.LastBlockID = commit.BlockID |
| 20 | header.ValidatorsHash = vals.Hash() |
| 21 | header.Version.Block = version.BlockProtocol |
| 22 | vals2, _ := randValidatorPrivValSet(3, 1) |
| 23 | vals3 := vals.Copy() |
| 24 | vals3.Proposer = &Validator{} |
| 25 | commit.BlockID.Hash = header.Hash() |
| 26 | |
| 27 | sh := &SignedHeader{ |
| 28 | Header: &header, |
| 29 | Commit: commit, |
| 30 | } |
| 31 | |
| 32 | testCases := []struct { |
| 33 | name string |
| 34 | sh *SignedHeader |
| 35 | vals *ValidatorSet |
| 36 | expectErr bool |
| 37 | }{ |
| 38 | {"valid light block", sh, vals, false}, |
| 39 | {"hashes don't match", sh, vals2, true}, |
| 40 | {"invalid validator set", sh, vals3, true}, |
| 41 | {"invalid signed header", &SignedHeader{Header: &header, Commit: randCommit(time.Now())}, vals, true}, |
| 42 | } |
| 43 | |
| 44 | for _, tc := range testCases { |
| 45 | lightBlock := LightBlock{ |
| 46 | SignedHeader: tc.sh, |
| 47 | ValidatorSet: tc.vals, |
| 48 | } |
| 49 | err := lightBlock.ValidateBasic(header.ChainID) |
| 50 | if tc.expectErr { |
| 51 | assert.Error(t, err, tc.name) |
| 52 | } else { |
| 53 | assert.NoError(t, err, tc.name) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | |
| 59 | func TestLightBlockProtobuf(t *testing.T) { |
| 60 | header := MakeRandHeader() |
nothing calls this directly
no test coverage detected
searching dependent graphs…