-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate integration tests (#29)
- Loading branch information
1 parent
1691e43
commit a43182d
Showing
4 changed files
with
96 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use alloy_provider::ReqwestProvider; | ||
use rsp_client_executor::{ | ||
io::ClientExecutorInput, ClientExecutor, EthereumVariant, OptimismVariant, Variant, | ||
}; | ||
use rsp_host_executor::HostExecutor; | ||
use tracing_subscriber::{ | ||
filter::EnvFilter, fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, | ||
}; | ||
use url::Url; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_e2e_ethereum() { | ||
run_e2e::<EthereumVariant>("RPC_1", 18884864).await; | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_e2e_optimism() { | ||
run_e2e::<OptimismVariant>("RPC_10", 122853660).await; | ||
} | ||
|
||
async fn run_e2e<V>(env_var_key: &str, block_number: u64) | ||
where | ||
V: Variant, | ||
{ | ||
// 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 = ReqwestProvider::new_http(rpc_url); | ||
|
||
// Setup the host executor. | ||
let host_executor = HostExecutor::new(provider); | ||
|
||
// Execute the host. | ||
let (client_input, _) = | ||
host_executor.execute(block_number).await.expect("failed to execute host"); | ||
|
||
// Setup the client executor. | ||
let client_executor = ClientExecutor; | ||
|
||
// Execute the client. | ||
client_executor.execute::<V>(client_input.clone()).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 = bincode::deserialize(&buffer).unwrap(); | ||
} |