|
|
@ -55,6 +55,7 @@ func TestValidateBlockHeader(t *testing.T) { |
|
|
|
{"ChainID wrong", func(block *types.Block) { block.ChainID = "not-the-real-one" }}, |
|
|
|
{"Height wrong", func(block *types.Block) { block.Height += 10 }}, |
|
|
|
{"Time wrong", func(block *types.Block) { block.Time = block.Time.Add(-time.Second * 1) }}, |
|
|
|
{"Time wrong 2", func(block *types.Block) { block.Time = block.Time.Add(time.Second * 1) }}, |
|
|
|
|
|
|
|
{"LastBlockID wrong", func(block *types.Block) { block.LastBlockID.PartSetHeader.Total += 10 }}, |
|
|
|
{"LastCommitHash wrong", func(block *types.Block) { block.LastCommitHash = wrongHash }}, |
|
|
@ -69,6 +70,11 @@ func TestValidateBlockHeader(t *testing.T) { |
|
|
|
{"EvidenceHash wrong", func(block *types.Block) { block.EvidenceHash = wrongHash }}, |
|
|
|
{"Proposer wrong", func(block *types.Block) { block.ProposerAddress = ed25519.GenPrivKey().PubKey().Address() }}, |
|
|
|
{"Proposer invalid", func(block *types.Block) { block.ProposerAddress = []byte("wrong size") }}, |
|
|
|
|
|
|
|
{"first LastCommit contains signatures", func(block *types.Block) { |
|
|
|
block.LastCommit = types.NewCommit(0, 0, types.BlockID{}, []types.CommitSig{types.NewCommitSigAbsent()}) |
|
|
|
block.LastCommitHash = block.LastCommit.Hash() |
|
|
|
}}, |
|
|
|
} |
|
|
|
|
|
|
|
// Build up state for multiple heights
|
|
|
@ -81,6 +87,7 @@ func TestValidateBlockHeader(t *testing.T) { |
|
|
|
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, proposerAddr) |
|
|
|
tc.malleateBlock(block) |
|
|
|
err := blockExec.ValidateBlock(state, block) |
|
|
|
t.Logf("%s: %v", tc.name, err) |
|
|
|
require.Error(t, err, tc.name) |
|
|
|
} |
|
|
|
|
|
|
@ -91,6 +98,19 @@ func TestValidateBlockHeader(t *testing.T) { |
|
|
|
state, _, lastCommit, err = makeAndCommitGoodBlock(state, height, lastCommit, proposerAddr, blockExec, privVals, nil) |
|
|
|
require.NoError(t, err, "height %d", height) |
|
|
|
} |
|
|
|
|
|
|
|
nextHeight := validationTestsStopHeight |
|
|
|
block, _ := state.MakeBlock( |
|
|
|
nextHeight, |
|
|
|
makeTxs(nextHeight), |
|
|
|
lastCommit, |
|
|
|
nil, |
|
|
|
state.Validators.GetProposer().Address, |
|
|
|
) |
|
|
|
state.InitialHeight = nextHeight + 1 |
|
|
|
err := blockExec.ValidateBlock(state, block) |
|
|
|
require.Error(t, err, "expected an error when state is ahead of block") |
|
|
|
assert.Contains(t, err.Error(), "lower than initial height") |
|
|
|
} |
|
|
|
|
|
|
|
func TestValidateBlockCommit(t *testing.T) { |
|
|
|