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