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.

57 lines
1.5 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. // Max size of Txs is much smaller than size of block,
  17. // since we need to account for commits and evidence.
  18. testCases := []struct {
  19. tx types.Tx
  20. isErr bool
  21. }{
  22. {types.Tx(cmn.RandBytes(250)), false},
  23. {types.Tx(cmn.RandBytes(1809)), false},
  24. {types.Tx(cmn.RandBytes(1810)), false},
  25. {types.Tx(cmn.RandBytes(1811)), true},
  26. {types.Tx(cmn.RandBytes(1812)), true},
  27. {types.Tx(cmn.RandBytes(3000)), true},
  28. }
  29. for i, tc := range testCases {
  30. stateDB := dbm.NewDB("state", "memdb", os.TempDir())
  31. state, err := LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  32. require.NoError(t, err)
  33. f := TxPreCheck(state)
  34. if tc.isErr {
  35. assert.NotNil(t, f(tc.tx), "#%v", i)
  36. } else {
  37. assert.Nil(t, f(tc.tx), "#%v", i)
  38. }
  39. }
  40. }
  41. func randomGenesisDoc() *types.GenesisDoc {
  42. pubkey := ed25519.GenPrivKey().PubKey()
  43. return &types.GenesisDoc{
  44. GenesisTime: tmtime.Now(),
  45. ChainID: "abc",
  46. Validators: []types.GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}},
  47. ConsensusParams: types.DefaultConsensusParams(),
  48. }
  49. }