From 3813349a9b9357dac68188518beaa21fe6664b8d Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Fri, 23 Feb 2024 08:55:02 +0100 Subject: [PATCH] clean up --- crates/e2e/src/drink_client.rs | 9 +++++++++ integration-tests/contract-xcm/lib.rs | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/e2e/src/drink_client.rs b/crates/e2e/src/drink_client.rs index bdc7220545..78c3995433 100644 --- a/crates/e2e/src/drink_client.rs +++ b/crates/e2e/src/drink_client.rs @@ -471,6 +471,15 @@ pub mod preset { pub use pallet_contracts_mock_network::*; + /// A [`drink::SandboxConfig`] configuration that can be used to test contracts + /// with a mock network of relay chain and parachains. + /// + /// ```no_compile + /// #[ink_e2e::test(backend(runtime_only(runtime = mock_network::Config)))] + /// async fn my_test(mut client: Client) -> E2EResult<()> { + /// // ... + /// } + /// ``` pub struct Config; impl SandboxConfig for Config { type Runtime = parachain::Runtime; diff --git a/integration-tests/contract-xcm/lib.rs b/integration-tests/contract-xcm/lib.rs index 50c6f0d5d4..916248c9a3 100644 --- a/integration-tests/contract-xcm/lib.rs +++ b/integration-tests/contract-xcm/lib.rs @@ -2,7 +2,6 @@ #[ink::contract] mod contract_xcm { - // use xcm::VersionedXcm; use xcm::{ v4::prelude::*, VersionedLocation, @@ -14,8 +13,7 @@ mod contract_xcm { prelude::*, }; - /// A trivial contract with a single message, that uses `xcm_execute` API for - /// performing native token transfer. + /// A trivial contract used to exercise the XCM APIs. #[ink(storage)] #[derive(Default)] pub struct ContractXcm; @@ -78,6 +76,12 @@ mod contract_xcm { .map_err(Into::into) } + /// Sends an lock some funds to the relay chain. + /// + /// Fails if: + /// - called in the off-chain environment + /// - the chain is not configured with Xcm + /// - the XCM program executed failed (e.g contract doesn't have enough balance) #[ink(message)] pub fn lock_funds_to_relay( &mut self, @@ -198,7 +202,7 @@ mod contract_xcm { let mut constructor = ContractXcmRef::new(); let contract = client .instantiate("contract_xcm", &ink_e2e::alice(), &mut constructor) - .value(1_000_000) + .value(CONTRACT_BALANCE) .submit() .await .expect("instantiate failed"); @@ -207,7 +211,7 @@ mod contract_xcm { // This will fail since we have insufficient balance let transfer_message = call_builder.transfer_through_xcm( default_accounts::().bob, - 2_000_000, + CONTRACT_BALANCE + 1, ); let call_res = client @@ -243,7 +247,7 @@ mod contract_xcm { let mut constructor = ContractXcmRef::new(); let contract = client .instantiate("contract_xcm", &ink_e2e::alice(), &mut constructor) - .value(1_000_000) + .value(CONTRACT_BALANCE) .submit() .await .expect("instantiate failed"); @@ -268,7 +272,7 @@ mod contract_xcm { }); let mut call_builder = contract.call_builder::(); - let message = call_builder.lock_funds_to_relay(500_000, 8_000); + let message = call_builder.lock_funds_to_relay(TRANSFER_VALUE, 8_000); let call_res = client.call(&ink_e2e::alice(), &message).submit().await?; assert!(call_res.return_value().is_ok()); @@ -282,7 +286,7 @@ mod contract_xcm { ), vec![BalanceLock { id: *b"py/xcmlk", - amount: 500_000, + amount: TRANSFER_VALUE, reasons: Reasons::All }] );