mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
tx-pool: add unit tests for LocalTransactionConfig (#9859)
This commit is contained in:
@ -225,4 +225,75 @@ mod tests {
|
|||||||
// now this should be above the limits
|
// now this should be above the limits
|
||||||
assert!(config.is_exceeded(pool_size));
|
assert!(config.is_exceeded(pool_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_default_config() {
|
||||||
|
let config = LocalTransactionConfig::default();
|
||||||
|
|
||||||
|
assert!(!config.no_exemptions);
|
||||||
|
assert!(config.local_addresses.is_empty());
|
||||||
|
assert!(config.propagate_local_transactions);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_no_local_exemptions() {
|
||||||
|
let config = LocalTransactionConfig { no_exemptions: true, ..Default::default() };
|
||||||
|
assert!(config.no_local_exemptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_contains_local_address() {
|
||||||
|
let address = Address::new([1; 20]);
|
||||||
|
let mut local_addresses = HashSet::new();
|
||||||
|
local_addresses.insert(address);
|
||||||
|
|
||||||
|
let config = LocalTransactionConfig { local_addresses, ..Default::default() };
|
||||||
|
|
||||||
|
// Should contain the inserted address
|
||||||
|
assert!(config.contains_local_address(address));
|
||||||
|
|
||||||
|
// Should not contain another random address
|
||||||
|
assert!(!config.contains_local_address(Address::new([2; 20])));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_local_with_no_exemptions() {
|
||||||
|
let address = Address::new([1; 20]);
|
||||||
|
let config = LocalTransactionConfig {
|
||||||
|
no_exemptions: true,
|
||||||
|
local_addresses: HashSet::new(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Should return false as no exemptions is set to true
|
||||||
|
assert!(!config.is_local(TransactionOrigin::Local, address));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_local_without_no_exemptions() {
|
||||||
|
let address = Address::new([1; 20]);
|
||||||
|
let mut local_addresses = HashSet::new();
|
||||||
|
local_addresses.insert(address);
|
||||||
|
|
||||||
|
let config =
|
||||||
|
LocalTransactionConfig { no_exemptions: false, local_addresses, ..Default::default() };
|
||||||
|
|
||||||
|
// Should return true as the transaction origin is local
|
||||||
|
assert!(config.is_local(TransactionOrigin::Local, Address::new([2; 20])));
|
||||||
|
assert!(config.is_local(TransactionOrigin::Local, address));
|
||||||
|
|
||||||
|
// Should return true as the address is in the local_addresses set
|
||||||
|
assert!(config.is_local(TransactionOrigin::External, address));
|
||||||
|
// Should return false as the address is not in the local_addresses set
|
||||||
|
assert!(!config.is_local(TransactionOrigin::External, Address::new([2; 20])));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_propagate_local_transactions() {
|
||||||
|
let config = LocalTransactionConfig::default();
|
||||||
|
assert!(config.propagate_local_transactions);
|
||||||
|
|
||||||
|
let new_config = config.set_propagate_local_transactions(false);
|
||||||
|
assert!(!new_config.propagate_local_transactions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user