MCPcopy Create free account
hub / github.com/tendermint/tendermint / TestLightBlockValidateBasic

Function TestLightBlockValidateBasic

types/light_test.go:14–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func 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
59func TestLightBlockProtobuf(t *testing.T) {
60 header := MakeRandHeader()

Callers

nothing calls this directly

Calls 7

ValidateBasicMethod · 0.95
MakeRandHeaderFunction · 0.85
randCommitFunction · 0.85
randValidatorPrivValSetFunction · 0.85
HashMethod · 0.65
CopyMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…