Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Feb 23, 2024
1 parent d81ba7e commit 3813349
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 9 additions & 0 deletions crates/e2e/src/drink_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Client: E2EBackend>(mut client: Client) -> E2EResult<()> {
/// // ...
/// }
/// ```
pub struct Config;
impl SandboxConfig for Config {
type Runtime = parachain::Runtime;
Expand Down
20 changes: 12 additions & 8 deletions integration-tests/contract-xcm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#[ink::contract]
mod contract_xcm {
// use xcm::VersionedXcm;
use xcm::{
v4::prelude::*,
VersionedLocation,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand All @@ -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::<DefaultEnvironment>().bob,
2_000_000,
CONTRACT_BALANCE + 1,
);

let call_res = client
Expand Down Expand Up @@ -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");
Expand All @@ -268,7 +272,7 @@ mod contract_xcm {
});

let mut call_builder = contract.call_builder::<ContractXcm>();
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());
Expand All @@ -282,7 +286,7 @@ mod contract_xcm {
),
vec![BalanceLock {
id: *b"py/xcmlk",
amount: 500_000,
amount: TRANSFER_VALUE,
reasons: Reasons::All
}]
);
Expand Down

0 comments on commit 3813349

Please sign in to comment.