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

Function TestSignedHeaderValidateBasic

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

Source from the content-addressed store, hash-verified

110}
111
112func TestSignedHeaderValidateBasic(t *testing.T) {
113 commit := randCommit(time.Now())
114 chainID := "𠜎"
115 timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
116 h := Header{
117 Version: version.Consensus{Block: version.BlockProtocol, App: math.MaxInt64},
118 ChainID: chainID,
119 Height: commit.Height,
120 Time: timestamp,
121 LastBlockID: commit.BlockID,
122 LastCommitHash: commit.Hash(),
123 DataHash: commit.Hash(),
124 ValidatorsHash: commit.Hash(),
125 NextValidatorsHash: commit.Hash(),
126 ConsensusHash: commit.Hash(),
127 AppHash: commit.Hash(),
128 LastResultsHash: commit.Hash(),
129 EvidenceHash: commit.Hash(),
130 ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
131 }
132
133 validSignedHeader := SignedHeader{Header: &h, Commit: commit}
134 validSignedHeader.Commit.BlockID.Hash = validSignedHeader.Hash()
135 invalidSignedHeader := SignedHeader{}
136
137 testCases := []struct {
138 testName string
139 shHeader *Header
140 shCommit *Commit
141 expectErr bool
142 }{
143 {"Valid Signed Header", validSignedHeader.Header, validSignedHeader.Commit, false},
144 {"Invalid Signed Header", invalidSignedHeader.Header, validSignedHeader.Commit, true},
145 {"Invalid Signed Header", validSignedHeader.Header, invalidSignedHeader.Commit, true},
146 }
147
148 for _, tc := range testCases {
149 tc := tc
150 t.Run(tc.testName, func(t *testing.T) {
151 sh := SignedHeader{
152 Header: tc.shHeader,
153 Commit: tc.shCommit,
154 }
155 err := sh.ValidateBasic(validSignedHeader.Header.ChainID)
156 assert.Equalf(
157 t,
158 tc.expectErr,
159 err != nil,
160 "Validate Basic had an unexpected result",
161 err,
162 )
163 })
164 }
165}

Callers

nothing calls this directly

Calls 5

ValidateBasicMethod · 0.95
AddressHashFunction · 0.92
randCommitFunction · 0.85
HashMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…