|
|
@ -78,7 +78,7 @@ func checkTxs(t *testing.T, mp mempool.Mempool, count int, peerID uint16) types. |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
if err := mp.CheckTx(txBytes, nil, txInfo); err != nil { |
|
|
|
if err := mp.CheckTx(context.Background(), txBytes, nil, txInfo); err != nil { |
|
|
|
// Skip invalid txs.
|
|
|
|
// TestMempoolFilters will fail otherwise. It asserts a number of txs
|
|
|
|
// returned.
|
|
|
@ -189,13 +189,13 @@ func TestMempoolUpdate(t *testing.T) { |
|
|
|
{ |
|
|
|
err := mp.Update(1, []types.Tx{[]byte{0x01}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
err = mp.CheckTx([]byte{0x01}, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), []byte{0x01}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
|
|
|
|
// 2. Removes valid txs from the mempool
|
|
|
|
{ |
|
|
|
err := mp.CheckTx([]byte{0x02}, nil, mempool.TxInfo{}) |
|
|
|
err := mp.CheckTx(context.Background(), []byte{0x02}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
err = mp.Update(1, []types.Tx{[]byte{0x02}}, abciResponses(1, abci.CodeTypeOK), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
@ -204,13 +204,13 @@ func TestMempoolUpdate(t *testing.T) { |
|
|
|
|
|
|
|
// 3. Removes invalid transactions from the cache and the mempool (if present)
|
|
|
|
{ |
|
|
|
err := mp.CheckTx([]byte{0x03}, nil, mempool.TxInfo{}) |
|
|
|
err := mp.CheckTx(context.Background(), []byte{0x03}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
err = mp.Update(1, []types.Tx{[]byte{0x03}}, abciResponses(1, 1), nil, nil) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.Zero(t, mp.Size()) |
|
|
|
|
|
|
|
err = mp.CheckTx([]byte{0x03}, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), []byte{0x03}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -231,7 +231,7 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) { |
|
|
|
b := make([]byte, 8) |
|
|
|
binary.BigEndian.PutUint64(b, 1) |
|
|
|
|
|
|
|
err := mp.CheckTx(b, nil, mempool.TxInfo{}) |
|
|
|
err := mp.CheckTx(context.Background(), b, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
// simulate new block
|
|
|
@ -242,11 +242,11 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) { |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
// a must be added to the cache
|
|
|
|
err = mp.CheckTx(a, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), a, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
// b must remain in the cache
|
|
|
|
err = mp.CheckTx(b, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), b, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
|
|
|
@ -258,7 +258,7 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) { |
|
|
|
// remove a from the cache to test (2)
|
|
|
|
mp.cache.Remove(a) |
|
|
|
|
|
|
|
err := mp.CheckTx(a, nil, mempool.TxInfo{}) |
|
|
|
err := mp.CheckTx(context.Background(), a, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -327,7 +327,7 @@ func TestSerialReap(t *testing.T) { |
|
|
|
// This will succeed
|
|
|
|
txBytes := make([]byte, 8) |
|
|
|
binary.BigEndian.PutUint64(txBytes, uint64(i)) |
|
|
|
err := mp.CheckTx(txBytes, nil, mempool.TxInfo{}) |
|
|
|
err := mp.CheckTx(context.Background(), txBytes, nil, mempool.TxInfo{}) |
|
|
|
_, cached := cacheMap[string(txBytes)] |
|
|
|
if cached { |
|
|
|
require.NotNil(t, err, "expected error for cached tx") |
|
|
@ -337,7 +337,7 @@ func TestSerialReap(t *testing.T) { |
|
|
|
cacheMap[string(txBytes)] = struct{}{} |
|
|
|
|
|
|
|
// Duplicates are cached and should return error
|
|
|
|
err = mp.CheckTx(txBytes, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), txBytes, nil, mempool.TxInfo{}) |
|
|
|
require.NotNil(t, err, "Expected error after CheckTx on duplicated tx") |
|
|
|
} |
|
|
|
} |
|
|
@ -446,7 +446,7 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) { |
|
|
|
|
|
|
|
tx := tmrand.Bytes(testCase.len) |
|
|
|
|
|
|
|
err := mempl.CheckTx(tx, nil, mempool.TxInfo{}) |
|
|
|
err := mempl.CheckTx(context.Background(), tx, nil, mempool.TxInfo{}) |
|
|
|
bv := gogotypes.BytesValue{Value: tx} |
|
|
|
bz, err2 := bv.Marshal() |
|
|
|
require.NoError(t, err2) |
|
|
@ -475,7 +475,7 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
assert.EqualValues(t, 0, mp.SizeBytes()) |
|
|
|
|
|
|
|
// 2. len(tx) after CheckTx
|
|
|
|
err := mp.CheckTx([]byte{0x01}, nil, mempool.TxInfo{}) |
|
|
|
err := mp.CheckTx(context.Background(), []byte{0x01}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.EqualValues(t, 1, mp.SizeBytes()) |
|
|
|
|
|
|
@ -485,7 +485,7 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
assert.EqualValues(t, 0, mp.SizeBytes()) |
|
|
|
|
|
|
|
// 4. zero after Flush
|
|
|
|
err = mp.CheckTx([]byte{0x02, 0x03}, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), []byte{0x02, 0x03}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.EqualValues(t, 2, mp.SizeBytes()) |
|
|
|
|
|
|
@ -493,9 +493,15 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
assert.EqualValues(t, 0, mp.SizeBytes()) |
|
|
|
|
|
|
|
// 5. ErrMempoolIsFull is returned when/if MaxTxsBytes limit is reached.
|
|
|
|
err = mp.CheckTx([]byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx( |
|
|
|
context.Background(), |
|
|
|
[]byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, |
|
|
|
nil, |
|
|
|
mempool.TxInfo{}, |
|
|
|
) |
|
|
|
require.NoError(t, err) |
|
|
|
err = mp.CheckTx([]byte{0x05}, nil, mempool.TxInfo{}) |
|
|
|
|
|
|
|
err = mp.CheckTx(context.Background(), []byte{0x05}, nil, mempool.TxInfo{}) |
|
|
|
if assert.Error(t, err) { |
|
|
|
assert.IsType(t, mempool.ErrMempoolIsFull{}, err) |
|
|
|
} |
|
|
@ -509,7 +515,7 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
txBytes := make([]byte, 8) |
|
|
|
binary.BigEndian.PutUint64(txBytes, uint64(0)) |
|
|
|
|
|
|
|
err = mp.CheckTx(txBytes, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), txBytes, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.EqualValues(t, 8, mp.SizeBytes()) |
|
|
|
|
|
|
@ -536,7 +542,7 @@ func TestMempoolTxsBytes(t *testing.T) { |
|
|
|
assert.EqualValues(t, 0, mp.SizeBytes()) |
|
|
|
|
|
|
|
// 7. Test RemoveTxByKey function
|
|
|
|
err = mp.CheckTx([]byte{0x06}, nil, mempool.TxInfo{}) |
|
|
|
err = mp.CheckTx(context.Background(), []byte{0x06}, nil, mempool.TxInfo{}) |
|
|
|
require.NoError(t, err) |
|
|
|
assert.EqualValues(t, 1, mp.SizeBytes()) |
|
|
|
mp.RemoveTxByKey(mempool.TxKey([]byte{0x07}), true) |
|
|
@ -580,7 +586,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) { |
|
|
|
tx := txs[txNum] |
|
|
|
|
|
|
|
// this will err with ErrTxInCache many times ...
|
|
|
|
mp.CheckTx(tx, nil, mempool.TxInfo{SenderID: uint16(peerID)}) //nolint: errcheck // will error
|
|
|
|
mp.CheckTx(context.Background(), tx, nil, mempool.TxInfo{SenderID: uint16(peerID)}) //nolint: errcheck // will error
|
|
|
|
} |
|
|
|
err := mp.FlushAppConn() |
|
|
|
require.NoError(t, err) |
|
|
|