|
|
@ -170,7 +170,8 @@ func TestMempoolFilters(t *testing.T) { |
|
|
|
{10, PreCheckMaxBytes(20), PostCheckMaxGas(0), 0}, |
|
|
|
} |
|
|
|
for tcIndex, tt := range tests { |
|
|
|
mempool.Update(1, emptyTxArr, abciResponses(len(emptyTxArr), abci.CodeTypeOK), tt.preFilter, tt.postFilter) |
|
|
|
err := mempool.Update(1, emptyTxArr, 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) |
|
|
|
mempool.Flush() |
|
|
@ -185,8 +186,9 @@ func TestMempoolUpdate(t *testing.T) { |
|
|
|
|
|
|
|
// 1. Adds valid txs to the cache
|
|
|
|
{ |
|
|
|
mempool.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
err := mempool.CheckTx([]byte{0x01}, nil, TxInfo{}) |
|
|
|
err := mempool.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
err = mempool.CheckTx([]byte{0x01}, nil, TxInfo{}) |
|
|
|
if assert.Error(t, err) { |
|
|
|
assert.Equal(t, ErrTxInCache, err) |
|
|
|
} |
|
|
@ -196,7 +198,8 @@ func TestMempoolUpdate(t *testing.T) { |
|
|
|
{ |
|
|
|
err := mempool.CheckTx([]byte{0x02}, nil, TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
mempool.Update(1, []types.Tx{[]byte{0x02}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
err = mempool.Update(1, []types.Tx{[]byte{0x02}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.Zero(t, mempool.Size()) |
|
|
|
} |
|
|
|
|
|
|
@ -204,11 +207,12 @@ func TestMempoolUpdate(t *testing.T) { |
|
|
|
{ |
|
|
|
err := mempool.CheckTx([]byte{0x03}, nil, TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
mempool.Update(1, []types.Tx{[]byte{0x03}}, abciResponses(1, 1), nil, nil) |
|
|
|
err = mempool.Update(1, []types.Tx{[]byte{0x03}}, abciResponses(1, 1), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.Zero(t, mempool.Size()) |
|
|
|
|
|
|
|
err = mempool.CheckTx([]byte{0x03}, nil, TxInfo{}) |
|
|
|
assert.NoError(t, err) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -385,7 +389,8 @@ func TestMempoolCloseWAL(t *testing.T) { |
|
|
|
mempool, cleanup := newMempoolWithAppAndConfig(cc, wcfg) |
|
|
|
defer cleanup() |
|
|
|
mempool.height = 10 |
|
|
|
mempool.InitWAL() |
|
|
|
err = mempool.InitWAL() |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
// 4. Ensure that the directory contains the WAL file
|
|
|
|
m2, err := filepath.Glob(filepath.Join(rootDir, "*")) |
|
|
@ -393,7 +398,8 @@ func TestMempoolCloseWAL(t *testing.T) { |
|
|
|
require.Equal(t, 1, len(m2), "expecting the wal match in") |
|
|
|
|
|
|
|
// 5. Write some contents to the WAL
|
|
|
|
mempool.CheckTx(types.Tx([]byte("foo")), nil, TxInfo{}) |
|
|
|
err = mempool.CheckTx(types.Tx([]byte("foo")), nil, TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
walFilepath := mempool.wal.Path |
|
|
|
sum1 := checksumFile(walFilepath, t) |
|
|
|
|
|
|
@ -403,7 +409,8 @@ func TestMempoolCloseWAL(t *testing.T) { |
|
|
|
// 7. Invoke CloseWAL() and ensure it discards the
|
|
|
|
// WAL thus any other write won't go through.
|
|
|
|
mempool.CloseWAL() |
|
|
|
mempool.CheckTx(types.Tx([]byte("bar")), nil, TxInfo{}) |
|
|
|
err = mempool.CheckTx(types.Tx([]byte("bar")), nil, TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
sum2 := checksumFile(walFilepath, t) |
|
|
|
require.Equal(t, sum1, sum2, "expected no change to the WAL after invoking CloseWAL() since it was discarded") |
|
|
|
|
|
|
@ -481,7 +488,8 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
assert.EqualValues(t, 1, mempool.TxsBytes()) |
|
|
|
|
|
|
|
// 3. zero again after tx is removed by Update
|
|
|
|
mempool.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
err = mempool.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.EqualValues(t, 0, mempool.TxsBytes()) |
|
|
|
|
|
|
|
// 4. zero after Flush
|
|
|
@ -517,7 +525,11 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus")) |
|
|
|
err = appConnCon.Start() |
|
|
|
require.Nil(t, err) |
|
|
|
defer appConnCon.Stop() |
|
|
|
t.Cleanup(func() { |
|
|
|
if err := appConnCon.Stop(); err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
}) |
|
|
|
res, err := appConnCon.DeliverTxSync(abci.RequestDeliverTx{Tx: txBytes}) |
|
|
|
require.NoError(t, err) |
|
|
|
require.EqualValues(t, 0, res.Code) |
|
|
@ -526,7 +538,8 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
require.NotEmpty(t, res2.Data) |
|
|
|
|
|
|
|
// Pretend like we committed nothing so txBytes gets rechecked and removed.
|
|
|
|
mempool.Update(1, []types.Tx{}, abciResponses(0, abci.CodeTypeOK), nil, nil) |
|
|
|
err = mempool.Update(1, []types.Tx{}, abciResponses(0, abci.CodeTypeOK), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.EqualValues(t, 0, mempool.TxsBytes()) |
|
|
|
|
|
|
|
// 7. Test RemoveTxByKey function
|
|
|
@ -548,7 +561,11 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) { |
|
|
|
sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6)) |
|
|
|
app := kvstore.NewApplication() |
|
|
|
cc, server := newRemoteApp(t, sockPath, app) |
|
|
|
defer server.Stop() |
|
|
|
t.Cleanup(func() { |
|
|
|
if err := server.Stop(); err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
}) |
|
|
|
config := cfg.ResetTestRoot("mempool_test") |
|
|
|
mempool, cleanup := newMempoolWithAppAndConfig(cc, config) |
|
|
|
defer cleanup() |
|
|
@ -570,7 +587,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) { |
|
|
|
tx := txs[txNum] |
|
|
|
|
|
|
|
// this will err with ErrTxInCache many times ...
|
|
|
|
mempool.CheckTx(tx, nil, TxInfo{SenderID: uint16(peerID)}) |
|
|
|
mempool.CheckTx(tx, nil, TxInfo{SenderID: uint16(peerID)}) //nolint: errcheck // will error
|
|
|
|
} |
|
|
|
err := mempool.FlushAppConn() |
|
|
|
require.NoError(t, err) |
|
|
@ -597,7 +614,7 @@ func newRemoteApp( |
|
|
|
} |
|
|
|
func checksumIt(data []byte) string { |
|
|
|
h := sha256.New() |
|
|
|
h.Write(data) |
|
|
|
h.Write(data) //nolint: errcheck // ignore errcheck
|
|
|
|
return fmt.Sprintf("%x", h.Sum(nil)) |
|
|
|
} |
|
|
|
|
|
|
|