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

Commit

Permalink
Remove tests unused
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Sep 10, 2024
1 parent ed6fc8a commit 5870827
Showing 1 changed file with 0 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -600,346 +600,3 @@ fn transfer_ah_token() {
);
});
}

#[test]
fn transfer_penpal_native_token() {
let assethub_location = BridgeHubWestend::sibling_location_of(AssetHubWestend::para_id());
let assethub_sovereign = BridgeHubWestend::sovereign_account_id_of(assethub_location);
BridgeHubWestend::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]);

let ethereum_destination = Location::new(2, [GlobalConsensus(Ethereum { chain_id: CHAIN_ID })]);
let ethereum_sovereign: AccountId =
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&ethereum_destination)
.unwrap()
.into();
AssetHubWestend::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]);

let penpal_asset_location = Location::new(1, [Parachain(PenpalB::para_id().into())]);

let penpal_asset_location_after_reanchored =
Location::new(1, [GlobalConsensus(Westend), Parachain(PenpalB::para_id().into())]);

let token_id = TokenIdOf::convert_location(&penpal_asset_location_after_reanchored).unwrap();

// Register token on AH
AssetHubWestend::force_create_foreign_asset(
penpal_asset_location.clone().try_into().unwrap(),
PenpalBSiblingSovereignAccount::get().clone(),
false,
ASSET_MIN_BALANCE,
vec![],
);

// Fund sender on AH
AssetHubWestend::mint_foreign_asset(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(PenpalBSiblingSovereignAccount::get()),
penpal_asset_location.clone().try_into().unwrap(),
AssetHubWestendSender::get(),
TOKEN_AMOUNT,
);

// Fund sov of AH on penpal
let ah_sovereign =
PenpalB::sovereign_account_id_of(PenpalB::sibling_location_of(AssetHubWestend::para_id()));
PenpalB::fund_accounts(vec![(ah_sovereign.clone(), INITIAL_FUND)]);
PenpalB::mint_foreign_asset(
<PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
RelayLocation::get(),
ah_sovereign.clone(),
INITIAL_FUND,
);

// Create token
BridgeHubWestend::execute_with(|| {
type RuntimeOrigin = <BridgeHubWestend as Chain>::RuntimeOrigin;

assert_ok!(<BridgeHubWestend as BridgeHubWestendPallet>::EthereumSystem::register_token(
RuntimeOrigin::root(),
Box::new(VersionedLocation::V4(penpal_asset_location.clone())),
AssetMetadata {
name: "penpal_asset".as_bytes().to_vec().try_into().unwrap(),
symbol: "penpal_asset".as_bytes().to_vec().try_into().unwrap(),
decimals: 12,
},
));
});

// Send token to Ethereum
AssetHubWestend::execute_with(|| {
type RuntimeOrigin = <AssetHubWestend as Chain>::RuntimeOrigin;
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;

let assets = vec![Asset {
id: penpal_asset_location.clone().into(),
fun: Fungible(TOKEN_AMOUNT / 10),
}];

let beneficiary = VersionedLocation::V4(Location::new(
0,
[AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }],
));

assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::limited_reserve_transfer_assets(
RuntimeOrigin::signed(AssetHubWestendSender::get()),
Box::new(VersionedLocation::from(ethereum_destination)),
Box::new(beneficiary),
Box::new(VersionedAssets::from(Assets::from(assets))),
0,
Unlimited,
));

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

let events = AssetHubWestend::events();
// Check that the native asset transferred to some reserved account(sovereign of Ethereum)
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::ForeignAssets(pallet_assets::Event::Transferred { amount, to, ..})
if *amount == TOKEN_AMOUNT/10 && *to == ethereum_sovereign
)),
"native token reserved to Ethereum sovereign account."
);
});

// Send token back from Ethereum
BridgeHubWestend::execute_with(|| {
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;

// Check that the transfer token back to Ethereum message was queue in the Ethereum
// Outbound Queue
assert_expected_events!(
BridgeHubWestend,
vec![RuntimeEvent::EthereumOutboundQueue(snowbridge_pallet_outbound_queue::Event::MessageQueued{..}) => {},]
);

let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendNativeToken {
token_id,
destination: Destination::ForeignAccountId32 {
para_id: PenpalB::para_id().into(),
id: PenpalBReceiver::get().into(),
fee: XCM_FEE,
},
amount: TOKEN_AMOUNT / 10,
fee: XCM_FEE,
},
});

// Convert the message to XCM
let (xcm, _) = EthereumInboundQueue::do_convert([0; 32].into(), message).unwrap();
// Send the XCM
let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubWestend::para_id().into()).unwrap();

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

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

// Check that token burnt from some reserved account
assert_expected_events!(
AssetHubWestend,
vec![RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { .. }) => {},]
);
});

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

// Check that token issued to beneficial
assert_expected_events!(
PenpalB,
vec![RuntimeEvent::Balances(pallet_balances::Event::Minted { .. }) => {},]
);

let events = PenpalB::events();

// Check that token issued to destination account
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Minted { amount, who, ..})
if *amount == TOKEN_AMOUNT/10 && *who == PenpalBReceiver::get()
)),
"Token minted to beneficiary."
);
})
}

#[test]
fn transfer_penpal_asset() {
let assethub_location = BridgeHubWestend::sibling_location_of(AssetHubWestend::para_id());
let assethub_sovereign = BridgeHubWestend::sovereign_account_id_of(assethub_location);
BridgeHubWestend::fund_accounts(vec![(assethub_sovereign.clone(), INITIAL_FUND)]);

let ethereum_destination = Location::new(2, [GlobalConsensus(Ethereum { chain_id: CHAIN_ID })]);
let ethereum_sovereign: AccountId =
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&ethereum_destination)
.unwrap()
.into();

AssetHubWestend::fund_accounts(vec![(ethereum_sovereign.clone(), INITIAL_FUND)]);

let penpal_asset_location = Location::new(1, [Parachain(PenpalB::para_id().into())])
.appended_with(PenpalLocalTeleportableToAssetHub::get())
.unwrap();

let penpal_asset_location_after_reanchored =
Location::new(1, [GlobalConsensus(Westend), Parachain(PenpalB::para_id().into())])
.appended_with(PenpalLocalTeleportableToAssetHub::get())
.unwrap();

let token_id = TokenIdOf::convert_location(&penpal_asset_location_after_reanchored).unwrap();

// Fund sender on AH
AssetHubWestend::mint_foreign_asset(
<AssetHubWestend as Chain>::RuntimeOrigin::signed(PenpalBSiblingSovereignAccount::get()),
penpal_asset_location.clone().try_into().unwrap(),
AssetHubWestendSender::get(),
TOKEN_AMOUNT,
);

// Fund sov of AH on penpal
let ah_sovereign =
PenpalB::sovereign_account_id_of(PenpalB::sibling_location_of(AssetHubWestend::para_id()));
PenpalB::fund_accounts(vec![(ah_sovereign.clone(), INITIAL_FUND)]);
PenpalB::mint_foreign_asset(
<PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
RelayLocation::get(),
ah_sovereign.clone(),
INITIAL_FUND,
);
PenpalB::mint_asset(
<PenpalB as Chain>::RuntimeOrigin::signed(PenpalAssetOwner::get()),
TELEPORTABLE_ASSET_ID,
ah_sovereign.clone(),
TOKEN_AMOUNT,
);

// create token
BridgeHubWestend::execute_with(|| {
type Runtime = <BridgeHubWestend as Chain>::Runtime;

snowbridge_pallet_system::ForeignToNativeId::<Runtime>::insert(
token_id,
penpal_asset_location_after_reanchored.clone(),
);
});

// Send token to Ethereum
AssetHubWestend::execute_with(|| {
type RuntimeOrigin = <AssetHubWestend as Chain>::RuntimeOrigin;
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;

let assets = vec![Asset {
id: penpal_asset_location.clone().into(),
fun: Fungible(TOKEN_AMOUNT / 10),
}];

let beneficiary = VersionedLocation::V4(Location::new(
0,
[AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }],
));

assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::PolkadotXcm::limited_reserve_transfer_assets(
RuntimeOrigin::signed(AssetHubWestendSender::get()),
Box::new(VersionedLocation::from(ethereum_destination)),
Box::new(beneficiary),
Box::new(VersionedAssets::from(Assets::from(assets))),
0,
Unlimited,
));

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

let events = AssetHubWestend::events();
// Check that the native asset transferred to some reserved account(sovereign of Ethereum)
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::ForeignAssets(pallet_assets::Event::Transferred { amount, to, ..})
if *amount == TOKEN_AMOUNT/10 && *to == ethereum_sovereign
)),
"native token reserved to Ethereum sovereign account."
);
});

// Send token back from Ethereum
BridgeHubWestend::execute_with(|| {
type RuntimeEvent = <BridgeHubWestend as Chain>::RuntimeEvent;

// Check that the transfer token back to Ethereum message was queue in the Ethereum
// Outbound Queue
assert_expected_events!(
BridgeHubWestend,
vec![RuntimeEvent::EthereumOutboundQueue(snowbridge_pallet_outbound_queue::Event::MessageQueued{..}) => {},]
);

let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendNativeToken {
token_id,
destination: Destination::ForeignAccountId32 {
para_id: PenpalB::para_id().into(),
id: PenpalBReceiver::get().into(),
fee: XCM_FEE,
},
amount: TOKEN_AMOUNT / 10,
fee: XCM_FEE,
},
});

// Convert the message to XCM
let (xcm, _) = EthereumInboundQueue::do_convert([0; 32].into(), message).unwrap();
// Send the XCM
let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubWestend::para_id().into()).unwrap();

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

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

// Check that token burnt from some reserved account
assert_expected_events!(
AssetHubWestend,
vec![RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { .. }) => {},]
);
});

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

// Check that token issued to beneficial
assert_expected_events!(
PenpalB,
vec![RuntimeEvent::Assets(pallet_assets::Event::Issued { .. }) => {},]
);

let events = PenpalB::events();

// Check that token issued to destination account
assert!(
events.iter().any(|event| matches!(
event,
RuntimeEvent::Assets(pallet_assets::Event::Issued { amount, owner, ..})
if *amount == TOKEN_AMOUNT/10 && *owner == PenpalBReceiver::get()
)),
"Token minted to beneficiary."
);
})
}

0 comments on commit 5870827

Please sign in to comment.