gitlab.com/gpdionisio/tendermint@v0.34.19-dev2/state/tx_filter_test.go (about) 1 package state_test 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 10 dbm "github.com/tendermint/tm-db" 11 12 tmrand "github.com/tendermint/tendermint/libs/rand" 13 sm "github.com/tendermint/tendermint/state" 14 "github.com/tendermint/tendermint/types" 15 ) 16 17 func TestTxFilter(t *testing.T) { 18 genDoc := randomGenesisDoc() 19 genDoc.ConsensusParams.Block.MaxBytes = 3000 20 genDoc.ConsensusParams.Evidence.MaxBytes = 1500 21 22 // Max size of Txs is much smaller than size of block, 23 // since we need to account for commits and evidence. 24 testCases := []struct { 25 tx types.Tx 26 isErr bool 27 }{ 28 {types.Tx(tmrand.Bytes(2155)), false}, 29 {types.Tx(tmrand.Bytes(2156)), true}, 30 {types.Tx(tmrand.Bytes(3000)), true}, 31 } 32 33 for i, tc := range testCases { 34 stateDB, err := dbm.NewDB("state", "memdb", os.TempDir()) 35 require.NoError(t, err) 36 stateStore := sm.NewStore(stateDB) 37 state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc) 38 require.NoError(t, err) 39 40 f := sm.TxPreCheck(state) 41 if tc.isErr { 42 assert.NotNil(t, f(tc.tx), "#%v", i) 43 } else { 44 assert.Nil(t, f(tc.tx), "#%v", i) 45 } 46 } 47 }