|
@ -4,61 +4,65 @@ import ( |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
dbm "github.com/tendermint/tmlibs/db" |
|
|
|
|
|
"github.com/tendermint/tmlibs/log" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func _TestValidateBlock(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestValidateBlock(t *testing.T) { |
|
|
state := state() |
|
|
state := state() |
|
|
|
|
|
|
|
|
|
|
|
blockExec := NewBlockExecutor(dbm.NewMemDB(), log.TestingLogger(), nil, nil, nil) |
|
|
|
|
|
|
|
|
// proper block must pass
|
|
|
// proper block must pass
|
|
|
block := makeBlock(state, 1) |
|
|
block := makeBlock(state, 1) |
|
|
err := ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err := blockExec.ValidateBlock(state, block) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
// wrong chain fails
|
|
|
// wrong chain fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.ChainID = "not-the-real-one" |
|
|
block.ChainID = "not-the-real-one" |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong height fails
|
|
|
// wrong height fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.Height += 10 |
|
|
block.Height += 10 |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong total tx fails
|
|
|
// wrong total tx fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.TotalTxs += 10 |
|
|
block.TotalTxs += 10 |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong blockid fails
|
|
|
// wrong blockid fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.LastBlockID.PartsHeader.Total += 10 |
|
|
block.LastBlockID.PartsHeader.Total += 10 |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong app hash fails
|
|
|
// wrong app hash fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.AppHash = []byte("wrong app hash") |
|
|
block.AppHash = []byte("wrong app hash") |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong consensus hash fails
|
|
|
// wrong consensus hash fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.ConsensusHash = []byte("wrong consensus hash") |
|
|
block.ConsensusHash = []byte("wrong consensus hash") |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong results hash fails
|
|
|
// wrong results hash fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.LastResultsHash = []byte("wrong results hash") |
|
|
block.LastResultsHash = []byte("wrong results hash") |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// wrong validators hash fails
|
|
|
// wrong validators hash fails
|
|
|
block = makeBlock(state, 1) |
|
|
block = makeBlock(state, 1) |
|
|
block.ValidatorsHash = []byte("wrong validators hash") |
|
|
block.ValidatorsHash = []byte("wrong validators hash") |
|
|
err = ValidateBlock(state, block) |
|
|
|
|
|
|
|
|
err = blockExec.ValidateBlock(state, block) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
} |
|
|
} |