forked from risechain/pevm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beneficiary.rs
57 lines (51 loc) · 1.8 KB
/
beneficiary.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Tests for the beneficiary account, especially for the lazy update of its balance to avoid
// "implicit" dependency among consecutive transactions.
use pevm::InMemoryStorage;
use rand::random;
use revm::primitives::{alloy_primitives::U160, env::TxEnv, Address, TransactTo, U256};
pub mod common;
const BLOCK_SIZE: usize = 100_000;
fn test_beneficiary(get_address: fn(usize) -> Address) {
common::test_execute_revm(
// Mock the beneficiary account (`Address:ZERO`) and the next `BLOCK_SIZE` user accounts.
InMemoryStorage::new((0..=BLOCK_SIZE).map(common::mock_account), None, []),
// Mock `BLOCK_SIZE` transactions sending some tokens to itself.
// Skipping `Address::ZERO` as the beneficiary account.
(1..=BLOCK_SIZE)
.map(|i| {
// Randomly insert a beneficiary spending every ~256 txs
let address = get_address(i);
TxEnv {
caller: address,
transact_to: TransactTo::Call(address),
value: U256::from(1),
gas_price: U256::from(1),
..TxEnv::default()
}
})
.collect(),
);
}
#[test]
fn beneficiary_random() {
test_beneficiary(|i| {
// Randomly insert a beneficiary spending every ~256 txs
if random::<u8>() == 0 {
Address::from(U160::from(0))
} else {
Address::from(U160::from(i))
}
});
}
#[test]
fn beneficiary_heavy_evaluation() {
test_beneficiary(|i| {
// Setting only the last tx as beneficiary for a heavy
// evaluation all the way to the top of the block.
if i == BLOCK_SIZE {
Address::from(U160::from(0))
} else {
Address::from(U160::from(i))
}
});
}