-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathintegration.rs
More file actions
133 lines (114 loc) · 3.78 KB
/
integration.rs
File metadata and controls
133 lines (114 loc) · 3.78 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use std::sync::Arc;
use alloy_provider::{network::Ethereum, Network, RootProvider};
use guest_executor::{
executor::{ClientExecutor, EthClientExecutor},
io::ClientExecutorInput,
BlockValidator, FromInput, IntoInput, IntoPrimitives,
};
use host_executor::{EthHostExecutor, HostExecutor};
use primitives::genesis::Genesis;
use reth_chainspec::ChainSpec;
use reth_evm::ConfigureEvm;
use reth_optimism_chainspec::OpChainSpec;
use revm_primitives::{address, Address};
use serde::{de::DeserializeOwned, Serialize};
use tracing_subscriber::{
fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter,
};
use url::Url;
#[tokio::test(flavor = "multi_thread")]
async fn test_e2e_ethereum() {
run_eth_e2e(&Genesis::Mainnet, "RPC_1", 18884864, None).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_e2e_optimism() {
let chain_spec: Arc<OpChainSpec> = Arc::new((&Genesis::OpMainnet).try_into().unwrap());
// Setup the host executor.
let host_executor = host_executor::OpHostExecutor::optimism(chain_spec.clone());
// Setup the client executor.
let guest_executor = guest_executor::executor::OpClientExecutor::optimism(chain_spec);
run_e2e::<_, OpChainSpec, op_alloy_network::Optimism>(
host_executor,
guest_executor,
"RPC_10",
122853660,
&Genesis::OpMainnet,
None,
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_e2e_linea() {
run_eth_e2e(
&Genesis::Linea,
"RPC_59144",
5600000,
Some(address!("8f81e2e3f8b46467523463835f965ffe476e1c9e")),
)
.await;
}
#[tokio::test(flavor = "multi_thread")]
async fn test_e2e_sepolia() {
run_eth_e2e(&Genesis::Sepolia, "RPC_11155111", 6804324, None).await;
}
async fn run_eth_e2e(
genesis: &Genesis,
env_var_key: &str,
block_number: u64,
custom_beneficiary: Option<Address>,
) {
let chain_spec: Arc<ChainSpec> = Arc::new(genesis.try_into().unwrap());
// Setup the host executor.
let host_executor = EthHostExecutor::eth(chain_spec.clone(), custom_beneficiary);
// Setup the client executor.
let guest_executor = EthClientExecutor::eth(chain_spec, custom_beneficiary);
run_e2e::<_, ChainSpec, Ethereum>(
host_executor,
guest_executor,
env_var_key,
block_number,
genesis,
custom_beneficiary,
)
.await;
}
async fn run_e2e<C, CS, N>(
host_executor: HostExecutor<C, CS>,
client_executor: ClientExecutor<C, CS>,
env_var_key: &str,
block_number: u64,
genesis: &Genesis,
custom_beneficiary: Option<Address>,
) where
C: ConfigureEvm,
C::Primitives: FromInput
+ IntoPrimitives<N>
+ IntoInput
+ BlockValidator<CS>
+ Serialize
+ DeserializeOwned,
N: Network,
{
// Intialize the environment variables.
dotenv::dotenv().ok();
// Initialize the logger.
let _ = tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.try_init();
// Setup the provider.
let rpc_url =
Url::parse(std::env::var(env_var_key).unwrap().as_str()).expect("invalid rpc url");
let provider = RootProvider::<N>::new_http(rpc_url);
// Execute the host.
let client_input = host_executor
.execute(block_number, &provider, &provider, genesis.clone(), custom_beneficiary, false)
.await
.expect("failed to execute host");
// Execute the client.
client_executor.execute(client_input.clone(), vec![]).expect("failed to execute client");
// Save the client input to a buffer.
let buffer = bincode::serialize(&client_input).unwrap();
// Load the client input from a buffer.
let _: ClientExecutorInput<C::Primitives> = bincode::deserialize(&buffer).unwrap();
}