diff --git a/smoketest/src/constants.rs b/smoketest/src/constants.rs index 3525fa7ef6..6920df3929 100644 --- a/smoketest/src/constants.rs +++ b/smoketest/src/constants.rs @@ -21,4 +21,7 @@ pub const GATEWAY_PROXY_CONTRACT: [u8; 20] = hex!("EDa338E4dC46038493b885327842f // Agent for sibling parachain 1001 pub const SIBLING_AGENT_ID: [u8; 32] = - hex!("2075b9f5bc236462eb1473c9a6236c3588e33ed19ead53aa3d9c62ed941cb793"); + hex!("2075b9f5bc236462eb1473c9a6236c3588e33ed19ead53aa3d9c62ed941cb793"); + +pub const BRIDGE_HUB_AGENT_ID: [u8; 32] = + hex!("05f0ced792884ed09997292bd95f8d0d1094bb3bded91ec3f2f08531624037d6"); diff --git a/smoketest/src/helper.rs b/smoketest/src/helper.rs index ffaaa1c47e..3623eaebff 100644 --- a/smoketest/src/helper.rs +++ b/smoketest/src/helper.rs @@ -1,328 +1,326 @@ -use crate::constants::*; -use crate::contracts::i_gateway; -use crate::parachains::bridgehub::{self}; -use crate::parachains::bridgehub::{ - api::runtime_types::bridge_hub_rococo_runtime::RuntimeCall as BHRuntimeCall, api::utility, +use crate::{ + constants::*, + contracts::i_gateway, + parachains::{ + bridgehub::{ + self, + api::{ + runtime_types::bridge_hub_rococo_runtime::RuntimeCall as BHRuntimeCall, utility, + }, + }, + relaychain, + relaychain::api::runtime_types::{ + pallet_xcm::pallet::Call as RelaychainPalletXcmCall, + rococo_runtime::RuntimeCall as RelaychainRuntimeCall, + sp_weights::weight_v2::Weight as RelaychainWeight, + xcm::{ + double_encoded::DoubleEncoded as RelaychainDoubleEncoded, + v2::OriginKind as RelaychainOriginKind, + v3::{ + junction::Junction as RelaychainJunction, + junctions::Junctions as RelaychainJunctions, + multilocation::MultiLocation as RelaychainMultiLocation, + Instruction as RelaychainInstruction, WeightLimit as RelaychainWeightLimit, + Xcm as RelaychainXcm, + }, + VersionedMultiLocation as RelaychainVersionedMultiLocation, + VersionedXcm as RelaychainVersionedXcm, + }, + }, + template::{ + api::runtime_types::xcm as templateXcm, + {self}, + }, + }, }; -use crate::parachains::relaychain; -use crate::parachains::relaychain::api::runtime_types::{ - pallet_xcm::pallet::Call as RelaychainPalletXcmCall, - rococo_runtime::RuntimeCall as RelaychainRuntimeCall, - sp_weights::weight_v2::Weight as RelaychainWeight, - xcm::{ - double_encoded::DoubleEncoded as RelaychainDoubleEncoded, - v2::OriginKind as RelaychainOriginKind, - v3::{ - junction::Junction as RelaychainJunction, junctions::Junctions as RelaychainJunctions, - multilocation::MultiLocation as RelaychainMultiLocation, - Instruction as RelaychainInstruction, WeightLimit as RelaychainWeightLimit, - Xcm as RelaychainXcm, - }, - VersionedMultiLocation as RelaychainVersionedMultiLocation, - VersionedXcm as RelaychainVersionedXcm, - }, +use ethers::{ + prelude::{ + Address, EthEvent, LocalWallet, Middleware, Provider, Signer, SignerMiddleware, + TransactionRequest, Ws, U256, + }, + providers::Http, }; -use crate::parachains::template::api::runtime_types::xcm as templateXcm; -use crate::parachains::template::{self}; -use ethers::prelude::{ - Address, EthEvent, LocalWallet, Middleware, Provider, Signer, SignerMiddleware, - TransactionRequest, Ws, U256, -}; -use ethers::providers::Http; use futures::StreamExt; use sp_core::{sr25519::Pair, Pair as PairT, H160}; -use std::ops::Deref; -use std::sync::Arc; -use std::time::Duration; -use subxt::blocks::ExtrinsicEvents; -use subxt::events::StaticEvent; -use subxt::tx::{PairSigner, TxPayload}; -use subxt::{Config, OnlineClient, PolkadotConfig}; +use std::{ops::Deref, sync::Arc, time::Duration}; +use subxt::{ + blocks::ExtrinsicEvents, + events::StaticEvent, + tx::{PairSigner, TxPayload}, + Config, OnlineClient, PolkadotConfig, +}; use templateXcm::{ - v3::{junction::Junction, junctions::Junctions, multilocation::MultiLocation}, - VersionedMultiLocation, VersionedXcm, + v3::{junction::Junction, junctions::Junctions, multilocation::MultiLocation}, + VersionedMultiLocation, VersionedXcm, }; /// Custom config that works with Statemint pub enum TemplateConfig {} impl Config for TemplateConfig { - type Index = ::Index; - type Hash = ::Hash; - type AccountId = ::AccountId; - type Address = ::Address; - type Signature = ::Signature; - type Hasher = ::Hasher; - type Header = ::Header; - type ExtrinsicParams = ::ExtrinsicParams; + type Index = ::Index; + type Hash = ::Hash; + type AccountId = ::AccountId; + type Address = ::Address; + type Signature = ::Signature; + type Hasher = ::Hasher; + type Header = ::Header; + type ExtrinsicParams = ::ExtrinsicParams; } pub struct TestClients { - pub bridge_hub_client: Box>, - pub template_client: Box>, - pub relaychain_client: Box>, - pub ethereum_client: Box>>, - pub ethereum_signed_client: Box, LocalWallet>>>, + pub bridge_hub_client: Box>, + pub template_client: Box>, + pub relaychain_client: Box>, + pub ethereum_client: Box>>, + pub ethereum_signed_client: Box, LocalWallet>>>, } pub async fn initial_clients() -> Result> { - let bridge_hub_client: OnlineClient = OnlineClient::from_url(BRIDGE_HUB_WS_URL) - .await - .expect("can not connect to assethub"); - - let template_client: OnlineClient = - OnlineClient::from_url(TEMPLATE_NODE_WS_URL) - .await - .expect("can not connect to assethub"); - - let relaychain_client: OnlineClient = - OnlineClient::from_url(RELAY_CHAIN_WS_URL) - .await - .expect("can not connect to relaychain"); - - let ethereum_provider = Provider::::connect(ETHEREUM_API) - .await - .unwrap() - .interval(Duration::from_millis(10u64)); - - let ethereum_client = Arc::new(ethereum_provider); - - let ethereum_signed_client = initialize_wallet().await.expect("initialize wallet"); - - Ok(TestClients { - bridge_hub_client: Box::new(bridge_hub_client), - template_client: Box::new(template_client), - relaychain_client: Box::new(relaychain_client), - ethereum_client: Box::new(ethereum_client), - ethereum_signed_client: Box::new(Arc::new(ethereum_signed_client)), - }) + let bridge_hub_client: OnlineClient = OnlineClient::from_url(BRIDGE_HUB_WS_URL) + .await + .expect("can not connect to assethub"); + + let template_client: OnlineClient = + OnlineClient::from_url(TEMPLATE_NODE_WS_URL) + .await + .expect("can not connect to assethub"); + + let relaychain_client: OnlineClient = + OnlineClient::from_url(RELAY_CHAIN_WS_URL) + .await + .expect("can not connect to relaychain"); + + let ethereum_provider = Provider::::connect(ETHEREUM_API) + .await + .unwrap() + .interval(Duration::from_millis(10u64)); + + let ethereum_client = Arc::new(ethereum_provider); + + let ethereum_signed_client = initialize_wallet().await.expect("initialize wallet"); + + Ok(TestClients { + bridge_hub_client: Box::new(bridge_hub_client), + template_client: Box::new(template_client), + relaychain_client: Box::new(relaychain_client), + ethereum_client: Box::new(ethereum_client), + ethereum_signed_client: Box::new(Arc::new(ethereum_signed_client)), + }) } pub async fn wait_for_bridgehub_event( - bridge_hub_client: &Box>, + bridge_hub_client: &Box>, ) { - let mut blocks = bridge_hub_client - .blocks() - .subscribe_finalized() - .await - .expect("block subscription") - .take(5); - - let mut substrate_event_found = false; - while let Some(Ok(block)) = blocks.next().await { - println!( - "Polling bridgehub block {} for expected event.", - block.number() - ); - let events = block.events().await.expect("read block events"); - for event in events.find::() { - let _ = event.expect("expect upgrade"); - println!("Event found at bridgehub block {}.", block.number()); - substrate_event_found = true; - break; - } - if substrate_event_found { - break; - } - } - assert!(substrate_event_found); + let mut blocks = bridge_hub_client + .blocks() + .subscribe_finalized() + .await + .expect("block subscription") + .take(5); + + let mut substrate_event_found = false; + while let Some(Ok(block)) = blocks.next().await { + println!("Polling bridgehub block {} for expected event.", block.number()); + let events = block.events().await.expect("read block events"); + for event in events.find::() { + let _ = event.expect("expect upgrade"); + println!("Event found at bridgehub block {}.", block.number()); + substrate_event_found = true; + break + } + if substrate_event_found { + break + } + } + assert!(substrate_event_found); } pub async fn wait_for_ethereum_event(ethereum_client: &Box>>) { - let gateway_addr: Address = GATEWAY_PROXY_CONTRACT.into(); - let gateway = i_gateway::IGateway::new(gateway_addr, (*ethereum_client).deref().clone()); - - let wait_for_blocks = 300; - let mut stream = ethereum_client - .subscribe_blocks() - .await - .unwrap() - .take(wait_for_blocks); - - let mut ethereum_event_found = false; - while let Some(block) = stream.next().await { - println!( - "Polling ethereum block {:?} for expected event", - block.number.unwrap() - ); - if let Ok(events) = gateway - .event::() - .at_block_hash(block.hash.unwrap()) - .query() - .await - { - for _ in events { - println!("Event found at ethereum block {:?}", block.number.unwrap()); - ethereum_event_found = true; - break; - } - } - if ethereum_event_found { - break; - } - } - assert!(ethereum_event_found); + let gateway_addr: Address = GATEWAY_PROXY_CONTRACT.into(); + let gateway = i_gateway::IGateway::new(gateway_addr, (*ethereum_client).deref().clone()); + + let wait_for_blocks = 300; + let mut stream = ethereum_client.subscribe_blocks().await.unwrap().take(wait_for_blocks); + + let mut ethereum_event_found = false; + while let Some(block) = stream.next().await { + println!("Polling ethereum block {:?} for expected event", block.number.unwrap()); + if let Ok(events) = gateway.event::().at_block_hash(block.hash.unwrap()).query().await { + for _ in events { + println!("Event found at ethereum block {:?}", block.number.unwrap()); + ethereum_event_found = true; + break + } + } + if ethereum_event_found { + break + } + } + assert!(ethereum_event_found); } pub async fn send_xcm_transact( - template_client: &Box>, - message: Box, + template_client: &Box>, + message: Box, ) -> Result, Box> { - let dest = Box::new(VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: Junctions::X1(Junction::Parachain(BRIDGE_HUB_PARA_ID)), - })); + let dest = Box::new(VersionedMultiLocation::V3(MultiLocation { + parents: 1, + interior: Junctions::X1(Junction::Parachain(BRIDGE_HUB_PARA_ID)), + })); - let xcm_call = template::api::template_pallet::calls::TransactionApi.send_xcm(*dest, *message); + let xcm_call = template::api::template_pallet::calls::TransactionApi.send_xcm(*dest, *message); - let owner: Pair = Pair::from_string("//Alice", None).expect("cannot create keypair"); + let owner: Pair = Pair::from_string("//Alice", None).expect("cannot create keypair"); - let signer: PairSigner = PairSigner::new(owner); + let signer: PairSigner = PairSigner::new(owner); - let result = template_client - .tx() - .sign_and_submit_then_watch_default(&xcm_call, &signer) - .await - .expect("send through xcm call.") - .wait_for_finalized_success() - .await - .expect("xcm call failed"); + let result = template_client + .tx() + .sign_and_submit_then_watch_default(&xcm_call, &signer) + .await + .expect("send through xcm call.") + .wait_for_finalized_success() + .await + .expect("xcm call failed"); - Ok(result) + Ok(result) } pub async fn initialize_wallet( ) -> Result, LocalWallet>, Box> { - let provider = Provider::::try_from(ETHEREUM_HTTP_API) - .unwrap() - .interval(Duration::from_millis(10u64)); + let provider = Provider::::try_from(ETHEREUM_HTTP_API) + .unwrap() + .interval(Duration::from_millis(10u64)); - let wallet: LocalWallet = ETHEREUM_KEY - .parse::() - .unwrap() - .with_chain_id(ETHEREUM_CHAIN_ID); + let wallet: LocalWallet = + ETHEREUM_KEY.parse::().unwrap().with_chain_id(ETHEREUM_CHAIN_ID); - Ok(SignerMiddleware::new(provider.clone(), wallet.clone())) + Ok(SignerMiddleware::new(provider.clone(), wallet.clone())) } pub async fn get_balance( - client: &Box, LocalWallet>>>, - who: Address, + client: &Box, LocalWallet>>>, + who: Address, ) -> Result> { - let balance = client.get_balance(who, None).await?; + let balance = client.get_balance(who, None).await?; - Ok(balance) + Ok(balance) } pub async fn fund_account( - client: &Box, LocalWallet>>>, - address_to: Address, + client: &Box, LocalWallet>>>, + address_to: Address, ) -> Result<(), Box> { - let tx = TransactionRequest::new() - .to(address_to) - .from(client.address()) - .value(U256::from(ethers::utils::parse_ether(1)?)); - let tx = client.send_transaction(tx, None).await?.await?; - assert_eq!(tx.clone().unwrap().status.unwrap().as_u64(), 1u64); - println!("receipt: {:#?}", hex::encode(tx.unwrap().transaction_hash)); - Ok(()) + let tx = TransactionRequest::new() + .to(address_to) + .from(client.address()) + .value(U256::from(ethers::utils::parse_ether(1)?)); + let tx = client.send_transaction(tx, None).await?.await?; + assert_eq!(tx.clone().unwrap().status.unwrap().as_u64(), 1u64); + println!("receipt: {:#?}", hex::encode(tx.unwrap().transaction_hash)); + Ok(()) } pub async fn construct_create_agent_call( - bridge_hub_client: &Box>, + bridge_hub_client: &Box>, ) -> Result, Box> { - let call = bridgehub::api::ethereum_control::calls::TransactionApi - .create_agent() - .encode_call_data(&bridge_hub_client.metadata())?; + let call = bridgehub::api::ethereum_control::calls::TransactionApi + .create_agent() + .encode_call_data(&bridge_hub_client.metadata())?; - Ok(call) + Ok(call) } pub async fn construct_create_channel_call( - bridge_hub_client: &Box>, + bridge_hub_client: &Box>, ) -> Result, Box> { - let call = bridgehub::api::ethereum_control::calls::TransactionApi - .create_channel() - .encode_call_data(&bridge_hub_client.metadata())?; + let call = bridgehub::api::ethereum_control::calls::TransactionApi + .create_channel() + .encode_call_data(&bridge_hub_client.metadata())?; - Ok(call) + Ok(call) } pub async fn construct_transfer_native_from_agent_call( - bridge_hub_client: &Box>, - recipient: H160, - amount: u128, + bridge_hub_client: &Box>, + recipient: H160, + amount: u128, ) -> Result, Box> { - let call = bridgehub::api::ethereum_control::calls::TransactionApi - .transfer_native_from_agent(recipient, amount) - .encode_call_data(&bridge_hub_client.metadata())?; + let call = bridgehub::api::ethereum_control::calls::TransactionApi + .transfer_native_from_agent(recipient, amount) + .encode_call_data(&bridge_hub_client.metadata())?; - Ok(call) + Ok(call) } pub async fn governance_bridgehub_call_from_relay_chain( - calls: Vec, + calls: Vec, ) -> Result<(), Box> { - let test_clients = initial_clients().await.expect("initialize clients"); - - let sudo: Pair = Pair::from_string("//Alice", None).expect("cannot create sudo keypair"); - - let signer: PairSigner = PairSigner::new(sudo); - - let utility_api = utility::calls::TransactionApi; - let batch_call = utility_api - .batch_all(calls) - .encode_call_data(&test_clients.bridge_hub_client.metadata()) - .expect("encoded call"); - - let weight = 180000000000; - let proof_size = 900000; - - let dest = Box::new(RelaychainVersionedMultiLocation::V3( - RelaychainMultiLocation { - parents: 0, - interior: RelaychainJunctions::X1(RelaychainJunction::Parachain(BRIDGE_HUB_PARA_ID)), - }, - )); - let message = Box::new(RelaychainVersionedXcm::V3(RelaychainXcm(vec![ - RelaychainInstruction::UnpaidExecution { - weight_limit: RelaychainWeightLimit::Limited(RelaychainWeight { - ref_time: weight, - proof_size, - }), - check_origin: None, - }, - RelaychainInstruction::Transact { - origin_kind: RelaychainOriginKind::Superuser, - require_weight_at_most: RelaychainWeight { - ref_time: weight, - proof_size, - }, - call: RelaychainDoubleEncoded { - encoded: batch_call, - }, - }, - ]))); - - let sudo_api = relaychain::api::sudo::calls::TransactionApi; - let sudo_call = sudo_api.sudo(RelaychainRuntimeCall::XcmPallet( - RelaychainPalletXcmCall::send { dest, message }, - )); - - let result = test_clients - .relaychain_client - .tx() - .sign_and_submit_then_watch_default(&sudo_call, &signer) - .await - .expect("send through sudo call.") - .wait_for_finalized_success() - .await - .expect("sudo call success"); - - println!( - "Sudo call issued at relaychain block hash {:?}", - result.block_hash() - ); - - Ok(()) + let test_clients = initial_clients().await.expect("initialize clients"); + + let sudo: Pair = Pair::from_string("//Alice", None).expect("cannot create sudo keypair"); + + let signer: PairSigner = PairSigner::new(sudo); + + let utility_api = utility::calls::TransactionApi; + let batch_call = utility_api + .batch_all(calls) + .encode_call_data(&test_clients.bridge_hub_client.metadata()) + .expect("encoded call"); + + let weight = 180000000000; + let proof_size = 900000; + + let dest = Box::new(RelaychainVersionedMultiLocation::V3(RelaychainMultiLocation { + parents: 0, + interior: RelaychainJunctions::X1(RelaychainJunction::Parachain(BRIDGE_HUB_PARA_ID)), + })); + let message = Box::new(RelaychainVersionedXcm::V3(RelaychainXcm(vec![ + RelaychainInstruction::UnpaidExecution { + weight_limit: RelaychainWeightLimit::Limited(RelaychainWeight { + ref_time: weight, + proof_size, + }), + check_origin: None, + }, + RelaychainInstruction::Transact { + origin_kind: RelaychainOriginKind::Superuser, + require_weight_at_most: RelaychainWeight { ref_time: weight, proof_size }, + call: RelaychainDoubleEncoded { encoded: batch_call }, + }, + ]))); + + let sudo_api = relaychain::api::sudo::calls::TransactionApi; + let sudo_call = sudo_api + .sudo(RelaychainRuntimeCall::XcmPallet(RelaychainPalletXcmCall::send { dest, message })); + + let result = test_clients + .relaychain_client + .tx() + .sign_and_submit_then_watch_default(&sudo_call, &signer) + .await + .expect("send through sudo call.") + .wait_for_finalized_success() + .await + .expect("sudo call success"); + + println!("Sudo call issued at relaychain block hash {:?}", result.block_hash()); + + Ok(()) +} + +pub async fn fund_agent(agent_id: [u8; 32]) -> Result<(), Box> { + let test_clients = initial_clients().await.expect("initialize clients"); + let gateway_addr: Address = GATEWAY_PROXY_CONTRACT.into(); + let ethereum_client = *(test_clients.ethereum_client.clone()); + let gateway = i_gateway::IGateway::new(gateway_addr, ethereum_client.clone()); + let agent_address = gateway.agent_of(agent_id).await.expect("find agent"); + + println!("agent address {}", hex::encode(agent_address)); + + fund_account(&test_clients.ethereum_signed_client, agent_address) + .await + .expect("fund account"); + Ok(()) } diff --git a/smoketest/tests/create_agent.rs b/smoketest/tests/create_agent.rs index 93188c0e2d..7baaf54d5a 100644 --- a/smoketest/tests/create_agent.rs +++ b/smoketest/tests/create_agent.rs @@ -1,29 +1,33 @@ -use snowbridge_smoketest::contracts::i_gateway::AgentCreatedFilter; -use snowbridge_smoketest::helper::*; -use snowbridge_smoketest::parachains::bridgehub::api::ethereum_control::events::CreateAgent; -use snowbridge_smoketest::xcm::construct_xcm_message; +use snowbridge_smoketest::{ + constants::SIBLING_AGENT_ID, contracts::i_gateway::AgentCreatedFilter, helper::*, + parachains::bridgehub::api::ethereum_control::events::CreateAgent, xcm::construct_xcm_message, +}; #[tokio::test] async fn create_agent() { - let test_clients = initial_clients().await.expect("initialize clients"); + let test_clients = initial_clients().await.expect("initialize clients"); - let message = construct_xcm_message( - construct_create_agent_call(&test_clients.bridge_hub_client) - .await - .expect("construct innner call."), - ); + let message = construct_xcm_message( + construct_create_agent_call(&test_clients.bridge_hub_client) + .await + .expect("construct innner call."), + ); - let result = send_xcm_transact(&test_clients.template_client, message) - .await - .expect("failed to send xcm transact."); + let result = send_xcm_transact(&test_clients.template_client, message) + .await + .expect("failed to send xcm transact."); - println!( - "xcm call issued at block hash {:?}, transaction hash {:?}", - result.block_hash(), - result.extrinsic_hash() - ); + println!( + "xcm call issued at block hash {:?}, transaction hash {:?}", + result.block_hash(), + result.extrinsic_hash() + ); - wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; + wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; - wait_for_ethereum_event::(&test_clients.ethereum_client).await; + wait_for_ethereum_event::(&test_clients.ethereum_client).await; + + // after agent created we fund it with some initial reserve for later tests like + // create_channel + fund_agent(SIBLING_AGENT_ID).await.expect("fund bridgeHub agent"); } diff --git a/smoketest/tests/create_channel.rs b/smoketest/tests/create_channel.rs index 4cd43b3c50..3d6bb9d1fd 100644 --- a/smoketest/tests/create_channel.rs +++ b/smoketest/tests/create_channel.rs @@ -1,29 +1,30 @@ -use snowbridge_smoketest::contracts::i_gateway::ChannelCreatedFilter; -use snowbridge_smoketest::helper::*; -use snowbridge_smoketest::parachains::bridgehub::api::ethereum_control::events::CreateChannel; -use snowbridge_smoketest::xcm::construct_xcm_message; +use snowbridge_smoketest::{ + contracts::i_gateway::ChannelCreatedFilter, helper::*, + parachains::bridgehub::api::ethereum_control::events::CreateChannel, + xcm::construct_xcm_message, +}; #[tokio::test] async fn create_channel() { - let test_clients = initial_clients().await.expect("initialize clients"); + let test_clients = initial_clients().await.expect("initialize clients"); - let message = construct_xcm_message( - construct_create_channel_call(&test_clients.bridge_hub_client) - .await - .expect("construct innner call."), - ); + let message = construct_xcm_message( + construct_create_channel_call(&test_clients.bridge_hub_client) + .await + .expect("construct innner call."), + ); - let result = send_xcm_transact(&test_clients.template_client, message) - .await - .expect("failed to send xcm transact."); + let result = send_xcm_transact(&test_clients.template_client, message) + .await + .expect("failed to send xcm transact."); - println!( - "xcm call issued at block hash {:?}, transaction hash {:?}", - result.block_hash(), - result.extrinsic_hash() - ); + println!( + "xcm call issued at block hash {:?}, transaction hash {:?}", + result.block_hash(), + result.extrinsic_hash() + ); - wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; + wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; - wait_for_ethereum_event::(&test_clients.ethereum_client).await; + wait_for_ethereum_event::(&test_clients.ethereum_client).await; } diff --git a/smoketest/tests/transfer_native_from_agent.rs b/smoketest/tests/transfer_native_from_agent.rs index d686640d9c..69200d0291 100644 --- a/smoketest/tests/transfer_native_from_agent.rs +++ b/smoketest/tests/transfer_native_from_agent.rs @@ -1,71 +1,49 @@ -use ethers::prelude::Address; -use snowbridge_smoketest::constants::*; -use snowbridge_smoketest::contracts::i_gateway; -use snowbridge_smoketest::contracts::i_gateway::InboundMessageDispatchedFilter; -use snowbridge_smoketest::helper::*; -use snowbridge_smoketest::parachains::bridgehub::api::ethereum_control::events::TransferNativeFromAgent; -use snowbridge_smoketest::xcm::construct_xcm_message; +use snowbridge_smoketest::{ + constants::*, contracts::i_gateway::InboundMessageDispatchedFilter, helper::*, + parachains::bridgehub::api::ethereum_control::events::TransferNativeFromAgent, + xcm::construct_xcm_message, +}; #[tokio::test] async fn transfer_native_from_agent() { - let test_clients = initial_clients().await.expect("initialize clients"); + let test_clients = initial_clients().await.expect("initialize clients"); - let gateway_addr: Address = GATEWAY_PROXY_CONTRACT.into(); - let ethereum_client = *(test_clients.ethereum_client.clone()); - let gateway = i_gateway::IGateway::new(gateway_addr, ethereum_client.clone()); - let agent_address = gateway - .agent_of(SIBLING_AGENT_ID) - .await - .expect("find agent"); + let before = get_balance(&test_clients.ethereum_signed_client, ETHEREUM_ADDRESS.into()) + .await + .expect("get balance"); - println!("agent address {}", hex::encode(agent_address)); + println!("balance before: {}", before); - fund_account(&test_clients.ethereum_signed_client, agent_address) - .await - .expect("fund account"); + const TRANSFER_AMOUNT: u128 = 1000000000; - let before = get_balance( - &test_clients.ethereum_signed_client, - ETHEREUM_ADDRESS.into(), - ) - .await - .expect("get balance"); + let message = construct_xcm_message( + construct_transfer_native_from_agent_call( + &test_clients.bridge_hub_client, + ETHEREUM_ADDRESS.into(), + TRANSFER_AMOUNT, + ) + .await + .expect("construct innner call."), + ); - println!("balance before: {}", before); + let result = send_xcm_transact(&test_clients.template_client, message) + .await + .expect("failed to send xcm transact."); - const TRANSFER_AMOUNT: u128 = 1000000000; + println!( + "xcm call issued at block hash {:?}, transaction hash {:?}", + result.block_hash(), + result.extrinsic_hash() + ); - let message = construct_xcm_message( - construct_transfer_native_from_agent_call( - &test_clients.bridge_hub_client, - ETHEREUM_ADDRESS.into(), - TRANSFER_AMOUNT, - ) - .await - .expect("construct innner call."), - ); + wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; - let result = send_xcm_transact(&test_clients.template_client, message) - .await - .expect("failed to send xcm transact."); + wait_for_ethereum_event::(&test_clients.ethereum_client).await; - println!( - "xcm call issued at block hash {:?}, transaction hash {:?}", - result.block_hash(), - result.extrinsic_hash() - ); + let after = get_balance(&test_clients.ethereum_signed_client, ETHEREUM_ADDRESS.into()) + .await + .expect("get balance"); - wait_for_bridgehub_event::(&test_clients.bridge_hub_client).await; - - wait_for_ethereum_event::(&test_clients.ethereum_client).await; - - let after = get_balance( - &test_clients.ethereum_signed_client, - ETHEREUM_ADDRESS.into(), - ) - .await - .expect("get balance"); - - println!("balance after: {}", after); - assert_eq!(before + TRANSFER_AMOUNT, after); + println!("balance after: {}", after); + assert_eq!(before + TRANSFER_AMOUNT, after); } diff --git a/web/packages/test/scripts/set-env.sh b/web/packages/test/scripts/set-env.sh index 1e43290d7f..725624da71 100755 --- a/web/packages/test/scripts/set-env.sh +++ b/web/packages/test/scripts/set-env.sh @@ -95,7 +95,7 @@ export REGISTER_NATIVE_TOKEN_FEE="${ETH_REGISTER_NATIVE_TOKEN_FEE:-0}" export SEND_NATIVE_TOKEN_FEE="${ETH_SEND_NATIVE_TOKEN_FEE:-0}" ## Vault -export BRIDGE_HUB_INITIAL_DEPOSIT="${ETH_BRIDGE_HUB_INITIAL_DEPOSIT:-1000}" +export BRIDGE_HUB_INITIAL_DEPOSIT="${ETH_BRIDGE_HUB_INITIAL_DEPOSIT:-1000000000000000000}" ## BaseFee to cover the cost of an Ethereum no-op dispatchable in DOT, default 0.1 DOT export BASE_FEE="${BASE_FEE:-100000000000}"