types: remove panic from block methods (#7501)

This commit is contained in:
Sam Kleinman
2022-01-03 16:14:26 -05:00
committed by GitHub
parent 5f85c8f536
commit 430817d9e9
21 changed files with 413 additions and 192 deletions
+10 -5
View File
@@ -316,14 +316,16 @@ func TestCreateProposalBlock(t *testing.T) {
)
commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
block, _ := blockExec.CreateProposalBlock(
block, _, err := blockExec.CreateProposalBlock(
height,
state, commit,
proposerAddr,
)
require.NoError(t, err)
// check that the part set does not exceed the maximum block size
partSet := block.MakePartSet(partSize)
partSet, err := block.MakePartSet(partSize)
require.NoError(t, err)
assert.Less(t, partSet.ByteSize(), int64(maxBytes))
partSetFromHeader := types.NewPartSetFromHeader(partSet.Header())
@@ -387,18 +389,20 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
)
commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
block, _ := blockExec.CreateProposalBlock(
block, _, err := blockExec.CreateProposalBlock(
height,
state, commit,
proposerAddr,
)
require.NoError(t, err)
pb, err := block.ToProto()
require.NoError(t, err)
assert.Less(t, int64(pb.Size()), maxBytes)
// check that the part set does not exceed the maximum block size
partSet := block.MakePartSet(partSize)
partSet, err := block.MakePartSet(partSize)
require.NoError(t, err)
assert.EqualValues(t, partSet.ByteSize(), int64(pb.Size()))
}
@@ -494,11 +498,12 @@ func TestMaxProposalBlockSize(t *testing.T) {
commit.Signatures = append(commit.Signatures, cs)
}
block, partSet := blockExec.CreateProposalBlock(
block, partSet, err := blockExec.CreateProposalBlock(
math.MaxInt64,
state, commit,
proposerAddr,
)
require.NoError(t, err)
// this ensures that the header is at max size
block.Header.Time = timestamp