tendermint/state/validation_test.go

69 lines
1.7 KiB
Go
Raw Normal View History

2017-12-27 20:03:48 -05:00
package state
import (
"testing"
"github.com/stretchr/testify/require"
2018-07-01 22:36:49 -04:00
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
2017-12-27 20:03:48 -05:00
)
2017-12-28 21:08:39 -05:00
func TestValidateBlock(t *testing.T) {
state, _ := state(1, 1)
2017-12-27 20:03:48 -05:00
2017-12-28 21:08:39 -05:00
blockExec := NewBlockExecutor(dbm.NewMemDB(), log.TestingLogger(), nil, nil, nil)
2017-12-27 20:03:48 -05:00
// proper block must pass
block := makeBlock(state, 1)
2017-12-28 21:08:39 -05:00
err := blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.NoError(t, err)
// wrong chain fails
block = makeBlock(state, 1)
block.ChainID = "not-the-real-one"
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong height fails
block = makeBlock(state, 1)
block.Height += 10
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong total tx fails
block = makeBlock(state, 1)
block.TotalTxs += 10
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong blockid fails
block = makeBlock(state, 1)
block.LastBlockID.PartsHeader.Total += 10
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong app hash fails
block = makeBlock(state, 1)
block.AppHash = []byte("wrong app hash")
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong consensus hash fails
block = makeBlock(state, 1)
block.ConsensusHash = []byte("wrong consensus hash")
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong results hash fails
block = makeBlock(state, 1)
block.LastResultsHash = []byte("wrong results hash")
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
// wrong validators hash fails
block = makeBlock(state, 1)
block.ValidatorsHash = []byte("wrong validators hash")
2017-12-28 21:08:39 -05:00
err = blockExec.ValidateBlock(state, block)
2017-12-27 20:03:48 -05:00
require.Error(t, err)
}