You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. package state
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/crypto/ed25519"
  8. cmn "github.com/tendermint/tendermint/libs/common"
  9. dbm "github.com/tendermint/tendermint/libs/db"
  10. "github.com/tendermint/tendermint/types"
  11. tmtime "github.com/tendermint/tendermint/types/time"
  12. )
  13. func TestTxFilter(t *testing.T) {
  14. genDoc := randomGenesisDoc()
  15. genDoc.ConsensusParams.BlockSize.MaxBytes = 3000
  16. testCases := []struct {
  17. tx types.Tx
  18. isTxValid bool
  19. }{
  20. {types.Tx(cmn.RandBytes(250)), true},
  21. {types.Tx(cmn.RandBytes(3001)), false},
  22. }
  23. for i, tc := range testCases {
  24. stateDB := dbm.NewDB("state", "memdb", os.TempDir())
  25. state, err := LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  26. require.NoError(t, err)
  27. f := TxFilter(state)
  28. assert.Equal(t, tc.isTxValid, f(tc.tx), "#%v", i)
  29. }
  30. }
  31. func randomGenesisDoc() *types.GenesisDoc {
  32. pubkey := ed25519.GenPrivKey().PubKey()
  33. return &types.GenesisDoc{
  34. GenesisTime: tmtime.Now(),
  35. ChainID: "abc",
  36. Validators: []types.GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}},
  37. ConsensusParams: types.DefaultConsensusParams(),
  38. }
  39. }