-
Notifications
You must be signed in to change notification settings - Fork 406
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
Statemine integration test #1712
Merged
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f69e348
poc
xlc e3014cc
wip
xlc 5852155
Merge remote-tracking branch 'origin/master' into statemine
06c053a
WIP: Transfer assets from westmint /statemine to karura
05f8c51
update
xlc 3c4ee72
merge master
zqhxuyuan d490d9b
fix statemine test
zqhxuyuan b2b003d
transfer back to statemine failed
zqhxuyuan 8b3700a
transfer back RMRK to statmine ok
zqhxuyuan 034251c
revert BaseXcmWeight
zqhxuyuan 62cfee8
rename method
zqhxuyuan cd29c19
update orml
zqhxuyuan 5c92deb
deduplicate dmp
zqhxuyuan 5627b8a
update orml
zqhxuyuan b4d0ea1
Merge remote-tracking branch 'origin/master' into statemine
zqhxuyuan 35e1e9e
merge master
zqhxuyuan c0f5cdb
integration tests
zqhxuyuan 0743ded
simplify new default config
zqhxuyuan ddd64e5
update tests
zqhxuyuan 21efbd1
update orml
zqhxuyuan aa16463
Merge remote-tracking branch 'origin/master' into statemine
zqhxuyuan e67598c
merge master v0.9.17
zqhxuyuan daff9e0
update orml
zqhxuyuan 0d0cd9d
merge master
zqhxuyuan f6fa9b3
reset sub-module
zqhxuyuan 1c2df45
update test
zqhxuyuan cbb8dbc
update test
zqhxuyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule evm-tests
updated
5 files
+1 −1 | jsontests/res/ethtests | |
+20 −25 | jsontests/src/mock.rs | |
+155 −88 | jsontests/src/state.rs | |
+1 −2 | jsontests/src/vm.rs | |
+10 −0 | jsontests/tests/state.rs |
Submodule orml
updated
34 files
+65 −65 | Cargo.dev.toml | |
+7 −7 | auction/Cargo.toml | |
+9 −9 | authority/Cargo.toml | |
+14 −14 | bencher/Cargo.toml | |
+1 −1 | bencher/src/bench_runner.rs | |
+7 −7 | bencher/test/Cargo.toml | |
+10 −10 | benchmarking/Cargo.toml | |
+1 −1 | benchmarking/src/lib.rs | |
+8 −8 | currencies/Cargo.toml | |
+7 −7 | gradually-update/Cargo.toml | |
+7 −7 | nft/Cargo.toml | |
+8 −8 | oracle/Cargo.toml | |
+3 −3 | oracle/rpc/Cargo.toml | |
+2 −2 | oracle/rpc/runtime-api/Cargo.toml | |
+8 −8 | rewards/Cargo.toml | |
+9 −9 | tokens/Cargo.toml | |
+6 −6 | tokens/rpc/Cargo.toml | |
+3 −3 | tokens/rpc/runtime-api/Cargo.toml | |
+7 −7 | traits/Cargo.toml | |
+8 −8 | unknown-tokens/Cargo.toml | |
+6 −6 | utilities/Cargo.toml | |
+8 −8 | vesting/Cargo.toml | |
+3 −1 | vesting/src/mock.rs | |
+42 −0 | vesting/src/tests.rs | |
+1 −1 | weight-gen/Cargo.toml | |
+8 −8 | weight-meter/Cargo.toml | |
+5 −5 | xcm-support/Cargo.toml | |
+6 −6 | xcm/Cargo.toml | |
+23 −23 | xtokens/Cargo.toml | |
+46 −0 | xtokens/README.md | |
+197 −194 | xtokens/src/lib.rs | |
+6 −0 | xtokens/src/mock/mod.rs | |
+16 −3 | xtokens/src/mock/para.rs | |
+296 −9 | xtokens/src/tests.rs |
Submodule predeploy-contracts
updated
9 files
+2 −2 | README.md | |
+1 −1 | contracts/state_rent/IStateRent.sol | |
+5 −5 | contracts/state_rent/StateRent.sol | |
+16 −0 | contracts/test/Erc20DemoContract.sol | |
+1 −1 | contracts/utils/Address.d.ts | |
+2 −2 | contracts/utils/Address.js | |
+1 −1 | contracts/utils/Address.sol | |
+3 −3 | generate/generate.js | |
+6 −6 | resources/bytecodes.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ | |
mod kusama_cross_chain_transfer; | ||
pub mod kusama_test_net; | ||
mod relay_chain; | ||
mod statemine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
// This file is part of Acala. | ||
|
||
// Copyright (C) 2020-2021 Acala Foundation. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! Tests parachain to parachain xcm communication between Statemine and Karura. | ||
use crate::relaychain::kusama_test_net::*; | ||
use crate::setup::*; | ||
use cumulus_primitives_core::ParaId; | ||
|
||
use frame_support::assert_ok; | ||
use module_asset_registry::AssetMetadata; | ||
use polkadot_parachain::primitives::Sibling; | ||
use xcm::v1::{Junction, MultiLocation}; | ||
use xcm_emulator::TestExt; | ||
|
||
pub const UNIT: Balance = 1_000_000_000_000; | ||
pub const TEN: Balance = 10_000_000_000_000; | ||
pub const FEE_STATEMINE: Balance = 4_000_000_000; | ||
pub const FEE_KUSAMA: Balance = 106_666_660; | ||
|
||
#[cfg(feature = "with-karura-runtime")] | ||
#[test] | ||
fn user_different_ksm_fee() { | ||
let para_2000: AccountId = Sibling::from(2000).into_account(); | ||
let child_2000: AccountId = ParaId::from(2000).into_account(); | ||
let child_1000: AccountId = ParaId::from(1000).into_account(); | ||
let user_fees = vec![ | ||
FEE_STATEMINE + FEE_KUSAMA - 1, | ||
FEE_STATEMINE + FEE_KUSAMA, | ||
FEE_STATEMINE + FEE_KUSAMA + 1, | ||
2 * FEE_STATEMINE - 1, | ||
2 * FEE_STATEMINE, | ||
2 * FEE_STATEMINE + 1, | ||
2 * FEE_STATEMINE + FEE_KUSAMA, | ||
]; | ||
let min_user_fee = 2 * FEE_STATEMINE; | ||
for user_fee in user_fees { | ||
TestNet::reset(); | ||
|
||
statemine_side(); | ||
|
||
KusamaNet::execute_with(|| { | ||
let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, UNIT); | ||
}); | ||
|
||
// user fee amount split into two parts | ||
// first part is `FEE_STATEMINE` sent to statemine | ||
// second part left sent to kusama | ||
karura_side(user_fee + FEE_STATEMINE); | ||
|
||
KusamaNet::execute_with(|| { | ||
assert_eq!(UNIT - user_fee, kusama_runtime::Balances::free_balance(&child_2000)); | ||
assert_eq!( | ||
user_fee - FEE_KUSAMA, | ||
kusama_runtime::Balances::free_balance(&child_1000) | ||
); | ||
}); | ||
|
||
Statemine::execute_with(|| { | ||
use statemine_runtime::*; | ||
// Karura send back custom asset to Statemine, ensure recipient got custom asset | ||
assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); | ||
// the recipient's ksm not changed | ||
assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); | ||
// and withdraw sibling parachain sovereign account | ||
assert_eq!(TEN - UNIT, Assets::balance(0, ¶_2000)); | ||
|
||
if user_fee < min_user_fee { | ||
assert_eq!(UNIT - FEE_STATEMINE, Balances::free_balance(¶_2000)); | ||
} else { | ||
assert_eq!( | ||
UNIT - FEE_STATEMINE + user_fee - (FEE_STATEMINE + FEE_KUSAMA), | ||
Balances::free_balance(¶_2000) | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
#[cfg(feature = "with-karura-runtime")] | ||
#[test] | ||
fn user_large_fee_fund_to_sovereign_account_works() { | ||
let para_2000: AccountId = Sibling::from(2000).into_account(); | ||
let child_2000: AccountId = ParaId::from(2000).into_account(); | ||
let child_1000: AccountId = ParaId::from(1000).into_account(); | ||
|
||
let assets: Vec<(u128, u128, u128, u128)> = vec![ | ||
(9 * UNIT + FEE_STATEMINE, UNIT, 8_999_893_333_340, 9_991_893_333_340), | ||
(UNIT, 9_004_000_000_000, 995_893_333_340, 1_987_893_333_340), | ||
]; | ||
|
||
for (asset, c_2000, c_1000, p_2000) in assets { | ||
TestNet::reset(); | ||
|
||
statemine_side(); | ||
|
||
KusamaNet::execute_with(|| { | ||
let _ = kusama_runtime::Balances::make_free_balance_be(&child_2000, TEN); | ||
}); | ||
|
||
karura_side(asset); | ||
|
||
KusamaNet::execute_with(|| { | ||
// first xcm send to relaychain with 9 KSM. 10 KSM - 9 KSM = 1 KSM | ||
assert_eq!(c_2000, kusama_runtime::Balances::free_balance(&child_2000)); | ||
// 9 KSM - fee on relaychain = 9 KSM - 106_666_660 | ||
assert_eq!(c_1000, kusama_runtime::Balances::free_balance(&child_1000)); | ||
}); | ||
|
||
Statemine::execute_with(|| { | ||
use statemine_runtime::*; | ||
// Karura send back custom asset to Statemine, ensure recipient got custom asset | ||
assert_eq!(UNIT, Assets::balance(0, &AccountId::from(BOB))); | ||
// the recipient's ksm not changed | ||
assert_eq!(UNIT, Balances::free_balance(&AccountId::from(BOB))); | ||
// and withdraw sibling parachain sovereign account | ||
assert_eq!(9 * UNIT, Assets::balance(0, ¶_2000)); | ||
|
||
assert_eq!(p_2000, Balances::free_balance(¶_2000)); | ||
}); | ||
} | ||
} | ||
|
||
// transfer custom asset from Karura to Statemine | ||
fn karura_side(fee_amount: u128) { | ||
Karura::execute_with(|| { | ||
assert_eq!( | ||
9_999_936_000_000, | ||
Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) | ||
); | ||
// ensure sender has enough KSM balance to be charged as fee | ||
assert_ok!(Tokens::deposit(KSM, &AccountId::from(BOB), TEN)); | ||
|
||
assert_ok!(XTokens::transfer_multicurrencies( | ||
Origin::signed(BOB.into()), | ||
vec![(CurrencyId::ForeignAsset(0), UNIT), (KSM, fee_amount)], | ||
1, | ||
Box::new( | ||
MultiLocation::new( | ||
1, | ||
X2( | ||
Parachain(1000), | ||
Junction::AccountId32 { | ||
network: NetworkId::Any, | ||
id: BOB.into(), | ||
} | ||
) | ||
) | ||
.into() | ||
), | ||
FEE_STATEMINE as u64 | ||
)); | ||
|
||
assert_eq!( | ||
8_999_936_000_000, | ||
Tokens::free_balance(CurrencyId::ForeignAsset(0), &AccountId::from(BOB)) | ||
); | ||
assert_eq!(TEN - fee_amount, Tokens::free_balance(KSM, &AccountId::from(BOB))); | ||
}); | ||
} | ||
|
||
// transfer custom asset from Statemine to Karura | ||
fn statemine_side() { | ||
register_asset(); | ||
|
||
let para_acc: AccountId = Sibling::from(2000).into_account(); | ||
|
||
Statemine::execute_with(|| { | ||
use statemine_runtime::*; | ||
|
||
let origin = Origin::signed(ALICE.into()); | ||
Balances::make_free_balance_be(&ALICE.into(), TEN); | ||
Balances::make_free_balance_be(&BOB.into(), UNIT); | ||
|
||
// create custom asset cost 1 KSM | ||
assert_ok!(Assets::create( | ||
origin.clone(), | ||
0, | ||
MultiAddress::Id(ALICE.into()), | ||
UNIT / 100 | ||
)); | ||
assert_eq!(9 * UNIT, Balances::free_balance(&AccountId::from(ALICE))); | ||
|
||
assert_ok!(Assets::mint( | ||
origin.clone(), | ||
0, | ||
MultiAddress::Id(ALICE.into()), | ||
1000 * UNIT | ||
)); | ||
|
||
// need to have some KSM to be able to receive user assets | ||
Balances::make_free_balance_be(¶_acc, UNIT); | ||
|
||
assert_ok!(PolkadotXcm::reserve_transfer_assets( | ||
origin.clone(), | ||
Box::new(MultiLocation::new(1, X1(Parachain(2000))).into()), | ||
Box::new( | ||
Junction::AccountId32 { | ||
id: BOB, | ||
network: NetworkId::Any | ||
} | ||
.into() | ||
.into() | ||
), | ||
Box::new((X2(PalletInstance(50), GeneralIndex(0)), TEN).into()), | ||
0 | ||
)); | ||
|
||
assert_eq!(0, Assets::balance(0, &AccountId::from(BOB))); | ||
|
||
assert_eq!(TEN, Assets::balance(0, ¶_acc)); | ||
// the KSM balance of sibling parachain sovereign account is not changed | ||
assert_eq!(UNIT, Balances::free_balance(¶_acc)); | ||
}); | ||
|
||
// Rerun the Statemine::execute to actually send the egress message via XCM | ||
Statemine::execute_with(|| {}); | ||
} | ||
|
||
fn register_asset() { | ||
Karura::execute_with(|| { | ||
// register foreign asset | ||
assert_ok!(AssetRegistry::register_foreign_asset( | ||
Origin::root(), | ||
Box::new(MultiLocation::new(1, X3(Parachain(1000), PalletInstance(50), GeneralIndex(0))).into()), | ||
Box::new(AssetMetadata { | ||
name: b"Sibling Token".to_vec(), | ||
symbol: b"ST".to_vec(), | ||
decimals: 10, | ||
minimal_balance: Balances::minimum_balance() / 100, // 10% | ||
}) | ||
)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ pub use frame_support::{ | |
traits::{Everything, Get, Nothing}, | ||
weights::Weight, | ||
}; | ||
use orml_traits::MultiCurrency; | ||
use orml_traits::{parameter_type_with_key, MultiCurrency}; | ||
use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; | ||
use pallet_xcm::XcmPassthrough; | ||
use polkadot_parachain::primitives::Sibling; | ||
|
@@ -287,6 +287,16 @@ parameter_types! { | |
pub const MaxAssetsForTransfer: usize = 2; | ||
} | ||
|
||
parameter_type_with_key! { | ||
pub ParachainMinFee: |location: MultiLocation| -> u128 { | ||
#[allow(clippy::match_ref_pats)] // false positive | ||
match (location.parents, location.first_interior()) { | ||
(1, Some(Parachain(parachains::statemine::ID))) => 4_000_000_000, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be managed by XcmInterface pallet so that we can dynamically updating it if needed |
||
_ => u128::MAX, | ||
} | ||
}; | ||
} | ||
|
||
impl orml_xtokens::Config for Runtime { | ||
type Event = Event; | ||
type Balance = Balance; | ||
|
@@ -299,6 +309,7 @@ impl orml_xtokens::Config for Runtime { | |
type BaseXcmWeight = BaseXcmWeight; | ||
type LocationInverter = LocationInverter<Ancestry>; | ||
type MaxAssetsForTransfer = MaxAssetsForTransfer; | ||
type MinXcmFee = ParachainMinFee; | ||
} | ||
|
||
pub type LocalAssetTransactor = MultiCurrencyAdapter< | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deduplicate DMP: shaunxw/xcm-simulator#24