Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fixed test integration test cases
  • Loading branch information
b-yap committed Jul 6, 2023
commit dbe1ae404acff630ee94e75bb57191b47e3d35f2
2 changes: 2 additions & 0 deletions runtime/integration-tests/pendulum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//extern crate core;

#[cfg(test)]
mod polkadot_test_net;

Expand Down
2 changes: 1 addition & 1 deletion runtime/integration-tests/pendulum/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{PENDULUM_ID, STATEMINT_ID};
use frame_support::traits::GenesisBuild;
use pendulum_runtime::{PendulumCurrencyId, Runtime, System};
use polkadot_core_primitives::{AccountId, Balance};
use crate::{PENDULUM_ID, STATEMINT_ID};

pub fn units(amount: Balance) -> Balance {
amount * 10u128.saturating_pow(9)
Expand Down
65 changes: 31 additions & 34 deletions runtime/integration-tests/pendulum/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ use frame_support::{
use pendulum_runtime::{Balances, PendulumCurrencyId, RuntimeOrigin, Tokens, XTokens};
use sp_runtime::{traits::AccountIdConversion, MultiAddress};
use xcm::latest::{Junction, Junction::*, Junctions::*, MultiLocation, NetworkId, WeightLimit};
use xcm_emulator::{ParaId, TestExt};
use xcm_emulator::TestExt;

use pendulum_runtime::{RuntimeEvent, System};
use polkadot_core_primitives::{AccountId, Balance};
use polkadot_parachain::primitives::Sibling;
use xcm::v3::Weight;

const DOT_FEE_WHEN_TRANSFER_TO_PARACHAIN: Balance = 3200000000; //The fees that relay chain will charge when transfer DOT to parachain. sovereign account of some parachain will receive transfer_amount - DOT_FEE
const ASSET_ID: u32 = 1984; //Real USDT Asset ID from Statemint
const INCORRECT_ASSET_ID: u32 = 0; //Incorrect asset id that pendulum is not supporting pendulum_runtime xcm_config
pub const UNIT: Balance = 1_000_000_000_000;
pub const TEN_UNITS: Balance = 10_000_000_000_000;
const DOT_FEE_WHEN_TRANSFER_TO_RELAY: u128 = 421434140; //This fee will taken to transfer assets(Polkadot) from sovereign parachain account to destination user account;

#[test]
fn transfer_dot_from_relay_chain_to_pendulum() {
Expand Down Expand Up @@ -48,8 +46,6 @@ fn transfer_dot_from_relay_chain_to_pendulum() {
});

PendulumParachain::execute_with(|| {
println!("ALL THE EVENTS: {:?}", System::events());

assert!(System::events().iter().any(|r| matches!(
r.event,
RuntimeEvent::Tokens(orml_tokens::Event::Deposited { .. })
Expand Down Expand Up @@ -90,19 +86,14 @@ fn transfer_dot_from_pendulum_to_relay_chain() {
pendulum_runtime::PendulumCurrencyId::XCM(0),
transfer_dot_amount,
Box::new(
MultiLocation {
parents: 1,
interior: X1(AccountId32 { network: Some(NetworkId::Polkadot), id: BOB })
}
.into()
MultiLocation { parents: 1, interior: X1(AccountId32 { network: None, id: BOB }) }
.into()
),
WeightLimit::Limited(4_000_000_000.into()),
WeightLimit::Unlimited
));
});

PendulumParachain::execute_with(|| {
println!("all pendulum events: {:#?}", System::events());

assert!(System::events().iter().any(|r| matches!(
r.event,
RuntimeEvent::Tokens(orml_tokens::Event::Withdrawn { .. })
Expand All @@ -117,29 +108,32 @@ fn transfer_dot_from_pendulum_to_relay_chain() {
Relay::execute_with(|| {
use polkadot_runtime::{RuntimeEvent, System};

println!("all polkadot events: {:#?}", System::events());

// assert!(System::events().iter().any(|r| matches!(
// r.event,
// RuntimeEvent::Balances(pallet_balances::Event::Withdraw { .. })
// )));
//
// assert!(System::events().iter().any(|r| matches!(
// r.event,
// RuntimeEvent::Balances(pallet_balances::Event::Deposit { .. })
// )));
//
// assert!(System::events().iter().any(|r| matches!(
// r.event,
// RuntimeEvent::Ump(polkadot_runtime_parachains::ump::Event::ExecutedUpward { .. })
// )));
});
let events = System::events();
assert_eq!(events.len(), 3);

let withdrawn_balance = match &events[0].event {
RuntimeEvent::Balances(pallet_balances::Event::Withdraw { who: _, amount }) => amount,
other => panic!("wrong event: {:#?}", other),
};

let deposited_balance = match &events[1].event {
RuntimeEvent::Balances(pallet_balances::Event::Deposit { who: _, amount }) => amount,
other => panic!("wrong event: {:#?}", other),
};

match &events[2].event {
RuntimeEvent::Ump(polkadot_runtime_parachains::ump::Event::ExecutedUpward(..)) =>
assert!(true),
other => panic!("wrong event: {:#?}", other),
};

//This fee will taken to transfer assets(Polkadot) from sovereign parachain account to destination user account;
let dot_fee_when_transferring_to_relay_chain = withdrawn_balance - deposited_balance;

Relay::execute_with(|| {
let after_bob_free_balance = polkadot_runtime::Balances::free_balance(&BOB.into());
assert_eq!(
after_bob_free_balance,
expected_base_balance + transfer_dot_amount - DOT_FEE_WHEN_TRANSFER_TO_RELAY
expected_base_balance + transfer_dot_amount - dot_fee_when_transferring_to_relay_chain
);
});
}
Expand Down Expand Up @@ -346,12 +340,15 @@ fn statemint_transfer_asset_to_statemint() {
1,
X2(
Parachain(STATEMINT_ID),
Junction::AccountId32 { network: None, id: BOB.into() }
Junction::AccountId32 {
network: Some(NetworkId::Polkadot),
id: BOB.into()
}
)
)
.into()
),
WeightLimit::Limited(Weight::from_parts(10_000_000_000, 0)),
WeightLimit::Unlimited
));

assert_eq!(
Expand Down
11 changes: 5 additions & 6 deletions runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ use runtime_common::parachains::polkadot::statemint;
use sp_runtime::traits::Convert;
use xcm::latest::{prelude::*, Weight as XCMWeight};
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin,
FixedWeightBounds, FungiblesAdapter, NoChecking, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,
AccountId32Aliases, AllowUnpaidExecutionFrom,
ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, NoChecking,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, UsingComponents,
};
use xcm_executor::{
traits::{JustTry, ShouldExecute, WithOriginFilter},
traits::{JustTry, ShouldExecute},
XcmExecutor,
};

Expand Down