Skip to content

Commit

Permalink
Feature/plmc 315 configure pallet assets to accept usdtusdc from ah (#…
Browse files Browse the repository at this point in the history
…161)

* add test xcm config to base + change 420 USDC to 1337

* fix reserve_based transfer tests

* remove reference to penpal from xcm file

* move testnet statemint assets to ForeignAssets

* move all references of statemint to Foreign assets

* change XCM config for test runtime to match base runtime

* change creation origin to root

* add tests for usdt,usdc and dot transfers

* fmt

* comments

* fmt

* single nit in text
  • Loading branch information
vstam1 authored Feb 13, 2024
1 parent abba0d5 commit 4c26ce0
Show file tree
Hide file tree
Showing 33 changed files with 1,162 additions and 990 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion integration-tests/penpal/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl ContainsPair<MultiAsset, MultiLocation> for MultiNativeAsset {
parameter_types! {
pub CommonGoodAssetsLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(1000)));
// ALWAYS ensure that the index in PalletInstance stays up-to-date with
// Statemint's Assets pallet index
// AssetHub's Assets pallet index
pub CommonGoodAssetsPalletLocation: MultiLocation =
MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50)));
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
Expand Down
45 changes: 31 additions & 14 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub mod accounts {
pub mod collators {
use super::*;

pub fn invulnerables_statemint() -> Vec<(AccountId, AssetHubPolkadotAuraId)> {
pub fn invulnerables_asset_hub() -> Vec<(AccountId, AssetHubPolkadotAuraId)> {
vec![
(get_account_id_from_seed::<sr25519::Public>("Alice"), get_from_seed::<AssetHubPolkadotAuraId>("Alice")),
(get_account_id_from_seed::<sr25519::Public>("Bob"), get_from_seed::<AssetHubPolkadotAuraId>("Bob")),
Expand Down Expand Up @@ -222,19 +222,19 @@ pub mod polkadot {
}
}

// Statemint
pub mod statemint {
// AssetHub
pub mod asset_hub {
use super::*;
use crate::Statemint;
use crate::AssetHub;
use xcm::{prelude::Parachain, v3::Parent};

pub const PARA_ID: u32 = 1000;
pub const ED: Balance = asset_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT;

pub fn genesis() -> Storage {
let mut funded_accounts = vec![
(Statemint::sovereign_account_id_of((Parent, Parachain(penpal::PARA_ID)).into()), INITIAL_DEPOSIT),
(Statemint::sovereign_account_id_of((Parent, Parachain(polimec::PARA_ID)).into()), INITIAL_DEPOSIT),
(AssetHub::sovereign_account_id_of((Parent, Parachain(penpal::PARA_ID)).into()), INITIAL_DEPOSIT),
(AssetHub::sovereign_account_id_of((Parent, Parachain(polimec::PARA_ID)).into()), INITIAL_DEPOSIT),
];
funded_accounts.extend(accounts::init_balances().iter().cloned().map(|k| (k, INITIAL_DEPOSIT)));

Expand All @@ -251,12 +251,12 @@ pub mod statemint {
..Default::default()
},
collator_selection: asset_hub_polkadot_runtime::CollatorSelectionConfig {
invulnerables: collators::invulnerables_statemint().iter().cloned().map(|(acc, _)| acc).collect(),
invulnerables: collators::invulnerables_asset_hub().iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: asset_hub_polkadot_runtime::SessionConfig {
keys: collators::invulnerables_statemint()
keys: collators::invulnerables_asset_hub()
.into_iter()
.map(|(acc, aura)| {
(
Expand Down Expand Up @@ -296,11 +296,11 @@ pub mod polimec {
const GENESIS_NUM_SELECTED_CANDIDATES: u32 = 5;

pub fn genesis() -> Storage {
let dot_asset_id = AcceptedFundingAsset::DOT.to_statemint_id();
let usdt_asset_id = AcceptedFundingAsset::USDT.to_statemint_id();
let dot_asset_id = AcceptedFundingAsset::DOT.to_assethub_id();
let usdt_asset_id = AcceptedFundingAsset::USDT.to_assethub_id();
let mut funded_accounts = vec![
(Polimec::sovereign_account_id_of((Parent, Parachain(penpal::PARA_ID)).into()), INITIAL_DEPOSIT),
(Polimec::sovereign_account_id_of((Parent, Parachain(statemint::PARA_ID)).into()), INITIAL_DEPOSIT),
(Polimec::sovereign_account_id_of((Parent, Parachain(asset_hub::PARA_ID)).into()), INITIAL_DEPOSIT),
];
let alice_account = Polimec::account_id_of(accounts::ALICE);
let bob_account: AccountId = Polimec::account_id_of(accounts::BOB);
Expand Down Expand Up @@ -385,7 +385,7 @@ pub mod polimec {
blocks_per_round: GENESIS_BLOCKS_PER_ROUND,
num_selected_candidates: GENESIS_NUM_SELECTED_CANDIDATES,
},
statemint_assets: polimec_parachain_runtime::StatemintAssetsConfig {
foreign_assets: polimec_parachain_runtime::ForeignAssetsConfig {
assets: vec![
(dot_asset_id, alice_account.clone(), true, 0_0_010_000_000u128),
(usdt_asset_id, alice_account.clone(), true, 0_0_010_000_000u128),
Expand Down Expand Up @@ -414,7 +414,7 @@ pub mod penpal {

pub fn genesis() -> Storage {
let mut funded_accounts = vec![
(Penpal::sovereign_account_id_of((Parent, Parachain(statemint::PARA_ID)).into()), INITIAL_DEPOSIT),
(Penpal::sovereign_account_id_of((Parent, Parachain(asset_hub::PARA_ID)).into()), INITIAL_DEPOSIT),
(Penpal::sovereign_account_id_of((Parent, Parachain(polimec::PARA_ID)).into()), 2_000_000_0_000_000_000), // i.e the CTs sold on polimec
];
funded_accounts.extend(accounts::init_balances().iter().cloned().map(|k| (k, INITIAL_DEPOSIT)));
Expand Down Expand Up @@ -465,6 +465,7 @@ pub mod penpal {
pub mod polimec_base {
use super::*;
use crate::PolimecBase;
use pallet_funding::AcceptedFundingAsset;
use xcm::{prelude::Parachain, v3::Parent};

pub const PARA_ID: u32 = 3344;
Expand All @@ -476,9 +477,12 @@ pub mod polimec_base {
const GENESIS_NUM_SELECTED_CANDIDATES: u32 = 5;

pub fn genesis() -> Storage {
let dot_asset_id = AcceptedFundingAsset::DOT.to_assethub_id();
let usdt_asset_id = AcceptedFundingAsset::USDT.to_assethub_id();
let usdc_asset_id = AcceptedFundingAsset::USDC.to_assethub_id();
let mut funded_accounts = vec![
(PolimecBase::sovereign_account_id_of((Parent, Parachain(penpal::PARA_ID)).into()), INITIAL_DEPOSIT),
(PolimecBase::sovereign_account_id_of((Parent, Parachain(statemint::PARA_ID)).into()), INITIAL_DEPOSIT),
(PolimecBase::sovereign_account_id_of((Parent, Parachain(asset_hub::PARA_ID)).into()), INITIAL_DEPOSIT),
];
let alice_account = PolimecBase::account_id_of(accounts::ALICE);
let bob_account: AccountId = PolimecBase::account_id_of(accounts::BOB);
Expand All @@ -496,6 +500,19 @@ pub mod polimec_base {
..Default::default()
},
balances: polimec_base_runtime::BalancesConfig { balances: funded_accounts },
foreign_assets: polimec_base_runtime::ForeignAssetsConfig {
assets: vec![
(dot_asset_id, alice_account.clone(), true, 0_0_010_000_000u128),
(usdt_asset_id, alice_account.clone(), true, 0_0_010_000_000u128),
(usdc_asset_id, alice_account.clone(), true, 0_0_010_000_000u128),
],
metadata: vec![
(dot_asset_id, "Local DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 12),
(usdt_asset_id, "Local USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6),
(usdc_asset_id, "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
],
accounts: vec![],
},
parachain_info: polimec_base_runtime::ParachainInfoConfig {
parachain_id: PARA_ID.into(),
..Default::default()
Expand Down
36 changes: 19 additions & 17 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod constants;

mod tests;

pub use constants::{accounts::*, penpal, polimec, polimec_base, polkadot, statemint};
pub use constants::{accounts::*, asset_hub, penpal, polimec, polimec_base, polkadot};
pub use frame_support::{assert_noop, assert_ok, pallet_prelude::Weight, parameter_types, sp_io, sp_tracing};
pub use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber};
pub use sp_core::{sr25519, storage::Storage, Encode, Get};
Expand Down Expand Up @@ -93,12 +93,12 @@ decl_test_parachains! {
pallets_extra = {
PolkadotXcm: polimec_parachain_runtime::PolkadotXcm,
LocalAssets: polimec_parachain_runtime::LocalAssets,
StatemintAssets: polimec_parachain_runtime::StatemintAssets,
ForeignAssets: polimec_parachain_runtime::ForeignAssets,
FundingPallet: polimec_parachain_runtime::PolimecFunding,
}
},
pub struct Statemint {
genesis = statemint::genesis(),
pub struct AssetHub {
genesis = asset_hub::genesis(),
on_init = (),
runtime = {
Runtime: asset_hub_polkadot_runtime::Runtime,
Expand Down Expand Up @@ -136,6 +136,7 @@ decl_test_parachains! {
},
pallets_extra = {
PolkadotXcm: polimec_base_runtime::PolkadotXcm,
ForeignAssets: polimec_base_runtime::ForeignAssets,
}
}
}
Expand All @@ -146,7 +147,7 @@ decl_test_networks! {
parachains = vec![
Polimec,
Penpal,
Statemint,
AssetHub,
PolimecBase,
],
bridge = ()
Expand All @@ -156,8 +157,8 @@ decl_test_networks! {
/// Shortcuts to reduce boilerplate on runtime types
pub mod shortcuts {
use super::{
Parachain, Penpal, Polimec, PolimecBase, PolimecBasePallet, PolimecPallet, PolkadotRelay as Polkadot,
PolkadotRelayPallet as PolkadotPallet, RelayChain, Statemint, StatemintPallet,
AssetHub, AssetHubPallet, Parachain, Penpal, Polimec, PolimecBase, PolimecBasePallet, PolimecPallet,
PolkadotRelay as Polkadot, PolkadotRelayPallet as PolkadotPallet, RelayChain,
};
use crate::PenpalPallet;

Expand All @@ -166,54 +167,55 @@ pub mod shortcuts {
pub type PolkadotRuntime = <Polkadot as RelayChain>::Runtime;
pub type PolimecRuntime = <Polimec as Parachain>::Runtime;
pub type PenpalRuntime = <Penpal as Parachain>::Runtime;
pub type StatemintRuntime = <Statemint as Parachain>::Runtime;
pub type AssetHubRuntime = <AssetHub as Parachain>::Runtime;
pub type BaseRuntime = <PolimecBase as Parachain>::Runtime;

pub type PolkadotXcmPallet = <Polkadot as PolkadotPallet>::XcmPallet;
pub type PolimecXcmPallet = <Polimec as PolimecPallet>::PolkadotXcm;
pub type PenpalXcmPallet = <Penpal as PenpalPallet>::PolkadotXcm;
pub type StatemintXcmPallet = <Statemint as StatemintPallet>::PolkadotXcm;
pub type AssetHubXcmPallet = <AssetHub as AssetHubPallet>::PolkadotXcm;
pub type BaseXcmPallet = <PolimecBase as PolimecBasePallet>::PolkadotXcm;

pub type PolkadotBalances = <Polkadot as RelayChain>::Balances;
pub type PolimecBalances = <Polimec as Parachain>::Balances;
pub type PenpalBalances = <Penpal as Parachain>::Balances;
pub type StatemintBalances = <Statemint as Parachain>::Balances;
pub type AssetHubBalances = <AssetHub as Parachain>::Balances;
pub type BaseBalances = <PolimecBase as Parachain>::Balances;

pub type PolimecLocalAssets = <Polimec as PolimecPallet>::LocalAssets;
pub type PolimecStatemintAssets = <Polimec as PolimecPallet>::StatemintAssets;
pub type PolimecForeignAssets = <Polimec as PolimecPallet>::ForeignAssets;
pub type PenpalAssets = <Penpal as PenpalPallet>::Assets;
pub type StatemintAssets = <Statemint as StatemintPallet>::LocalAssets;
pub type AssetHubAssets = <AssetHub as AssetHubPallet>::LocalAssets;
pub type BaseForeignAssets = <PolimecBase as PolimecBasePallet>::ForeignAssets;

pub type PolkadotOrigin = <Polkadot as RelayChain>::RuntimeOrigin;
pub type PolimecOrigin = <Polimec as Parachain>::RuntimeOrigin;
pub type PenpalOrigin = <Penpal as Parachain>::RuntimeOrigin;
pub type StatemintOrigin = <Statemint as Parachain>::RuntimeOrigin;
pub type AssetHubOrigin = <AssetHub as Parachain>::RuntimeOrigin;
pub type BaseOrigin = <PolimecBase as Parachain>::RuntimeOrigin;

pub type PolkadotCall = <Polkadot as RelayChain>::RuntimeCall;
pub type PolimecCall = <Polimec as Parachain>::RuntimeCall;
pub type PenpalCall = <Penpal as Parachain>::RuntimeCall;
pub type StatemintCall = <Statemint as Parachain>::RuntimeCall;
pub type AssetHubCall = <AssetHub as Parachain>::RuntimeCall;
pub type BaseCall = <PolimecBase as Parachain>::RuntimeCall;

pub type PolkadotAccountId = <PolkadotRuntime as frame_system::Config>::AccountId;
pub type PolimecAccountId = <PolimecRuntime as frame_system::Config>::AccountId;
pub type PenpalAccountId = <PenpalRuntime as frame_system::Config>::AccountId;
pub type StatemintAccountId = <StatemintRuntime as frame_system::Config>::AccountId;
pub type AssetHubAccountId = <AssetHubRuntime as frame_system::Config>::AccountId;
pub type BaseAccountId = <PolimecBase as frame_system::Config>::AccountId;

pub type PolkadotEvent = <Polkadot as RelayChain>::RuntimeEvent;
pub type PolimecEvent = <Polimec as Parachain>::RuntimeEvent;
pub type PenpalEvent = <Penpal as Parachain>::RuntimeEvent;
pub type StatemintEvent = <Statemint as Parachain>::RuntimeEvent;
pub type AssetHubEvent = <AssetHub as Parachain>::RuntimeEvent;
pub type BaseEvent = <PolimecBase as Parachain>::RuntimeEvent;

pub type PolkadotSystem = <Polkadot as RelayChain>::System;
pub type PolimecSystem = <Polimec as Parachain>::System;
pub type PenpalSystem = <Penpal as Parachain>::System;
pub type StatemintSystem = <Statemint as Parachain>::System;
pub type AssetHubSystem = <AssetHub as Parachain>::System;
pub type BaseSystem = <PolimecBase as Parachain>::System;
}
pub use shortcuts::*;
4 changes: 4 additions & 0 deletions integration-tests/src/tests/basic_comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use crate::*;
const MAX_REF_TIME: u64 = 300_000_000;
const MAX_PROOF_SIZE: u64 = 10_000;

// Ignored for now as we are not allowing "Transact" execution on our parachain
#[ignore]
#[test]
fn dmp() {
let remark = PolimecCall::System(frame_system::Call::<PolimecRuntime>::remark_with_event {
Expand Down Expand Up @@ -102,6 +104,8 @@ fn ump() {
});
}

// Ignored for now as we are not allowing "Transact" execution on our parachain
#[ignore]
#[test]
fn xcmp() {
let burn_transfer = PolimecCall::Balances(pallet_balances::Call::<PolimecRuntime>::transfer {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ fn funds_raised() {
inst.execute(|| {
let project_specific_account: AccountId = PolimecFunding::fund_account_id(project_id);
let funding =
PolimecStatemintAssets::balance(AcceptedFundingAsset::USDT.to_statemint_id(), project_specific_account);
PolimecForeignAssets::balance(AcceptedFundingAsset::USDT.to_assethub_id(), project_specific_account);
let fund_raised_from_excel = 1005361.955;
let fund_raised_to_substrate = FixedU128::from_float(fund_raised_from_excel);
let fund_raised_as_fixed = FixedU128::from_rational(funding, ASSET_UNIT);
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn values(
let [dot, usdc, usdt, plmc] = values;
bounded_vec![
(0u32, FixedU128::from_float(dot)),
(420u32, FixedU128::from_float(usdc)),
(1337u32, FixedU128::from_float(usdc)),
(1984u32, FixedU128::from_float(usdt)),
(2069u32, FixedU128::from_float(plmc))
]
Expand All @@ -53,7 +53,7 @@ fn members_can_feed_data() {

let expected_values = HashMap::from([
(0u32, FixedU128::from_float(4.84)),
(420u32, FixedU128::from_float(1.0)),
(1337u32, FixedU128::from_float(1.0)),
(1984u32, FixedU128::from_float(1.0)),
(2069u32, FixedU128::from_float(0.4)),
]);
Expand Down Expand Up @@ -95,7 +95,7 @@ fn data_is_correctly_combined() {
// Default CombineData implementation is the median value
let expected_values = HashMap::from([
(0u32, FixedU128::from_float(2.0)),
(420u32, FixedU128::from_float(1.0)),
(1337u32, FixedU128::from_float(1.0)),
(1984u32, FixedU128::from_float(1.1)),
(2069u32, FixedU128::from_float(0.22222)),
]);
Expand Down
Loading

0 comments on commit 4c26ce0

Please sign in to comment.