forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx_filter_test.go
47 lines (40 loc) · 1.13 KB
/
tx_filter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package state_test
import (
"os"
"testing"
"github.com/stretchr/testify/require"
dbm "github.com/cometbft/cometbft-db"
cmtrand "github.com/cometbft/cometbft/internal/rand"
sm "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/types"
)
func TestTxFilter(t *testing.T) {
genDoc := randomGenesisDoc()
genDoc.ConsensusParams.Block.MaxBytes = 3000
genDoc.ConsensusParams.Evidence.MaxBytes = 1500
// Max size of Txs is much smaller than size of block,
// since we need to account for commits and evidence.
testCases := []struct {
tx types.Tx
isErr bool
}{
{types.Tx(cmtrand.Bytes(2122)), false},
{types.Tx(cmtrand.Bytes(2123)), true},
{types.Tx(cmtrand.Bytes(3000)), true},
}
for i, tc := range testCases {
stateDB, err := dbm.NewDB("state", "memdb", os.TempDir())
require.NoError(t, err)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
require.NoError(t, err)
f := sm.TxPreCheck(state)
if tc.isErr {
require.Error(t, f(tc.tx), "#%v", i)
} else {
require.NoError(t, f(tc.tx), "#%v", i)
}
}
}