github.com/evdatsion/aphelion-dpos-bft@v0.32.1/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  	cmn "github.com/evdatsion/aphelion-dpos-bft/libs/common"
    11  	dbm "github.com/evdatsion/aphelion-dpos-bft/libs/db"
    12  	sm "github.com/evdatsion/aphelion-dpos-bft/state"
    13  	"github.com/evdatsion/aphelion-dpos-bft/types"
    14  )
    15  
    16  func TestTxFilter(t *testing.T) {
    17  	genDoc := randomGenesisDoc()
    18  	genDoc.ConsensusParams.Block.MaxBytes = 3000
    19  
    20  	// Max size of Txs is much smaller than size of block,
    21  	// since we need to account for commits and evidence.
    22  	testCases := []struct {
    23  		tx    types.Tx
    24  		isErr bool
    25  	}{
    26  		{types.Tx(cmn.RandBytes(250)), false},
    27  		{types.Tx(cmn.RandBytes(1809)), false},
    28  		{types.Tx(cmn.RandBytes(1810)), false},
    29  		{types.Tx(cmn.RandBytes(1811)), true},
    30  		{types.Tx(cmn.RandBytes(1812)), true},
    31  		{types.Tx(cmn.RandBytes(3000)), true},
    32  	}
    33  
    34  	for i, tc := range testCases {
    35  		stateDB := dbm.NewDB("state", "memdb", os.TempDir())
    36  		state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
    37  		require.NoError(t, err)
    38  
    39  		f := sm.TxPreCheck(state)
    40  		if tc.isErr {
    41  			assert.NotNil(t, f(tc.tx), "#%v", i)
    42  		} else {
    43  			assert.Nil(t, f(tc.tx), "#%v", i)
    44  		}
    45  	}
    46  }