Skip to content

Commit

Permalink
Fix integration tests for sibling XCM transfer for karura-runtime (#2138
Browse files Browse the repository at this point in the history
)

* Removed the integration-tests feature from karura-runtime

* Added a extra metadata storage for foreign assets in Asset Registry module
Modified integration tests to support sibling transfer of native assets.
Removed other integration-tests feature related code

* Renamed the fields in ForeignAssetExtraMetadata to better reflect their functionalities.
Added unit tests and modified integration tests for the new metadata's override functions.

* Fixed build issue from merge

* Removed the ForeignAssetExtraMetadata
Improved XCM integration test setups
Rewrote and improved the sibling chain BNC token transfer

* no message

* Reverted more unneeded changes

* Addressed some PR comments

* Added one more integration test that tests sending BNC to mock bifrost 2001 chain.

* Minor improvement

Co-authored-by: Roy Yang <[email protected]>
Co-authored-by: Acala Benchmarking Bot <[email protected]>
  • Loading branch information
3 people authored Jun 6, 2022
1 parent 7b1b20a commit 3c25a51
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 206 deletions.
1 change: 0 additions & 1 deletion runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ with-mandala-runtime = [
]
with-karura-runtime = [
"karura-runtime",
"karura-runtime/integration-tests",
"acala-service/with-karura-runtime",
"module-relaychain/kusama"
]
Expand Down
2 changes: 1 addition & 1 deletion runtime/integration-tests/src/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn test_trading_pair() {

assert_ok!(AssetRegistry::register_foreign_asset(
Origin::root(),
Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(KAR.encode()))).into()),
Box::new(MultiLocation::new(1, X2(Parachain(2002), GeneralKey(KAR.encode()))).into()),
Box::new(AssetMetadata {
name: b"Sibling Token".to_vec(),
symbol: b"ST".to_vec(),
Expand Down
24 changes: 13 additions & 11 deletions runtime/integration-tests/src/relaychain/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use sp_core::{H256, U256};
use std::str::FromStr;
use xcm_emulator::TestExt;

pub const SIBLING_ID: u32 = 2002;
pub const KARURA_ID: u32 = 2000;

pub fn erc20_address_0() -> EvmAddress {
EvmAddress::from_str("0x5e0b4bfa0b55932a3587e648c3552a6515ba56b1").unwrap()
}
Expand All @@ -39,6 +42,13 @@ pub fn alice_evm_addr() -> EvmAddress {
EvmAddress::from_str("1000000000000000000000000000000000000001").unwrap()
}

fn sibling_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(SIBLING_ID).into_account()
}
fn karura_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(KARURA_ID).into_account()
}

pub fn deploy_erc20_contracts() {
let json: serde_json::Value =
serde_json::from_str(include_str!("../../../../ts-tests/build/Erc20DemoContract2.json")).unwrap();
Expand Down Expand Up @@ -78,10 +88,6 @@ pub fn deploy_erc20_contracts() {
fn erc20_transfer_between_sibling() {
TestNet::reset();

fn sibling_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(2001).into_account()
}

Sibling::execute_with(|| {
let erc20_as_foreign_asset = CurrencyId::Erc20(erc20_address_0());
// register Karura's erc20 as foreign asset
Expand Down Expand Up @@ -142,7 +148,7 @@ fn erc20_transfer_between_sibling() {
MultiLocation::new(
1,
X2(
Parachain(2001),
Parachain(SIBLING_ID),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
Expand Down Expand Up @@ -244,16 +250,12 @@ fn erc20_transfer_between_sibling() {
fn sibling_erc20_to_self_as_foreign_asset() {
TestNet::reset();

fn sibling_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(2000).into_account()
}

Karura::execute_with(|| {
let erc20_as_foreign_asset = CurrencyId::Erc20(erc20_address_0());
// register Karura's erc20 as foreign asset
assert_ok!(AssetRegistry::register_foreign_asset(
Origin::root(),
Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(erc20_as_foreign_asset.encode()))).into()),
Box::new(MultiLocation::new(1, X2(Parachain(2002), GeneralKey(erc20_as_foreign_asset.encode()))).into()),
Box::new(AssetMetadata {
name: b"Sibling USDC".to_vec(),
symbol: b"sUSDC".to_vec(),
Expand Down Expand Up @@ -326,7 +328,7 @@ fn sibling_erc20_to_self_as_foreign_asset() {
);
assert_eq!(
10_000_000_000_000,
Currencies::free_balance(CurrencyId::Erc20(erc20_address_0()), &sibling_reserve_account())
Currencies::free_balance(CurrencyId::Erc20(erc20_address_0()), &karura_reserve_account())
);
});

Expand Down
Loading

0 comments on commit 3c25a51

Please sign in to comment.