Skip to content

Commit

Permalink
Replaced PendulumCurrencyId alias for CurrencyId
Browse files Browse the repository at this point in the history
  • Loading branch information
adelarja committed Jul 12, 2023
1 parent 7c4f004 commit c30785e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 39 deletions.
8 changes: 4 additions & 4 deletions runtime/integration-tests/pendulum/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{PENDULUM_ID, STATEMINT_ID};
use frame_support::traits::GenesisBuild;
use pendulum_runtime::{PendulumCurrencyId, Runtime, System};
use pendulum_runtime::{CurrencyId, Runtime, System};
use polkadot_core_primitives::{AccountId, Balance};

pub fn units(amount: Balance) -> Balance {
Expand All @@ -12,7 +12,7 @@ pub const BOB: [u8; 32] = [5u8; 32];
pub const INITIAL_BALANCE: u128 = 1_000_000_000;

pub struct ExtBuilderPendulum {
balances: Vec<(AccountId, PendulumCurrencyId, Balance)>,
balances: Vec<(AccountId, CurrencyId, Balance)>,
parachain_id: u32,
}

Expand All @@ -23,7 +23,7 @@ impl Default for ExtBuilderPendulum {
}

impl ExtBuilderPendulum {
pub fn balances(mut self, balances: Vec<(AccountId, PendulumCurrencyId, Balance)>) -> Self {
pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self {
self.balances = balances;
self
}
Expand All @@ -45,7 +45,7 @@ impl ExtBuilderPendulum {
.unwrap();

orml_tokens::GenesisConfig::<Runtime> {
balances: vec![(AccountId::from(BOB), PendulumCurrencyId::XCM(0), units(100))],
balances: vec![(AccountId::from(BOB), CurrencyId::XCM(0), units(100))],
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down
43 changes: 13 additions & 30 deletions runtime/integration-tests/pendulum/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use frame_support::{
assert_ok,
traits::{fungible::Mutate, fungibles::Inspect, Currency},
};
use pendulum_runtime::{Balances, PendulumCurrencyId, RuntimeOrigin, Tokens, XTokens};
use pendulum_runtime::{Balances, CurrencyId, RuntimeOrigin, Tokens, XTokens};
use sp_runtime::{traits::AccountIdConversion, MultiAddress};
use xcm::latest::{Junction, Junction::*, Junctions::*, MultiLocation, NetworkId, WeightLimit};
use xcm_emulator::TestExt;
Expand All @@ -25,10 +25,8 @@ fn transfer_dot_from_relay_chain_to_pendulum() {
let transfer_amount: Balance = units(20);
let mut orml_tokens_before = 0;
PendulumParachain::execute_with(|| {
orml_tokens_before = pendulum_runtime::Tokens::balance(
pendulum_runtime::PendulumCurrencyId::XCM(0),
&ALICE.into(),
);
orml_tokens_before =
pendulum_runtime::Tokens::balance(pendulum_runtime::CurrencyId::XCM(0), &ALICE.into());
});

Relay::execute_with(|| {
Expand Down Expand Up @@ -59,10 +57,7 @@ fn transfer_dot_from_relay_chain_to_pendulum() {

PendulumParachain::execute_with(|| {
assert_eq!(
pendulum_runtime::Tokens::balance(
pendulum_runtime::PendulumCurrencyId::XCM(0),
&ALICE.into()
),
pendulum_runtime::Tokens::balance(pendulum_runtime::CurrencyId::XCM(0), &ALICE.into()),
orml_tokens_before + transfer_amount - DOT_FEE_WHEN_TRANSFER_TO_PARACHAIN
);
});
Expand All @@ -83,7 +78,7 @@ fn transfer_dot_from_pendulum_to_relay_chain() {
PendulumParachain::execute_with(|| {
assert_ok!(pendulum_runtime::XTokens::transfer(
pendulum_runtime::RuntimeOrigin::signed(BOB.into()),
pendulum_runtime::PendulumCurrencyId::XCM(0),
pendulum_runtime::CurrencyId::XCM(0),
transfer_dot_amount,
Box::new(
MultiLocation { parents: 1, interior: X1(AccountId32 { network: None, id: BOB }) }
Expand Down Expand Up @@ -138,7 +133,7 @@ fn transfer_dot_from_pendulum_to_relay_chain() {
});
}

//pendulum_runtime::PendulumCurrencyId::XCM(1) is the representation of USDT from Statemint on Pendulum chain.
//pendulum_runtime::CurrencyId::XCM(1) is the representation of USDT from Statemint on Pendulum chain.
//The asset id for USDT on Statemint is 1984. and pendulum support only this asset id to recive it on chain.
//we are going to execute XCM call to sent incorrect Asset Id and expect to see cumulus_pallet_xcmp_queue::Event::Fail event with an error FailedToTransactAsset.
//we what to be sure that the initial USDT balance for BOB is the same after XCM call from statemint when we tried to send wrong ASSET_ID from system parachain.
Expand All @@ -149,10 +144,7 @@ fn statemint_transfer_incorrect_asset_to_pendulum_should_fails() {
let extected_base_usdt_balance = 0;
PendulumParachain::execute_with(|| {
assert_eq!(
pendulum_runtime::Tokens::balance(
pendulum_runtime::PendulumCurrencyId::XCM(1),
&BOB.into()
),
pendulum_runtime::Tokens::balance(pendulum_runtime::CurrencyId::XCM(1), &BOB.into()),
extected_base_usdt_balance
);
});
Expand Down Expand Up @@ -220,10 +212,7 @@ fn statemint_transfer_incorrect_asset_to_pendulum_should_fails() {

PendulumParachain::execute_with(|| {
assert_eq!(
pendulum_runtime::Tokens::balance(
pendulum_runtime::PendulumCurrencyId::XCM(1),
&BOB.into()
),
pendulum_runtime::Tokens::balance(pendulum_runtime::CurrencyId::XCM(1), &BOB.into()),
extected_base_usdt_balance
);
});
Expand All @@ -235,10 +224,7 @@ fn statemint_transfer_asset_to_pendulum() {

PendulumParachain::execute_with(|| {
assert_eq!(
pendulum_runtime::Tokens::balance(
pendulum_runtime::PendulumCurrencyId::XCM(1),
&BOB.into()
),
pendulum_runtime::Tokens::balance(pendulum_runtime::CurrencyId::XCM(1), &BOB.into()),
0
);
});
Expand Down Expand Up @@ -310,10 +296,7 @@ fn statemint_transfer_asset_to_pendulum() {
)));

assert_eq!(
pendulum_runtime::Tokens::balance(
pendulum_runtime::PendulumCurrencyId::XCM(1),
&BOB.into()
),
pendulum_runtime::Tokens::balance(pendulum_runtime::CurrencyId::XCM(1), &BOB.into()),
TEN_UNITS
);
});
Expand All @@ -327,13 +310,13 @@ fn statemint_transfer_asset_to_statemint() {
Statemint::execute_with(|| {});

PendulumParachain::execute_with(|| {
assert_eq!(TEN_UNITS, Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB)));
assert_eq!(TEN_UNITS, Tokens::balance(CurrencyId::XCM(1), &AccountId::from(BOB)));
// ensure sender has enough PEN balance to be charged as fee
assert_ok!(Balances::mint_into(&AccountId::from(BOB), TEN_UNITS));

assert_ok!(XTokens::transfer(
RuntimeOrigin::signed(BOB.into()),
PendulumCurrencyId::XCM(1),
CurrencyId::XCM(1),
UNIT * 1,
Box::new(
MultiLocation::new(
Expand All @@ -353,7 +336,7 @@ fn statemint_transfer_asset_to_statemint() {

assert_eq!(
TEN_UNITS - 1 * UNIT, //inital balance - one unit
Tokens::balance(PendulumCurrencyId::XCM(1), &AccountId::from(BOB))
Tokens::balance(CurrencyId::XCM(1), &AccountId::from(BOB))
);

assert!(System::events().iter().any(|r| matches!(
Expand Down
4 changes: 2 additions & 2 deletions runtime/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use xcm::v3::MultiLocation;
use zenlink_protocol::{AssetBalance, MultiAssetsHandler, PairInfo};

pub use parachain_staking::InflationInfo;
pub use spacewalk_primitives::CurrencyId as PendulumCurrencyId;

use codec::Encode;

Expand All @@ -28,6 +27,8 @@ use sp_runtime::{
ApplyExtrinsicResult, SaturatedConversion,
};

pub use spacewalk_primitives::CurrencyId;

use sp_std::{marker::PhantomData, prelude::*};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down Expand Up @@ -66,7 +67,6 @@ use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};

use orml_currencies::BasicCurrencyAdapter;
use orml_traits::{currency::MutationHooks, parameter_type_with_key};
use spacewalk_primitives::CurrencyId;

const CONTRACTS_DEBUG_OUTPUT: bool = true;

Expand Down
3 changes: 1 addition & 2 deletions runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{
AccountId, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
AccountId, Balance, Balances, CurrencyId, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
RuntimeCall, RuntimeEvent, RuntimeOrigin, Tokens, WeightToFee, XcmpQueue,
};
use crate::ConstU32;
Expand All @@ -17,7 +17,6 @@ use polkadot_parachain::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use runtime_common::parachains::polkadot::statemint;
use sp_runtime::traits::Convert;
use spacewalk_primitives::CurrencyId;
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_builder::{
AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin,
Expand Down
1 change: 0 additions & 1 deletion runtime/pendulum/src/zenlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use orml_traits::MultiCurrency;
use sp_runtime::{DispatchError, DispatchResult};
use sp_std::marker::PhantomData;

use spacewalk_primitives::CurrencyId;
use zenlink_protocol::{
AssetId, Config as ZenlinkConfig, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets,
};
Expand Down

0 comments on commit c30785e

Please sign in to comment.