github.com/Finschia/ostracon@v1.1.5/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/Finschia/ostracon/libs/rand"
    13  	sm "github.com/Finschia/ostracon/state"
    14  	"github.com/Finschia/ostracon/types"
    15  	vrf "github.com/oasisprotocol/curve25519-voi/primitives/ed25519/extra/ecvrf"
    16  )
    17  
    18  func TestTxFilter(t *testing.T) {
    19  	genDoc := randomGenesisDoc()
    20  	genDoc.ConsensusParams.Block.MaxBytes = 3035
    21  	genDoc.ConsensusParams.Evidence.MaxBytes = 1500
    22  
    23  	// Max size of Txs is much smaller than size of block,
    24  	// since we need to account for commits and evidence.
    25  	testCases := []struct {
    26  		tx    types.Tx
    27  		isErr bool
    28  	}{
    29  		{types.Tx(tmrand.Bytes(2178 - vrf.ProofSize)), false},
    30  		{types.Tx(tmrand.Bytes(2189 - vrf.ProofSize)), true},
    31  		{types.Tx(tmrand.Bytes(3000)), true},
    32  	}
    33  
    34  	for i, tc := range testCases {
    35  		stateDB, err := dbm.NewDB("state", "memdb", os.TempDir())
    36  		require.NoError(t, err)
    37  		stateStore := sm.NewStore(stateDB, sm.StoreOptions{
    38  			DiscardABCIResponses: false,
    39  		})
    40  		state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
    41  		require.NoError(t, err)
    42  
    43  		f := sm.TxPreCheck(state)
    44  		if tc.isErr {
    45  			assert.NotNil(t, f(tc.tx), "#%v", i)
    46  		} else {
    47  			assert.Nil(t, f(tc.tx), "#%v", i)
    48  		}
    49  	}
    50  }