Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Asset transfer to penpal #34

Merged
merged 10 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
Balances: penpal_runtime::Balances,
}
},
Expand All @@ -59,6 +60,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: penpal_runtime::PolkadotXcm,
Assets: penpal_runtime::Assets,
ForeignAssets: penpal_runtime::ForeignAssets,
Balances: penpal_runtime::Balances,
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ asset-hub-rococo-emulated-chain = { path = "../../chains/parachains/assets/asset
asset-hub-wococo-emulated-chain = { path = "../../chains/parachains/assets/asset-hub-wococo" }
bridge-hub-rococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-rococo" }
bridge-hub-wococo-emulated-chain = { path = "../../chains/parachains/bridges/bridge-hub-wococo" }
penpal-emulated-chain = { path = "../../chains/parachains/testing/penpal" }
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ pub use asset_hub_rococo_emulated_chain;
pub use asset_hub_wococo_emulated_chain;
pub use bridge_hub_rococo_emulated_chain;
pub use bridge_hub_wococo_emulated_chain;
pub use penpal_emulated_chain;
pub use rococo_emulated_chain;
pub use wococo_emulated_chain;

use asset_hub_rococo_emulated_chain::AssetHubRococo;
use asset_hub_wococo_emulated_chain::AssetHubWococo;
use bridge_hub_rococo_emulated_chain::BridgeHubRococo;
use bridge_hub_wococo_emulated_chain::BridgeHubWococo;
use penpal_emulated_chain::PenpalA;
use rococo_emulated_chain::Rococo;
use wococo_emulated_chain::Wococo;

Expand All @@ -43,6 +45,7 @@ decl_test_networks! {
parachains = vec![
AssetHubRococo,
BridgeHubRococo,
PenpalA,
],
bridge = RococoWococoMockBridge

Expand Down Expand Up @@ -90,5 +93,6 @@ decl_test_sender_receiver_accounts_parameter_types! {
BridgeHubRococoPara { sender: ALICE, receiver: BOB },
WococoRelay { sender: ALICE, receiver: BOB },
AssetHubWococoPara { sender: ALICE, receiver: BOB },
BridgeHubWococoPara { sender: ALICE, receiver: BOB }
BridgeHubWococoPara { sender: ALICE, receiver: BOB },
PenpalAPara { sender: ALICE, receiver: BOB }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ emulated-integration-tests-common = { path = "../../../common", default-features
rococo-wococo-system-emulated-network = { path = "../../../networks/rococo-wococo-system" }
bridge-hub-rococo-emulated-chain = { path = "../../../chains/parachains/bridges/bridge-hub-rococo"}
asset-hub-rococo-emulated-chain = { path = "../../../chains/parachains/assets/asset-hub-rococo"}
penpal-emulated-chain = { path = "../../../chains/parachains/testing/penpal" }

# Snowbridge
snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ pub use rococo_wococo_system_emulated_network::{
bridge_hub_rococo_emulated_chain::{
genesis::ED as BRIDGE_HUB_ROCOCO_ED, BridgeHubRococoParaPallet as BridgeHubRococoPallet,
},
penpal_emulated_chain::PenpalAParaPallet as PenpalAPallet,
rococo_emulated_chain::{genesis::ED as ROCOCO_ED, RococoRelayPallet as RococoPallet},
AssetHubRococoPara as AssetHubRococo, AssetHubRococoParaReceiver as AssetHubRococoReceiver,
AssetHubRococoParaSender as AssetHubRococoSender, AssetHubWococoPara as AssetHubWococo,
BridgeHubRococoPara as BridgeHubRococo, BridgeHubRococoParaReceiver as BridgeHubRococoReceiver,
BridgeHubRococoParaSender as BridgeHubRococoSender, BridgeHubWococoPara as BridgeHubWococo,
RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver,
RococoRelaySender as RococoSender,
PenpalAPara as PenpalA, PenpalAParaSender as PenpalASender, PenpalAParaReceiver as PenpalAReceiver,
RococoRelay as Rococo, RococoRelayReceiver as RococoReceiver, RococoRelaySender as RococoSender,
};

pub const ASSET_ID: u32 = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ use sp_core::H256;

const INITIAL_FUND: u128 = 5_000_000_000 * ROCOCO_ED;
const CHAIN_ID: u64 = 15;
const DEST_PARA_ID: u32 = 1000;
const ASSETHUB_PARA_ID: u32 = 1000;
const TREASURY_ACCOUNT: [u8; 32] =
hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000");
const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d");
const ASSETHUB_SOVEREIGN: [u8; 32] =
hex!("7369626ce8030000000000000000000000000000000000000000000000000000");
const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");

#[test]
Expand Down Expand Up @@ -188,7 +186,7 @@ fn register_token() {
BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(MultiLocation {
parents: 1,
interior: X1(Parachain(DEST_PARA_ID)),
interior: X1(Parachain(ASSETHUB_PARA_ID)),
}),
INITIAL_FUND,
)]);
Expand All @@ -204,7 +202,7 @@ fn register_token() {
command: Command::RegisterToken { token: WETH.into() },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, DEST_PARA_ID.into()).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();

assert_expected_events!(
BridgeHubRococo,
Expand All @@ -227,21 +225,47 @@ fn register_token() {
}

#[test]
fn send_token() {
BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(MultiLocation {
fn send_token_to_penpal() {
let asset_hub_sovereign = BridgeHubRococo::sovereign_account_id_of(
MultiLocation {
parents: 1,
interior: X1(Parachain(DEST_PARA_ID)),
}),
interior: X1(Parachain(ASSETHUB_PARA_ID)),
}
);
BridgeHubRococo::fund_accounts(vec![(
asset_hub_sovereign.clone(),
INITIAL_FUND,
)]);

// Fund ethereum sovereign in asset hub
AssetHubRococo::fund_accounts(vec![
(ASSETHUB_SOVEREIGN.into(), INITIAL_FUND),
(AssetHubRococoReceiver::get(), INITIAL_FUND),
]);

PenpalA::fund_accounts(vec![
(PenpalAReceiver::get(), INITIAL_FUND),
(PenpalASender::get(), INITIAL_FUND),
]);

let weth_asset_id: MultiLocation = (
Parent,
Parent,
Ethereum { chain_id: 15 },
AccountKey20 { network: None, key: WETH }
).into();

// Create asset on penpal.
PenpalA::execute_with(|| {
assert_ok!(<PenpalA as PenpalAPallet>::ForeignAssets::create(
<PenpalA as Chain>::RuntimeOrigin::signed(PenpalASender::get()),
weth_asset_id,
asset_hub_sovereign.into(),
1000,
));

//assert!(<PenpalA as PenpalAPallet>::Assets::asset_exists(weth_asset_id));
});

let message_id_: H256 = [1; 32].into();

BridgeHubRococo::execute_with(|| {
Expand All @@ -253,17 +277,17 @@ fn send_token() {
command: Command::RegisterToken { token: WETH.into() },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, DEST_PARA_ID.into()).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendToken {
token: WETH.into(),
destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() },
destination: Destination::ForeignAccountId32 { para_id: 2000, id: PenpalAReceiver::get().into() },
amount: 1_000_000_000,
},
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, DEST_PARA_ID.into()).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();

assert_expected_events!(
BridgeHubRococo,
Expand All @@ -278,6 +302,18 @@ fn send_token() {

assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {},
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
);
});

PenpalA::execute_with(|| {
type RuntimeEvent = <PenpalA as Chain>::RuntimeEvent;

assert_expected_events!(
PenpalA,
vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {},
]
Expand All @@ -286,18 +322,77 @@ fn send_token() {
}

#[test]
fn reserve_transfer_token() {
fn send_token() {
BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(MultiLocation {
parents: 1,
interior: X1(Parachain(DEST_PARA_ID)),
interior: X1(Parachain(ASSETHUB_PARA_ID)),
}),
INITIAL_FUND,
)]);

// Fund ethereum sovereign in asset hub
AssetHubRococo::fund_accounts(vec![
(ASSETHUB_SOVEREIGN.into(), INITIAL_FUND),
(AssetHubRococoReceiver::get(), INITIAL_FUND),
]);

let message_id_: H256 = [1; 32].into();

BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Chain>::RuntimeEvent;
type EthereumInboundQueue =
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::RegisterToken { token: WETH.into() },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendToken {
token: WETH.into(),
destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() },
amount: 1_000_000_000,
},
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();

assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
);
});

AssetHubRococo::execute_with(|| {
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;

assert_expected_events!(
AssetHubRococo,
vec![
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {},
]
);
});
}

#[test]
fn reserve_transfer_token() {
let assethub_sovereign = BridgeHubRococo::sovereign_account_id_of(
MultiLocation {
parents: 1,
interior: X1(Parachain(ASSETHUB_PARA_ID)),
}
);

BridgeHubRococo::fund_accounts(vec![
(assethub_sovereign.clone(), INITIAL_FUND)
]);

AssetHubRococo::fund_accounts(vec![
(AssetHubRococoReceiver::get(), INITIAL_FUND),
]);

Expand All @@ -313,7 +408,7 @@ fn reserve_transfer_token() {
command: Command::RegisterToken { token: WETH.into() },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, DEST_PARA_ID.into()).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendToken {
Expand All @@ -323,7 +418,7 @@ fn reserve_transfer_token() {
},
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, DEST_PARA_ID.into()).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();

assert_expected_events!(
BridgeHubRococo,
Expand Down Expand Up @@ -402,7 +497,7 @@ fn reserve_transfer_token() {
.find(|&event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount })
if *who == ASSETHUB_SOVEREIGN.into() && *amount == 2200000000000
if who == &assethub_sovereign && *amount == 2200000000000
))
.is_some(),
"Assethub sovereign takes remote fee."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ parameter_types! {
pub const CreateAssetCall: [u8;2] = [53, 0];
pub const CreateAssetExecutionFee: u128 = 2_000_000_000;
pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT;
pub const SendTokenExecutionFee: u128 = 2_000_000_000;
pub const SendTokenExecutionFee: u128 = 4_000_000_000;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
3 changes: 3 additions & 0 deletions cumulus/parachains/runtimes/testing/penpal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ cumulus-primitives-utility = { path = "../../../../primitives/utility", default-
pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false }
parachain-info = { package = "staging-parachain-info", path = "../../../pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../common", default-features = false }
assets-common = { path = "../../assets/common", default-features = false }

[features]
default = [ "std" ]
std = [
"assets-common/std",
"codec/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
Expand Down Expand Up @@ -135,6 +137,7 @@ std = [
]

runtime-benchmarks = [
"assets-common/runtime-benchmarks",
"cumulus-pallet-dmp-queue/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
Expand Down
Loading
Loading