2023-03-31 10:34:09 +00:00
|
|
|
pub mod tx;
|
|
|
|
pub mod validator_sets;
|
|
|
|
pub mod in_instructions;
|
2023-11-05 17:02:34 +00:00
|
|
|
pub mod dex;
|
2023-03-31 10:34:09 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! serai_test {
|
2023-10-23 04:33:38 +00:00
|
|
|
($($name: ident: $test: expr)*) => {
|
2023-03-31 10:34:09 +00:00
|
|
|
$(
|
|
|
|
#[tokio::test]
|
|
|
|
async fn $name() {
|
2023-10-23 04:33:38 +00:00
|
|
|
use dockertest::{
|
2023-10-23 10:59:38 +00:00
|
|
|
PullPolicy, StartPolicy, LogOptions, LogAction, LogPolicy, LogSource, Image,
|
|
|
|
TestBodySpecification, DockerTest,
|
2023-03-31 10:34:09 +00:00
|
|
|
};
|
|
|
|
|
2023-10-23 04:33:38 +00:00
|
|
|
serai_docker_tests::build("serai".to_string());
|
|
|
|
|
2023-10-23 10:59:38 +00:00
|
|
|
let handle = concat!("serai_client-serai_node-", stringify!($name));
|
|
|
|
|
|
|
|
let composition = TestBodySpecification::with_image(
|
2023-10-23 04:33:38 +00:00
|
|
|
Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never),
|
|
|
|
)
|
2023-10-23 10:59:38 +00:00
|
|
|
.replace_cmd(vec![
|
2023-10-23 04:33:38 +00:00
|
|
|
"serai-node".to_string(),
|
|
|
|
"--dev".to_string(),
|
|
|
|
"--unsafe-rpc-external".to_string(),
|
|
|
|
"--rpc-cors".to_string(),
|
|
|
|
"all".to_string(),
|
|
|
|
])
|
2023-10-23 10:59:38 +00:00
|
|
|
.set_publish_all_ports(true)
|
|
|
|
.set_handle(handle)
|
|
|
|
.set_start_policy(StartPolicy::Strict)
|
|
|
|
.set_log_options(Some(LogOptions {
|
2023-10-23 04:33:38 +00:00
|
|
|
action: LogAction::Forward,
|
|
|
|
policy: LogPolicy::Always,
|
|
|
|
source: LogSource::Both,
|
|
|
|
}));
|
|
|
|
|
2023-10-23 10:59:38 +00:00
|
|
|
let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
|
|
|
|
test.provide_container(composition);
|
2023-10-23 04:33:38 +00:00
|
|
|
test.run_async(|ops| async move {
|
|
|
|
// Sleep until the Substrate RPC starts
|
2023-10-23 10:59:38 +00:00
|
|
|
let serai_rpc = ops.handle(handle).host_port(9944).unwrap();
|
2023-10-23 04:33:38 +00:00
|
|
|
let serai_rpc = format!("ws://{}:{}", serai_rpc.0, serai_rpc.1);
|
|
|
|
// Bound execution to 60 seconds
|
|
|
|
for _ in 0 .. 60 {
|
|
|
|
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
|
|
|
|
let Ok(client) = Serai::new(&serai_rpc).await else { continue };
|
|
|
|
if client.latest_block_hash().await.is_err() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2023-03-31 10:34:09 +00:00
|
|
|
}
|
2023-10-23 04:33:38 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
|
|
|
$test(Serai::new(&serai_rpc).await.unwrap()).await;
|
2023-03-31 10:34:09 +00:00
|
|
|
}).await;
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|