|
|
|
@ -57,6 +57,11 @@ impl TestPool {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn import<S: Scoring<Transaction>, L: Listener<Transaction>>(txq: &mut Pool<Transaction, S, L>, tx: Transaction)
|
|
|
|
|
-> Result<Arc<Transaction>, Error<<Transaction as VerifiedTransaction>::Hash>> {
|
|
|
|
|
txq.import(tx, &mut DummyScoring::default())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn should_clear_queue() {
|
|
|
|
|
// given
|
|
|
|
@ -71,8 +76,8 @@ fn should_clear_queue() {
|
|
|
|
|
let tx2 = b.tx().nonce(1).mem_usage(1).new();
|
|
|
|
|
|
|
|
|
|
// add
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
txq.import(tx2).unwrap();
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
import(&mut txq, tx2).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status(), LightStatus {
|
|
|
|
|
mem_usage: 1,
|
|
|
|
|
transaction_count: 2,
|
|
|
|
@ -99,8 +104,8 @@ fn should_not_allow_same_transaction_twice() {
|
|
|
|
|
let tx2 = b.tx().nonce(0).new();
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
txq.import(tx2).unwrap_err();
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
import(&mut txq, tx2).unwrap_err();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
@ -115,8 +120,8 @@ fn should_replace_transaction() {
|
|
|
|
|
let tx2 = b.tx().nonce(0).gas_price(2).new();
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
txq.import(tx2).unwrap();
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
import(&mut txq, tx2).unwrap();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
@ -134,8 +139,8 @@ fn should_reject_if_above_count() {
|
|
|
|
|
let tx1 = b.tx().nonce(0).new();
|
|
|
|
|
let tx2 = b.tx().nonce(1).new();
|
|
|
|
|
let hash = tx2.hash.clone();
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
assert_eq!(txq.import(tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
|
|
|
|
|
|
txq.clear();
|
|
|
|
@ -143,8 +148,8 @@ fn should_reject_if_above_count() {
|
|
|
|
|
// Replace first
|
|
|
|
|
let tx1 = b.tx().nonce(0).new();
|
|
|
|
|
let tx2 = b.tx().nonce(0).sender(1).gas_price(2).new();
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
txq.import(tx2).unwrap();
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
import(&mut txq, tx2).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -160,8 +165,8 @@ fn should_reject_if_above_mem_usage() {
|
|
|
|
|
let tx1 = b.tx().nonce(1).mem_usage(1).new();
|
|
|
|
|
let tx2 = b.tx().nonce(2).mem_usage(2).new();
|
|
|
|
|
let hash = tx2.hash.clone();
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
assert_eq!(txq.import(tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
|
|
|
|
|
|
txq.clear();
|
|
|
|
@ -169,8 +174,8 @@ fn should_reject_if_above_mem_usage() {
|
|
|
|
|
// Replace first
|
|
|
|
|
let tx1 = b.tx().nonce(1).mem_usage(1).new();
|
|
|
|
|
let tx2 = b.tx().nonce(1).sender(1).gas_price(2).mem_usage(1).new();
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
txq.import(tx2).unwrap();
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
import(&mut txq, tx2).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -186,8 +191,8 @@ fn should_reject_if_above_sender_count() {
|
|
|
|
|
let tx1 = b.tx().nonce(1).new();
|
|
|
|
|
let tx2 = b.tx().nonce(2).new();
|
|
|
|
|
let hash = tx2.hash.clone();
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
assert_eq!(txq.import(tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
|
|
|
|
|
|
txq.clear();
|
|
|
|
@ -196,9 +201,9 @@ fn should_reject_if_above_sender_count() {
|
|
|
|
|
let tx1 = b.tx().nonce(1).new();
|
|
|
|
|
let tx2 = b.tx().nonce(2).gas_price(2).new();
|
|
|
|
|
let hash = tx2.hash.clone();
|
|
|
|
|
txq.import(tx1).unwrap();
|
|
|
|
|
import(&mut txq, tx1).unwrap();
|
|
|
|
|
// This results in error because we also compare nonces
|
|
|
|
|
assert_eq!(txq.import(tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
assert_eq!(import(&mut txq, tx2).unwrap_err(), error::Error::TooCheapToEnter(hash, "0x0".into()));
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -208,25 +213,25 @@ fn should_construct_pending() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
let tx0 = txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx1 = txq.import(b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx0 = import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx1 = import(&mut txq, b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx9 = txq.import(b.tx().sender(2).nonce(0).new()).unwrap();
|
|
|
|
|
let tx9 = import(&mut txq, b.tx().sender(2).nonce(0).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx5 = txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
let tx6 = txq.import(b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
let tx7 = txq.import(b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
let tx8 = txq.import(b.tx().sender(1).nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
let tx5 = import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
let tx6 = import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
let tx7 = import(&mut txq, b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
let tx8 = import(&mut txq, b.tx().sender(1).nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx2 = txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
let tx2 = import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
// this transaction doesn't get to the block despite high gas price
|
|
|
|
|
// because of block gas limit and simplistic ordering algorithm.
|
|
|
|
|
txq.import(b.tx().nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
//gap
|
|
|
|
|
txq.import(b.tx().nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// gap
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 11);
|
|
|
|
|
assert_eq!(txq.status(NonceReady::default()), Status {
|
|
|
|
@ -268,21 +273,21 @@ fn should_return_unordered_iterator() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
let tx0 = txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx1 = txq.import(b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx2 = txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
let tx3 = txq.import(b.tx().nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
let tx0 = import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx1 = import(&mut txq, b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx2 = import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
let tx3 = import(&mut txq, b.tx().nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
//gap
|
|
|
|
|
txq.import(b.tx().nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx5 = txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
let tx6 = txq.import(b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
let tx7 = txq.import(b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
let tx8 = txq.import(b.tx().sender(1).nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
let tx5 = import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
let tx6 = import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
let tx7 = import(&mut txq, b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
let tx8 = import(&mut txq, b.tx().sender(1).nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
// gap
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx9 = txq.import(b.tx().sender(2).nonce(0).new()).unwrap();
|
|
|
|
|
let tx9 = import(&mut txq, b.tx().sender(2).nonce(0).new()).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 11);
|
|
|
|
|
assert_eq!(txq.status(NonceReady::default()), Status {
|
|
|
|
|
stalled: 0,
|
|
|
|
@ -328,24 +333,24 @@ fn should_update_scoring_correctly() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
let tx9 = txq.import(b.tx().sender(2).nonce(0).new()).unwrap();
|
|
|
|
|
let tx9 = import(&mut txq, b.tx().sender(2).nonce(0).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx5 = txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
let tx6 = txq.import(b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
let tx7 = txq.import(b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
let tx8 = txq.import(b.tx().sender(1).nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
let tx5 = import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
let tx6 = import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
let tx7 = import(&mut txq, b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
let tx8 = import(&mut txq, b.tx().sender(1).nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
let tx0 = txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx1 = txq.import(b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx2 = txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
let tx0 = import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx1 = import(&mut txq, b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
let tx2 = import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
// this transaction doesn't get to the block despite high gas price
|
|
|
|
|
// because of block gas limit and simplistic ordering algorithm.
|
|
|
|
|
txq.import(b.tx().nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(3).gas_price(4).new()).unwrap();
|
|
|
|
|
//gap
|
|
|
|
|
txq.import(b.tx().nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// gap
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 11);
|
|
|
|
|
assert_eq!(txq.status(NonceReady::default()), Status {
|
|
|
|
@ -390,9 +395,9 @@ fn should_remove_transaction() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
let tx1 = txq.import(b.tx().nonce(0).new()).unwrap();
|
|
|
|
|
let tx2 = txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
let tx1 = import(&mut txq, b.tx().nonce(0).new()).unwrap();
|
|
|
|
|
let tx2 = import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 3);
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
@ -411,13 +416,13 @@ fn should_cull_stalled_transactions() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(3).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(3).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(5).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(txq.status(NonceReady::new(1)), Status {
|
|
|
|
|
stalled: 2,
|
|
|
|
@ -447,12 +452,12 @@ fn should_cull_stalled_transactions_from_a_sender() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(2).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(txq.status(NonceReady::new(2)), Status {
|
|
|
|
|
stalled: 4,
|
|
|
|
@ -483,10 +488,10 @@ fn should_re_insert_after_cull() {
|
|
|
|
|
let b = TransactionBuilder::default();
|
|
|
|
|
let mut txq = TestPool::default();
|
|
|
|
|
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(1).new()).unwrap();
|
|
|
|
|
assert_eq!(txq.status(NonceReady::new(1)), Status {
|
|
|
|
|
stalled: 2,
|
|
|
|
|
pending: 2,
|
|
|
|
@ -500,8 +505,8 @@ fn should_re_insert_after_cull() {
|
|
|
|
|
pending: 2,
|
|
|
|
|
future: 0,
|
|
|
|
|
});
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(0).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(txq.status(NonceReady::new(1)), Status {
|
|
|
|
|
stalled: 2,
|
|
|
|
@ -518,8 +523,8 @@ fn should_return_worst_transaction() {
|
|
|
|
|
assert!(txq.worst_transaction().is_none());
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(0).gas_price(4).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(0).gas_price(4).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert_eq!(txq.worst_transaction().unwrap().gas_price, 4.into());
|
|
|
|
@ -533,10 +538,10 @@ fn should_return_is_full() {
|
|
|
|
|
assert!(!txq.is_full());
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(110).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(110).new()).unwrap();
|
|
|
|
|
assert!(!txq.is_full());
|
|
|
|
|
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(0).gas_price(100).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(0).gas_price(100).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert!(txq.is_full());
|
|
|
|
@ -550,7 +555,7 @@ fn should_import_even_if_limit_is_reached_and_should_replace_returns_insert_new(
|
|
|
|
|
max_count: 1,
|
|
|
|
|
..Default::default()
|
|
|
|
|
});
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status(), LightStatus {
|
|
|
|
|
transaction_count: 1,
|
|
|
|
|
senders: 1,
|
|
|
|
@ -558,7 +563,7 @@ fn should_import_even_if_limit_is_reached_and_should_replace_returns_insert_new(
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.import(b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert_eq!(txq.light_status(), LightStatus {
|
|
|
|
@ -576,7 +581,7 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false()
|
|
|
|
|
max_count: 1,
|
|
|
|
|
..Default::default()
|
|
|
|
|
});
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status(), LightStatus {
|
|
|
|
|
transaction_count: 1,
|
|
|
|
|
senders: 1,
|
|
|
|
@ -584,7 +589,7 @@ fn should_not_import_even_if_limit_is_reached_and_should_replace_returns_false()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
let err = txq.import(b.tx().nonce(1).gas_price(5).new()).unwrap_err();
|
|
|
|
|
let err = import(&mut txq, b.tx().nonce(1).gas_price(5).new()).unwrap_err();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert_eq!(err, error::Error::TooCheapToEnter("0x00000000000000000000000000000000000000000000000000000000000001f5".into(), "0x5".into()));
|
|
|
|
@ -604,7 +609,7 @@ fn should_import_even_if_sender_limit_is_reached() {
|
|
|
|
|
max_per_sender: 1,
|
|
|
|
|
..Default::default()
|
|
|
|
|
});
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(0).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap();
|
|
|
|
|
assert_eq!(txq.light_status(), LightStatus {
|
|
|
|
|
transaction_count: 1,
|
|
|
|
|
senders: 1,
|
|
|
|
@ -612,7 +617,7 @@ fn should_import_even_if_sender_limit_is_reached() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.import(b.tx().nonce(1).gas_price(5).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(1).gas_price(5).new(), &mut DummyScoring::always_insert()).unwrap();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
assert_eq!(txq.light_status(), LightStatus {
|
|
|
|
@ -671,26 +676,26 @@ mod listener {
|
|
|
|
|
assert!(results.borrow().is_empty());
|
|
|
|
|
|
|
|
|
|
// Regular import
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added"]);
|
|
|
|
|
// Already present (no notification)
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap_err();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap_err();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added"]);
|
|
|
|
|
// Push out the first one
|
|
|
|
|
txq.import(b.tx().nonce(1).gas_price(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).gas_price(1).new()).unwrap();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added", "replaced"]);
|
|
|
|
|
// Reject
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap_err();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap_err();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added", "replaced", "rejected"]);
|
|
|
|
|
results.borrow_mut().clear();
|
|
|
|
|
// Different sender (accept)
|
|
|
|
|
txq.import(b.tx().sender(1).nonce(1).gas_price(2).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(1).nonce(1).gas_price(2).new()).unwrap();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added"]);
|
|
|
|
|
// Third sender push out low gas price
|
|
|
|
|
txq.import(b.tx().sender(2).nonce(1).gas_price(4).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().sender(2).nonce(1).gas_price(4).new()).unwrap();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added", "dropped", "added"]);
|
|
|
|
|
// Reject (too cheap)
|
|
|
|
|
txq.import(b.tx().sender(2).nonce(1).gas_price(2).new()).unwrap_err();
|
|
|
|
|
import(&mut txq, b.tx().sender(2).nonce(1).gas_price(2).new()).unwrap_err();
|
|
|
|
|
assert_eq!(*results.borrow(), &["added", "dropped", "added", "rejected"]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(txq.light_status().transaction_count, 2);
|
|
|
|
@ -704,8 +709,8 @@ mod listener {
|
|
|
|
|
let mut txq = Pool::new(listener, DummyScoring::default(), Options::default());
|
|
|
|
|
|
|
|
|
|
// insert
|
|
|
|
|
let tx1 = txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
let tx2 = txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
let tx1 = import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
let tx2 = import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
txq.remove(&tx1.hash(), false);
|
|
|
|
@ -723,8 +728,8 @@ mod listener {
|
|
|
|
|
let mut txq = Pool::new(listener, DummyScoring::default(), Options::default());
|
|
|
|
|
|
|
|
|
|
// insert
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.clear();
|
|
|
|
@ -741,8 +746,8 @@ mod listener {
|
|
|
|
|
let mut txq = Pool::new(listener, DummyScoring::default(), Options::default());
|
|
|
|
|
|
|
|
|
|
// insert
|
|
|
|
|
txq.import(b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
txq.import(b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(1).new()).unwrap();
|
|
|
|
|
import(&mut txq, b.tx().nonce(2).new()).unwrap();
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
|
txq.cull(None, NonceReady::new(3));
|
|
|
|
|