Skip to content

Commit

Permalink
Removed another FAIL-CI @bkontur
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed May 24, 2024
1 parent 6dd7b19 commit bd0ad1b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use sp_core::storage::Storage;

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, SAFE_XCM_VERSION,
accounts, build_genesis_storage, collators, PenpalSiblingSovereignAccount,
PenpalTeleportableAssetLocation, SAFE_XCM_VERSION,
};
use parachains_common::Balance;

Expand Down Expand Up @@ -60,6 +61,18 @@ pub fn genesis() -> Storage {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
foreign_assets: asset_hub_kusama_runtime::ForeignAssetsConfig {
assets: vec![
// Penpal's teleportable asset representation
(
PenpalTeleportableAssetLocation::get(),
PenpalSiblingSovereignAccount::get(),
true,
ED,
),
],
..Default::default()
},
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use sp_core::storage::Storage;

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, get_account_id_from_seed, get_from_seed, SAFE_XCM_VERSION,
accounts, build_genesis_storage, get_account_id_from_seed, get_from_seed,
PenpalSiblingSovereignAccount, PenpalTeleportableAssetLocation, SAFE_XCM_VERSION,
};
use parachains_common::{AccountId, AssetHubPolkadotAuraId, Balance};
use sp_core::sr25519;
Expand Down Expand Up @@ -74,6 +75,18 @@ pub fn genesis() -> Storage {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
foreign_assets: asset_hub_polkadot_runtime::ForeignAssetsConfig {
assets: vec![
// Penpal's teleportable asset representation
(
PenpalTeleportableAssetLocation::get(),
PenpalSiblingSovereignAccount::get(),
true,
ED,
),
],
..Default::default()
},
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,42 +123,26 @@ fn swap_locally_on_chain_using_foreign_assets() {
v3::Location::try_from(asset_hub_kusama_runtime::xcm_config::KsmLocation::get())
.expect("conversion works"),
);

let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubKusama::para_id());
let asset_location_on_penpal =
v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works");
let asset_id_on_penpal = match asset_location_on_penpal.last() {
Some(v3::Junction::GeneralIndex(id)) => *id as u32,
_ => unreachable!(),
};
let asset_owner_on_penpal = PenpalASender::get();
let foreign_asset_at_asset_hub_kusama =
v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())])
.appended_with(asset_location_on_penpal)
.unwrap();

// 1. Create asset on penpal and, 2. Create foreign asset on asset_hub_kusama
/*
// FAIL-CI @bkontur
super::penpal_create_foreign_asset_on_asset_hub(
asset_id_on_penpal,
foreign_asset_at_asset_hub_kusama,
ah_as_seen_by_penpal,
true,
asset_owner_on_penpal,
ASSET_MIN_BALANCE * 1_000_000,
);*/

let penpal_as_seen_by_ah = AssetHubKusama::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahk = AssetHubKusama::sovereign_account_id_of(penpal_as_seen_by_ah);
AssetHubKusama::fund_accounts(vec![
(AssetHubKusamaSender::get(), 5_000_000 * ASSET_HUB_KUSAMA_ED), /* An account to swap
* ksm
* for something else. */
// An account to swap ksmfor something else.
(AssetHubKusamaSender::get(), 5_000_000 * ASSET_HUB_KUSAMA_ED),
// Penpal's sovereign account in AH should have some balance
(sov_penpal_on_ahk.clone().into(), 100_000_000 * ASSET_HUB_KUSAMA_ED),
]);

AssetHubKusama::execute_with(|| {
// 3: Mint foreign asset on asset_hub_kusama:
// 0: No need to create foreign asset as it exists in genesis.
//
// 1:: Mint foreign asset on asset_hub_kusama:
//
// (While it might be nice to use batch,
// currently that's disabled due to safe call filters.)
Expand All @@ -169,7 +153,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
<AssetHubKusama as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()),
foreign_asset_at_asset_hub_kusama,
sov_penpal_on_ahk.clone().into(),
3_000_000_000_000,
ASSET_HUB_KUSAMA_ED * 3_000_000_000_000,
));

assert_expected_events!(
Expand Down Expand Up @@ -221,8 +205,8 @@ fn swap_locally_on_chain_using_foreign_assets() {
<AssetHubKusama as AssetHubKusamaPallet>::AssetConversion::swap_exact_tokens_for_tokens(
<AssetHubKusama as Chain>::RuntimeOrigin::signed(AssetHubKusamaSender::get()),
path,
100000,
1000,
100000 * ASSET_HUB_KUSAMA_ED,
1000 * ASSET_HUB_KUSAMA_ED,
AssetHubKusamaSender::get(),
true
)
Expand All @@ -232,8 +216,8 @@ fn swap_locally_on_chain_using_foreign_assets() {
AssetHubKusama,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapExecuted { amount_in, amount_out, .. },) => {
amount_in: *amount_in == 100000,
amount_out: *amount_out == 199399,
amount_in: *amount_in == 333333300000,
amount_out: *amount_out == 498874118173,
},
]
);
Expand All @@ -243,7 +227,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
<AssetHubKusama as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()),
asset_native.clone(),
Box::new(foreign_asset_at_asset_hub_kusama),
1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved.
1414213562273 / 2, // remove only half
0,
0,
sov_penpal_on_ahk.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,53 +132,37 @@ fn swap_locally_on_chain_using_foreign_assets() {
v3::Location::try_from(asset_hub_polkadot_runtime::xcm_config::DotLocation::get())
.expect("conversion works"),
);

let ah_as_seen_by_penpal = PenpalB::sibling_location_of(AssetHubPolkadot::para_id());
let asset_location_on_penpal =
v3::Location::try_from(PenpalLocalTeleportableToAssetHub::get()).expect("conversion works");
let asset_id_on_penpal = match asset_location_on_penpal.last() {
Some(v3::Junction::GeneralIndex(id)) => *id as u32,
_ => unreachable!(),
};
let asset_owner_on_penpal = PenpalBSender::get();
let foreign_asset_at_asset_hub_polkadot =
v3::Location::new(1, [v3::Junction::Parachain(PenpalB::para_id().into())])
v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())])
.appended_with(asset_location_on_penpal)
.unwrap();

// 1. Create asset on penpal and, 2. Create foreign asset on asset_hub_polkadot
/*
// FAIL-CI @bkontur
super::penpal_create_foreign_asset_on_asset_hub(
asset_id_on_penpal,
foreign_asset_at_asset_hub_polkadot,
ah_as_seen_by_penpal,
true,
asset_owner_on_penpal,
ASSET_MIN_BALANCE * 1_000_000,
);*/

let penpal_as_seen_by_ah = AssetHubPolkadot::sibling_location_of(PenpalB::para_id());
let sov_penpal_on_ahk = AssetHubPolkadot::sovereign_account_id_of(penpal_as_seen_by_ah);
let penpal_as_seen_by_ah = AssetHubPolkadot::sibling_location_of(PenpalA::para_id());
let sov_penpal_on_ahp = AssetHubPolkadot::sovereign_account_id_of(penpal_as_seen_by_ah);
AssetHubPolkadot::fund_accounts(vec![
(AssetHubPolkadotSender::get(), 5_000_000 * POLKADOT_ED), /* An account to swap
* dot
* for something else. */
// An account to swap dot for something else.
(AssetHubPolkadotSender::get(), 5_000_000 * ASSET_HUB_POLKADOT_ED),
// Penpal's sovereign account in AH should have some balance
(sov_penpal_on_ahp.clone().into(), 100_000_000 * ASSET_HUB_POLKADOT_ED),
]);

AssetHubPolkadot::execute_with(|| {
// 3: Mint foreign asset on asset_hub_polkadot:
// 0: No need to create foreign asset as it exists in genesis.
//
// 1:: Mint foreign asset on asset_hub_polkadot:
//
// (While it might be nice to use batch,
// currently that's disabled due to safe call filters.)

type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;
// 3. Mint foreign asset (in reality this should be a teleport or some such)
assert_ok!(<AssetHubPolkadot as AssetHubPolkadotPallet>::ForeignAssets::mint(
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()),
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahp.clone()),
foreign_asset_at_asset_hub_polkadot,
sov_penpal_on_ahk.clone().into(),
3_000_000_000_000,
sov_penpal_on_ahp.clone().into(),
ASSET_HUB_POLKADOT_ED * 3_000_000_000_000,
));

assert_expected_events!(
Expand All @@ -204,14 +188,14 @@ fn swap_locally_on_chain_using_foreign_assets() {

// 5. Add liquidity:
assert_ok!(<AssetHubPolkadot as AssetHubPolkadotPallet>::AssetConversion::add_liquidity(
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()),
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahp.clone()),
asset_native.clone(),
Box::new(foreign_asset_at_asset_hub_polkadot),
1_000_000_000_000,
2_000_000_000_000,
0,
0,
sov_penpal_on_ahk.clone()
sov_penpal_on_ahp.clone()
));

assert_expected_events!(
Expand All @@ -230,8 +214,8 @@ fn swap_locally_on_chain_using_foreign_assets() {
<AssetHubPolkadot as AssetHubPolkadotPallet>::AssetConversion::swap_exact_tokens_for_tokens(
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(AssetHubPolkadotSender::get()),
path,
100000,
1000,
100000 * ASSET_HUB_POLKADOT_ED,
1000 * ASSET_HUB_POLKADOT_ED,
AssetHubPolkadotSender::get(),
true
)
Expand All @@ -241,22 +225,22 @@ fn swap_locally_on_chain_using_foreign_assets() {
AssetHubPolkadot,
vec![
RuntimeEvent::AssetConversion(pallet_asset_conversion::Event::SwapExecuted { amount_in, amount_out, .. },) => {
amount_in: *amount_in == 100000,
amount_out: *amount_out == 199399,
amount_in: *amount_in == 10000000000000,
amount_out: *amount_out == 1817684594348,
},
]
);

// 7. Remove liquidity
assert_ok!(
<AssetHubPolkadot as AssetHubPolkadotPallet>::AssetConversion::remove_liquidity(
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahk.clone()),
<AssetHubPolkadot as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahp.clone()),
asset_native.clone(),
Box::new(foreign_asset_at_asset_hub_polkadot),
1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved.
1414213562273 / 2, // remove only half
0,
0,
sov_penpal_on_ahk.clone(),
sov_penpal_on_ahp.clone(),
)
);
});
Expand Down

0 comments on commit bd0ad1b

Please sign in to comment.