Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return postCheck error to abci client #507

Merged
merged 15 commits into from
Nov 25, 2022
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
ulbqb committed Nov 24, 2022
commit 39aabacb42f55613c56282605d4a6ff42f362ce6
20 changes: 14 additions & 6 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,31 @@ func TestMempoolFilters(t *testing.T) {
emptyTxArr := []types.Tx{[]byte{}}

nopPreFilter := func(tx types.Tx) error { return nil }
nopPostFilter := func(tx types.Tx, res *abci.ResponseCheckTx) error { return nil }

// each table driven test creates numTxsToCreate txs with checkTx, and at the end clears all remaining txs.
// each tx has 20 bytes
tests := []struct {
numTxsToCreate int
preFilter PreCheckFunc
postFilter PostCheckFunc
expectedNumTxs int
}{
{10, nopPreFilter, 10},
{10, PreCheckMaxBytes(10), 0},
{10, PreCheckMaxBytes(20), 0},
{10, PreCheckMaxBytes(22), 10},
{10, PreCheckMaxBytes(30), 10},
{10, nopPreFilter, nopPostFilter, 10},
{10, PreCheckMaxBytes(10), nopPostFilter, 0},
{10, PreCheckMaxBytes(22), nopPostFilter, 10},
{10, nopPreFilter, PostCheckMaxGas(-1), 10},
{10, nopPreFilter, PostCheckMaxGas(0), 10},
{10, nopPreFilter, PostCheckMaxGas(1), 10},
{10, nopPreFilter, PostCheckMaxGas(3000), 10},
{10, PreCheckMaxBytes(10), PostCheckMaxGas(20), 0},
{10, PreCheckMaxBytes(30), PostCheckMaxGas(20), 10},
{10, PreCheckMaxBytes(22), PostCheckMaxGas(1), 10},
{10, PreCheckMaxBytes(22), PostCheckMaxGas(0), 10},
}
for tcIndex, tt := range tests {
err := mempool.Update(newTestBlock(1, emptyTxArr),
abciResponses(len(emptyTxArr), abci.CodeTypeOK), tt.preFilter, nil)
abciResponses(len(emptyTxArr), abci.CodeTypeOK), tt.preFilter, tt.postFilter)
require.NoError(t, err)
checkTxs(t, mempool, tt.numTxsToCreate, UnknownPeerID)
require.Equal(t, tt.expectedNumTxs, mempool.Size(), "mempool had the incorrect size, on test case %d", tcIndex)
Expand Down