diff --git a/smoketest/make-bindings.sh b/smoketest/make-bindings.sh index b6fb1cf0d4..9f19656d40 100755 --- a/smoketest/make-bindings.sh +++ b/smoketest/make-bindings.sh @@ -6,7 +6,7 @@ mkdir -p src/contracts # Generate Rust bindings for contracts forge bind --module --overwrite \ - --select 'IGateway|WETH9|GatewayUpgradeMock' \ + --select 'IGateway|WETH9|GatewayUpgradeMock|AgentExecutor' \ --bindings-path src/contracts \ --root ../contracts diff --git a/smoketest/src/constants.rs b/smoketest/src/constants.rs index f72404a595..5bd625b37d 100644 --- a/smoketest/src/constants.rs +++ b/smoketest/src/constants.rs @@ -25,6 +25,7 @@ pub const ETHEREUM_ADDRESS: [u8; 20] = hex!("90A987B944Cb1dCcE5564e5FDeCD7a54D3d // the order in contracts are deployed in DeployScript.sol. pub const GATEWAY_PROXY_CONTRACT: [u8; 20] = hex!("EDa338E4dC46038493b885327842fD3E301CaB39"); pub const WETH_CONTRACT: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d"); +pub const AGENT_EXECUTOR_CONTRACT: [u8; 20] = hex!("2ffA5ecdBe006d30397c7636d3e015EEE251369F"); // Agent for bridge hub parachain 1013 pub const BRIDGE_HUB_AGENT_ID: [u8; 32] = diff --git a/smoketest/src/helper.rs b/smoketest/src/helper.rs index e470245f45..f67a04e66a 100644 --- a/smoketest/src/helper.rs +++ b/smoketest/src/helper.rs @@ -7,7 +7,8 @@ use crate::{ api::{ runtime_types, runtime_types::{ - snowbridge_core::outbound::v1::OperatingMode, xcm::VersionedLocation, + snowbridge_core::outbound::v1::OperatingMode, + staging_xcm::v4::junction::NetworkId, xcm::VersionedLocation, }, }, }, @@ -172,7 +173,7 @@ pub async fn wait_for_ethereum_event(ethereum_client: &Box::connect(ETHEREUM_API) + .await + .unwrap() + .interval(Duration::from_millis(10u64)); + + let ethereum_client = Arc::new(ethereum_provider); + + let gateway = IGateway::new(GATEWAY_PROXY_CONTRACT, ethereum_client.clone()); + let _agent_src = + gateway.agent_of(ASSET_HUB_AGENT_ID).await.expect("could not get agent address"); + + let assethub: OnlineClient = + OnlineClient::from_url(ASSET_HUB_WS_URL).await.unwrap(); + + let amount: u128 = 1_000_000_000; + let assets = VersionedAssets::V3(MultiAssets(vec![MultiAsset { + id: AssetId::Concrete(MultiLocation { parents: 1, interior: Junctions::Here }), + fun: Fungibility::Fungible(amount), + }])); + + let destination = VersionedLocation::V3(MultiLocation { + parents: 2, + interior: Junctions::X1(Junction::GlobalConsensus(NetworkId::Ethereum { + chain_id: ETHEREUM_CHAIN_ID, + })), + }); + + let beneficiary = VersionedLocation::V3(MultiLocation { + parents: 0, + interior: Junctions::X1(Junction::AccountKey20 { + network: None, + key: DESTINATION_ADDRESS.into(), + }), + }); + + let signer = dev::bob(); + + let token_transfer_call = + TransactionApi.reserve_transfer_assets(destination, beneficiary, assets, 0); + + let _ = assethub + .tx() + .sign_and_submit_then_watch_default(&token_transfer_call, &signer) + .await + .expect("call success"); + + let agent_executor_addr: Address = AGENT_EXECUTOR_CONTRACT.into(); + let agent_executor = + agent_executor::AgentExecutor::new(agent_executor_addr, ethereum_client.clone()); + + let wait_for_blocks = 500; + let mut stream = ethereum_client.subscribe_blocks().await.unwrap().take(wait_for_blocks); + + let mut transfer_event_found = false; + while let Some(block) = stream.next().await { + println!("Polling ethereum block {:?} for transfer event", block.number.unwrap()); + if let Ok(transfers) = agent_executor + .event::() + .at_block_hash(block.hash.unwrap()) + .query() + .await + { + for transfer in transfers { + println!("Transfer event found at ethereum block {:?}", block.number.unwrap()); + println!("token id {:?}", transfer.token_id); + transfer_event_found = true; + } + } + if transfer_event_found { + break + } + } + assert!(transfer_event_found); +}