forked from risechain/pevm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraw_transfers.rs
100 lines (93 loc) · 3.84 KB
/
raw_transfers.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Test raw transfers -- only send some ETH from one account to another without extra data.
use alloy_rpc_types::{Block, BlockTransactions, Transaction};
use pevm::{chain::PevmEthereum, InMemoryStorage};
use rand::random;
use revm::primitives::{alloy_primitives::U160, env::TxEnv, Address, TransactTo, U256};
pub mod common;
#[test]
fn raw_transfers_independent() {
let block_size = 100_000; // number of transactions
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| {
let address = Address::from(U160::from(i));
TxEnv {
caller: address,
transact_to: TransactTo::Call(address),
value: U256::from(1),
gas_limit: common::RAW_TRANSFER_GAS_LIMIT,
gas_price: U256::from(1),
..TxEnv::default()
}
})
.collect(),
);
}
// The same sender sending multiple transfers with increasing nonces.
// These must be detected and executed in the correct order.
#[test]
fn raw_transfers_same_sender_multiple_txs() {
let block_size = 5_000; // number of transactions
let same_sender_address = Address::from(U160::from(1));
let mut same_sender_nonce: u64 = 0;
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, []),
(1..=block_size)
.map(|i| {
// Insert a "parallel" transaction every ~256 transactions
// after the first ~30 guaranteed from the same sender.
let (address, nonce) = if i > 30 && random::<u8>() == 0 {
(Address::from(U160::from(i)), 1)
} else {
same_sender_nonce += 1;
(same_sender_address, same_sender_nonce)
};
TxEnv {
caller: address,
transact_to: TransactTo::Call(address),
value: U256::from(1),
gas_limit: common::RAW_TRANSFER_GAS_LIMIT,
gas_price: U256::from(1),
nonce: Some(nonce),
..TxEnv::default()
}
})
.collect(),
);
}
#[test]
fn raw_transfers_independent_alloy() {
let block_size = 100_000; // number of transactions
common::test_execute_alloy(
// Mock the beneficiary account (`Address:ZERO`) and the next `block_size` user accounts.
&InMemoryStorage::new((0..=block_size).map(common::mock_account), None, []),
&PevmEthereum::mainnet(),
Block {
header: common::MOCK_ALLOY_BLOCK_HEADER.clone(),
transactions: BlockTransactions::Full(
(1..block_size)
.map(|i| {
let address = Address::from(U160::from(i));
Transaction {
transaction_type: Some(2),
from: address,
to: Some(address),
value: U256::from(1),
gas: common::RAW_TRANSFER_GAS_LIMIT.into(),
max_fee_per_gas: Some(1),
nonce: 1,
..Transaction::default()
}
})
.collect(),
),
..Block::default()
},
false,
);
}