Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more test cases #1620

Merged
merged 5 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
122 changes: 107 additions & 15 deletions runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,134 @@ fn transfer_to_relay_chain() {
}

#[test]
fn foreign_asset_transfer_to_relay_chain() {
fn test_asset_registry_module() {
TestNet::reset();

fn sibling_2000_account() -> AccountId {
use sp_runtime::traits::AccountIdConversion;
polkadot_parachain::primitives::Sibling::from(2000).into_account()
}

Karura::execute_with(|| {
assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100_000_000_000_000));
});

Sibling::execute_with(|| {
assert_ok!(Tokens::deposit(BNC, &sibling_2000_account(), 100_000_000_000_000));
});

Karura::execute_with(|| {
assert_ok!(XTokens::transfer(
Origin::signed(ALICE.into()),
BNC,
10_000_000_000_000,
Box::new(
MultiLocation::new(
1,
X2(
Parachain(2001),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
}
)
)
.into()
),
1_000_000_000,
));

assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000);
});

Sibling::execute_with(|| {
assert_eq!(Tokens::free_balance(BNC, &sibling_2000_account()), 90_000_000_000_000);
assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 9_989_760_000_000);
});

Karura::execute_with(|| {
// register KSM as foreign asset
assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000);

// register foreign asset
assert_ok!(AssetRegistry::register_foreign_asset(
Origin::root(),
Box::new(MultiLocation::parent().into()),
Box::new(CurrencyIdConvert::convert(BNC).unwrap().into()),
Box::new(AssetMetadata {
name: b"Kusama".to_vec(),
symbol: b"KSM".to_vec(),
name: b"Sibling Token".to_vec(),
symbol: b"ST".to_vec(),
decimals: 12,
minimal_balance: 1,
})
));

assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000);
assert_eq!(
Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)),
0
);
});

Sibling::execute_with(|| {
assert_ok!(XTokens::transfer(
Origin::signed(BOB.into()),
BNC,
5_000_000_000_000,
Box::new(
MultiLocation::new(
1,
X2(
Parachain(2000),
Junction::AccountId32 {
network: NetworkId::Any,
id: ALICE.into(),
}
)
)
.into()
),
1_000_000_000,
));

assert_eq!(Tokens::free_balance(BNC, &sibling_2000_account()), 95_000_000_000_000);
assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 4_989_760_000_000);
});

Karura::execute_with(|| {
assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000);
assert_eq!(
Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)),
4_989_760_000_000
);

assert_ok!(XTokens::transfer(
Origin::signed(ALICE.into()),
CurrencyId::ForeignAsset(0),
dollar(KSM),
1_000_000_000_000,
Box::new(
MultiLocation::new(
1,
X1(Junction::AccountId32 {
id: BOB,
network: NetworkId::Any,
})
X2(
Parachain(2001),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
}
)
)
.into()
),
4_000_000_000
1_000_000_000,
));
});

KusamaNet::execute_with(|| {
assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90_000_000_000_000);
assert_eq!(
kusama_runtime::Balances::free_balance(&AccountId::from(BOB)),
999_893_333_340
Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(ALICE)),
3_989_760_000_000
);
});

Sibling::execute_with(|| {
assert_eq!(Tokens::free_balance(BNC, &sibling_2000_account()), 94_000_000_000_000);
assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 5_979_520_000_000);
});
}
14 changes: 12 additions & 2 deletions runtime/integration-tests/src/relaychain/kusama_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ decl_test_parachain! {
pub struct Karura {
Runtime = Runtime,
Origin = Origin,
new_ext = karura_ext(),
new_ext = para_ext(2000),
}
}

decl_test_parachain! {
pub struct Sibling {
Runtime = Runtime,
Origin = Origin,
new_ext = para_ext(2001),
}
}

Expand All @@ -49,6 +57,7 @@ decl_test_network! {
relay_chain = KusamaNet,
parachains = vec![
(2000, Karura),
(2001, Sibling),
],
}
}
Expand Down Expand Up @@ -125,8 +134,9 @@ pub fn kusama_ext() -> sp_io::TestExternalities {
ext
}

pub fn karura_ext() -> sp_io::TestExternalities {
pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
ExtBuilder::default()
.balances(vec![(AccountId::from(ALICE), KSM, 10 * dollar(KSM))])
.parachain_id(parachain_id)
.build()
}
13 changes: 11 additions & 2 deletions runtime/integration-tests/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,15 @@ pub fn set_relaychain_block_number(number: BlockNumber) {

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

impl Default for ExtBuilder {
fn default() -> Self {
Self { balances: vec![] }
Self {
balances: vec![],
parachain_id: None,
}
}
}

Expand All @@ -209,6 +213,11 @@ impl ExtBuilder {
self
}

pub fn parachain_id(mut self, parachain_id: u32) -> Self {
self.parachain_id = Some(parachain_id);
self
}

pub fn build(self) -> sp_io::TestExternalities {
let evm_genesis_accounts = evm_genesis();

Expand Down Expand Up @@ -281,7 +290,7 @@ impl ExtBuilder {

<parachain_info::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&parachain_info::GenesisConfig {
parachain_id: 2000.into(),
parachain_id: self.parachain_id.unwrap().into(),
},
&mut t,
)
Expand Down