Skip to content

Commit ee0f11d

Browse files
authored
feat(docker compose tests): issue transactions throughout the test (#342)
1 parent 7bc44a0 commit ee0f11d

File tree

7 files changed

+258
-3
lines changed

7 files changed

+258
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ tracing = { workspace = true }
2020
reth-tracing = { workspace = true }
2121
serde = { workspace = true }
2222
serde_json = "1.0"
23+
reth-e2e-test-utils.workspace = true

tests/l2geth-genesis-e2e.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,66 @@
110110
"code": "0x",
111111
"nonce": "0x1",
112112
"storage": {}
113+
},
114+
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266": {
115+
"balance": "0xD3C21BCECCEDA1000000"
116+
},
117+
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8": {
118+
"balance": "0xD3C21BCECCEDA1000000"
119+
},
120+
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC": {
121+
"balance": "0xD3C21BCECCEDA1000000"
122+
},
123+
"0x90F79bf6EB2c4f870365E785982E1f101E93b906": {
124+
"balance": "0xD3C21BCECCEDA1000000"
125+
},
126+
"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65": {
127+
"balance": "0xD3C21BCECCEDA1000000"
128+
},
129+
"0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc": {
130+
"balance": "0xD3C21BCECCEDA1000000"
131+
},
132+
"0x976EA74026E726554dB657fA54763abd0C3a0aa9": {
133+
"balance": "0xD3C21BCECCEDA1000000"
134+
},
135+
"0x14dC79964da2C08b23698B3D3cc7Ca32193d9955": {
136+
"balance": "0xD3C21BCECCEDA1000000"
137+
},
138+
"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f": {
139+
"balance": "0xD3C21BCECCEDA1000000"
140+
},
141+
"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720": {
142+
"balance": "0xD3C21BCECCEDA1000000"
143+
},
144+
"0xBcd4042DE499D14e55001CcbB24a551F3b954096": {
145+
"balance": "0xD3C21BCECCEDA1000000"
146+
},
147+
"0x71bE63f3384f5fb98995898A86B02Fb2426c5788": {
148+
"balance": "0xD3C21BCECCEDA1000000"
149+
},
150+
"0xFABB0ac9d68B0B445fB7357272Ff202C5651694a": {
151+
"balance": "0xD3C21BCECCEDA1000000"
152+
},
153+
"0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec": {
154+
"balance": "0xD3C21BCECCEDA1000000"
155+
},
156+
"0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097": {
157+
"balance": "0xD3C21BCECCEDA1000000"
158+
},
159+
"0xcd3B766CCDd6AE721141F452C550Ca635964ce71": {
160+
"balance": "0xD3C21BCECCEDA1000000"
161+
},
162+
"0x2546BcD3c84621e976D8185a91A922aE77ECEc30": {
163+
"balance": "0xD3C21BCECCEDA1000000"
164+
},
165+
"0xbDA5747bFD65F08deb54cb465eB87D40e51B197E": {
166+
"balance": "0xD3C21BCECCEDA1000000"
167+
},
168+
"0xdD2FD4581271e230360230F9337D5c0430Bf44C0": {
169+
"balance": "0xD3C21BCECCEDA1000000"
170+
},
171+
"0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199": {
172+
"balance": "0xD3C21BCECCEDA1000000"
113173
}
114174
}
115175
}

tests/l2reth-genesis-e2e.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,66 @@
103103
"code": "0x",
104104
"nonce": "0x1",
105105
"storage": {}
106+
},
107+
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266": {
108+
"balance": "0xD3C21BCECCEDA1000000"
109+
},
110+
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8": {
111+
"balance": "0xD3C21BCECCEDA1000000"
112+
},
113+
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC": {
114+
"balance": "0xD3C21BCECCEDA1000000"
115+
},
116+
"0x90F79bf6EB2c4f870365E785982E1f101E93b906": {
117+
"balance": "0xD3C21BCECCEDA1000000"
118+
},
119+
"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65": {
120+
"balance": "0xD3C21BCECCEDA1000000"
121+
},
122+
"0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc": {
123+
"balance": "0xD3C21BCECCEDA1000000"
124+
},
125+
"0x976EA74026E726554dB657fA54763abd0C3a0aa9": {
126+
"balance": "0xD3C21BCECCEDA1000000"
127+
},
128+
"0x14dC79964da2C08b23698B3D3cc7Ca32193d9955": {
129+
"balance": "0xD3C21BCECCEDA1000000"
130+
},
131+
"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f": {
132+
"balance": "0xD3C21BCECCEDA1000000"
133+
},
134+
"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720": {
135+
"balance": "0xD3C21BCECCEDA1000000"
136+
},
137+
"0xBcd4042DE499D14e55001CcbB24a551F3b954096": {
138+
"balance": "0xD3C21BCECCEDA1000000"
139+
},
140+
"0x71bE63f3384f5fb98995898A86B02Fb2426c5788": {
141+
"balance": "0xD3C21BCECCEDA1000000"
142+
},
143+
"0xFABB0ac9d68B0B445fB7357272Ff202C5651694a": {
144+
"balance": "0xD3C21BCECCEDA1000000"
145+
},
146+
"0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec": {
147+
"balance": "0xD3C21BCECCEDA1000000"
148+
},
149+
"0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097": {
150+
"balance": "0xD3C21BCECCEDA1000000"
151+
},
152+
"0xcd3B766CCDd6AE721141F452C550Ca635964ce71": {
153+
"balance": "0xD3C21BCECCEDA1000000"
154+
},
155+
"0x2546BcD3c84621e976D8185a91A922aE77ECEc30": {
156+
"balance": "0xD3C21BCECCEDA1000000"
157+
},
158+
"0xbDA5747bFD65F08deb54cb465eB87D40e51B197E": {
159+
"balance": "0xD3C21BCECCEDA1000000"
160+
},
161+
"0xdD2FD4581271e230360230F9337D5c0430Bf44C0": {
162+
"balance": "0xD3C21BCECCEDA1000000"
163+
},
164+
"0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199": {
165+
"balance": "0xD3C21BCECCEDA1000000"
106166
}
107167
}
108168
}

tests/src/utils.rs

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
use alloy_primitives::{hex::ToHexExt, Bytes};
12
use alloy_rpc_types_eth::BlockNumberOrTag;
2-
use eyre::Result;
3-
use std::time::Duration;
3+
use eyre::{Ok, Result};
4+
use reth_e2e_test_utils::{transaction::TransactionTestContext, wallet::Wallet};
5+
use std::{
6+
sync::{
7+
atomic::{AtomicBool, Ordering},
8+
Arc,
9+
},
10+
time::Duration,
11+
};
12+
use tokio::{sync::Mutex, time::interval};
413

514
use crate::docker_compose::NamedProvider;
615

@@ -214,3 +223,96 @@ pub async fn admin_remove_trusted_peer(provider: &NamedProvider, enode: &str) ->
214223
.await
215224
.map_err(|e| eyre::eyre!("Failed to remove trusted peer {}: {}", enode, e))
216225
}
226+
227+
pub fn create_wallet(chain_id: u64) -> Arc<Mutex<Wallet>> {
228+
Arc::new(Mutex::new(Wallet::default().with_chain_id(chain_id)))
229+
}
230+
231+
/// Generate a transfer transaction with the given wallet.
232+
pub async fn generate_tx(wallet: Arc<Mutex<Wallet>>) -> Bytes {
233+
let mut wallet = wallet.lock().await;
234+
let tx_fut = TransactionTestContext::transfer_tx_nonce_bytes(
235+
wallet.chain_id,
236+
wallet.inner.clone(),
237+
wallet.inner_nonce,
238+
);
239+
wallet.inner_nonce += 1;
240+
tx_fut.await
241+
}
242+
243+
/// Send a raw transaction to multiple nodes, optionally waiting for confirmation.
244+
pub async fn send_tx(
245+
wallet: Arc<Mutex<Wallet>>,
246+
nodes: &[&NamedProvider],
247+
wait_for_confirmation: bool,
248+
) -> Result<()> {
249+
let tx = generate_tx(wallet).await;
250+
251+
tracing::debug!("Sending transaction: {:?}", tx);
252+
let tx: Vec<u8> = tx.into();
253+
let mut pending_txs = Vec::new();
254+
255+
for node in nodes {
256+
let builder = node.send_raw_transaction(&tx).await;
257+
match builder {
258+
std::result::Result::Ok(builder) => {
259+
let pending_tx = builder.register().await?;
260+
tracing::debug!(
261+
"Sent transaction {:?} to node: {:?}",
262+
pending_tx.tx_hash(),
263+
node.name
264+
);
265+
pending_txs.push(pending_tx);
266+
}
267+
Err(e) => {
268+
if e.to_string().contains("already known") {
269+
continue;
270+
}
271+
eyre::bail!("Failed to send transaction to node {}: {}", node.name, e);
272+
}
273+
};
274+
}
275+
276+
if wait_for_confirmation {
277+
for pending_tx in pending_txs {
278+
let r = pending_tx.await?;
279+
tracing::debug!("Transaction confirmed: {:?}", r.encode_hex());
280+
}
281+
}
282+
283+
Ok(())
284+
}
285+
286+
/// Simple transaction sender that runs continuously until `stop` is set to true.
287+
pub async fn run_continuous_tx_sender(stop: Arc<AtomicBool>, nodes: &[&NamedProvider]) -> u64 {
288+
let mut interval = interval(Duration::from_millis(50));
289+
let mut tx_count = 0u64;
290+
291+
let wallet = create_wallet(nodes[0].get_chain_id().await.expect("Failed to get chain id"));
292+
293+
while !stop.load(Ordering::Relaxed) {
294+
interval.tick().await;
295+
296+
if let Err(e) = send_tx(wallet.clone(), nodes, false).await {
297+
tracing::error!("Error sending transaction: {}", e);
298+
} else {
299+
tx_count += 1;
300+
}
301+
}
302+
303+
tx_count
304+
}
305+
306+
pub async fn stop_continuous_tx_sender(
307+
stop: Arc<AtomicBool>,
308+
tx_sender: tokio::task::JoinHandle<u64>,
309+
) -> Result<()> {
310+
stop.store(true, Ordering::Relaxed);
311+
let tx_count = tx_sender.await?;
312+
tracing::info!(
313+
"🔄 Stopped continuous transaction sender after sending {} transactions",
314+
tx_count
315+
);
316+
317+
Ok(())
318+
}

tests/tests/heterogeneous_client_sync_and_sequencer_handoff.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use eyre::Result;
2+
use std::sync::{atomic::AtomicBool, Arc};
23
use tests::*;
34

45
/// Tests cross-client block propagation and synchronization between heterogeneous nodes.
@@ -47,7 +48,8 @@ async fn docker_test_heterogeneous_client_sync_and_sequencer_handoff() -> Result
4748
reth_tracing::init_test_tracing();
4849

4950
tracing::info!("=== STARTING docker_test_heterogeneous_client_sync_and_sequencer_handoff ===");
50-
let env = DockerComposeEnv::new("multi-client-propagation").await?;
51+
let env = DockerComposeEnv::new("docker_test_heterogeneous_client_sync_and_sequencer_handoff")
52+
.await?;
5153

5254
let rn_sequencer = env.get_rn_sequencer_provider().await?;
5355
let rn_follower = env.get_rn_follower_provider().await?;
@@ -66,6 +68,18 @@ async fn docker_test_heterogeneous_client_sync_and_sequencer_handoff() -> Result
6668
// Enable block production on l2geth sequencer
6769
utils::miner_start(&l2geth_sequencer).await?;
6870

71+
// Start single continuous transaction sender for entire test
72+
let stop = Arc::new(AtomicBool::new(false));
73+
let stop_clone = stop.clone();
74+
let rn_follower_clone = env.get_rn_follower_provider().await.unwrap();
75+
let l2geth_follower_clone = env.get_l2geth_follower_provider().await.unwrap();
76+
let tx_sender = tokio::spawn(async move {
77+
utils::run_continuous_tx_sender(stop_clone, &[&rn_follower_clone, &l2geth_follower_clone])
78+
.await
79+
});
80+
81+
tracing::info!("🔄 Started continuous transaction sender for entire test");
82+
6983
// Wait for at least 10 blocks to be produced
7084
let target_block = 10;
7185
utils::wait_for_block(&[&l2geth_sequencer], target_block).await?;
@@ -169,5 +183,7 @@ async fn docker_test_heterogeneous_client_sync_and_sequencer_handoff() -> Result
169183
utils::wait_for_block(&nodes, target_block).await?;
170184
assert_blocks_match(&nodes, target_block).await?;
171185

186+
utils::stop_continuous_tx_sender(stop, tx_sender).await?;
187+
172188
Ok(())
173189
}

tests/tests/migrate_sequencer.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use eyre::Result;
2+
use std::sync::{atomic::AtomicBool, Arc};
23
use tests::*;
34

45
#[tokio::test]
@@ -28,6 +29,18 @@ async fn docker_test_migrate_sequencer() -> Result<()> {
2829
utils::admin_add_peer(&rn_follower, &env.rn_sequencer_enode()?).await?;
2930
utils::admin_add_peer(&rn_sequencer, &env.l2geth_sequencer_enode()?).await?;
3031

32+
// Start single continuous transaction sender for entire test
33+
let stop = Arc::new(AtomicBool::new(false));
34+
let stop_clone = stop.clone();
35+
let rn_follower_clone = env.get_rn_follower_provider().await.unwrap();
36+
let l2geth_follower_clone = env.get_l2geth_follower_provider().await.unwrap();
37+
let tx_sender = tokio::spawn(async move {
38+
utils::run_continuous_tx_sender(stop_clone, &[&rn_follower_clone, &l2geth_follower_clone])
39+
.await
40+
});
41+
42+
tracing::info!("🔄 Started continuous transaction sender for entire test");
43+
3144
// Enable block production on l2geth sequencer
3245
utils::miner_start(&l2geth_sequencer).await?;
3346

@@ -47,5 +60,7 @@ async fn docker_test_migrate_sequencer() -> Result<()> {
4760
utils::wait_for_block(&nodes, target_block).await?;
4861
utils::assert_blocks_match(&nodes, target_block).await?;
4962

63+
utils::stop_continuous_tx_sender(stop, tx_sender).await?;
64+
5065
Ok(())
5166
}

0 commit comments

Comments
 (0)