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

Function TestProposalValidateBasic

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

Source from the content-addressed store, hash-verified

124}
125
126func TestProposalValidateBasic(t *testing.T) {
127
128 privVal := NewMockPV()
129 testCases := []struct {
130 testName string
131 malleateProposal func(*Proposal)
132 expectErr bool
133 }{
134 {"Good Proposal", func(p *Proposal) {}, false},
135 {"Invalid Type", func(p *Proposal) { p.Type = tmproto.PrecommitType }, true},
136 {"Invalid Height", func(p *Proposal) { p.Height = -1 }, true},
137 {"Invalid Round", func(p *Proposal) { p.Round = -1 }, true},
138 {"Invalid POLRound", func(p *Proposal) { p.POLRound = -2 }, true},
139 {"Invalid BlockId", func(p *Proposal) {
140 p.BlockID = BlockID{[]byte{1, 2, 3}, PartSetHeader{111, []byte("blockparts")}}
141 }, true},
142 {"Invalid Signature", func(p *Proposal) {
143 p.Signature = make([]byte, 0)
144 }, true},
145 {"Too big Signature", func(p *Proposal) {
146 p.Signature = make([]byte, MaxSignatureSize+1)
147 }, true},
148 }
149 blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
150
151 for _, tc := range testCases {
152 tc := tc
153 t.Run(tc.testName, func(t *testing.T) {
154 prop := NewProposal(
155 4, 2, 2,
156 blockID)
157 p := prop.ToProto()
158 err := privVal.SignProposal(context.Background(), "test_chain_id", p)
159 prop.Signature = p.Signature
160 require.NoError(t, err)
161 tc.malleateProposal(prop)
162 assert.Equal(t, tc.expectErr, prop.ValidateBasic() != nil, "Validate Basic had an unexpected result")
163 })
164 }
165}
166
167func TestProposalProtoBuf(t *testing.T) {
168 proposal := NewProposal(1, 2, 3, makeBlockID([]byte("hash"), 2, []byte("part_set_hash")))

Callers

nothing calls this directly

Calls 9

ToProtoMethod · 0.95
SignProposalMethod · 0.95
ValidateBasicMethod · 0.95
SumFunction · 0.92
NewMockPVFunction · 0.85
NewProposalFunction · 0.85
makeBlockIDFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…