1use std::sync::Arc;
2
3use candid::{decode_one, encode_one, CandidType};
4use icp::http_outcalls::handle_http_outcalls;
5use serde::Deserialize;
6use tokio::task;
7
8mod evm;
9mod icp;
10
11pub use crate::{
12 evm::{Evm, EvmUser},
13 icp::caller::{CallBuilder, CallError, CallMode, Caller},
14 icp::deployer::{DeployBuilder, DeployError, DeployMode, Deployer},
15 icp::user::IcpUser,
16 icp::Icp,
17};
18
19pub struct IcpTest {
20 pub icp: Icp,
21 pub evm: Evm,
22}
23
24impl IcpTest {
25 pub async fn new() -> Self {
26 let result = Self {
27 icp: Icp::new().await,
28 evm: Evm::new(),
29 };
30
31 let pic = Arc::downgrade(&result.icp.pic);
32 task::spawn(handle_http_outcalls(
33 pic,
34 result.evm.rpc_url(),
35 vec![result.evm.rpc_url().to_string()],
36 ));
37 result
38 }
39
40 pub async fn tick(&self) {
41 self.icp.tick().await;
42 self.evm.mine_block().await;
43 }
44}
45
46pub fn convert<F, T>(value: F) -> T
47where
48 F: CandidType,
49 T: for<'a> Deserialize<'a> + CandidType,
50{
51 decode_one(&encode_one(&value).unwrap()).unwrap()
52}