(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func 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 | |
| 167 | func TestProposalProtoBuf(t *testing.T) { |
| 168 | proposal := NewProposal(1, 2, 3, makeBlockID([]byte("hash"), 2, []byte("part_set_hash"))) |
nothing calls this directly
no test coverage detected
searching dependent graphs…