-
Notifications
You must be signed in to change notification settings - Fork 299
relay account and tests #651
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
Open
zqhxuyuan
wants to merge
16
commits into
master
Choose a base branch
from
relay_account
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7421f97
relay account and tests
zqhxuyuan 514566b
convert origin unit test
zqhxuyuan 1f7d92a
add AllowDescendOrigin and integration test
zqhxuyuan d132663
sibling parachain test
zqhxuyuan f4162e3
add doc
zqhxuyuan ced4d67
add transfer test and change to AllowEquivalentAccountsFrom
zqhxuyuan cbb4944
clippy
zqhxuyuan c3b4d7d
fix test
zqhxuyuan 61d40f5
allow network any
zqhxuyuan 1cb1abf
add IsParent
zqhxuyuan 23e1a9f
clean test
zqhxuyuan e1467ba
clippy
zqhxuyuan 9cffcc5
rename
zqhxuyuan 631659b
fmt
zqhxuyuan b1a2a90
support withdraw and deposit after buy_execution
zqhxuyuan 4177cd6
rm withdraw and more tests
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,204 @@ | ||
#![cfg(test)] | ||
zqhxuyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
use super::*; | ||
use super::para::AccountIdToMultiLocation; | ||
use orml_traits::{MultiCurrency}; | ||
use xcm_simulator::TestExt; | ||
use xcm_builder::{IsConcrete}; | ||
use crate::mock::relay::KsmLocation; | ||
use xcm_executor::traits::MatchesFungible; | ||
use crate::mock::para::RelayLocation; | ||
|
||
#[test] | ||
fn test_init_balance() { | ||
Relay::execute_with(|| { | ||
assert_eq!(RelayBalances::free_balance(&ALICE), INITIAL_BALANCE); | ||
assert_eq!(RelayBalances::free_balance(&BOB), 0); | ||
assert_eq!(RelayBalances::free_balance(¶_a_account()), 0); | ||
assert_eq!(RelayBalances::free_balance(¶_b_account()), 0); | ||
}); | ||
|
||
ParaA::execute_with(|| { | ||
assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), INITIAL_BALANCE); | ||
assert_eq!(ParaTokens::free_balance(CurrencyId::R, &BOB), 0); | ||
|
||
assert_eq!(ParaTokens::free_balance(CurrencyId::A, &ALICE), 0); | ||
assert_eq!(ParaTokens::free_balance(CurrencyId::B, &ALICE), 0); | ||
|
||
assert_eq!(ParaBalances::free_balance(&ALICE), 0); | ||
assert_eq!(ParaBalances::free_balance(&BOB), 0); | ||
assert_eq!(ParaBalances::free_balance(&sibling_b_account()), 0); | ||
assert_eq!(ParaBalances::free_balance(&sibling_c_account()), 0); | ||
}); | ||
|
||
ParaB::execute_with(|| { | ||
assert_eq!(ParaTokens::free_balance(CurrencyId::R, &ALICE), INITIAL_BALANCE); | ||
assert_eq!(ParaTokens::free_balance(CurrencyId::R, &BOB), 0); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn test_asset_matches_fungible() { | ||
// use raw way: VersionedMultiAssets -> MultiAssets -> Vec<MultiAsset> | ||
// `KsmLocation` in `relay.rs` is `Here` | ||
let assets: VersionedMultiAssets = (Here, 100u128).into(); | ||
let assets: MultiAssets = assets.try_into().unwrap(); | ||
let assets: Vec<MultiAsset> = assets.drain(); | ||
for asset in assets { | ||
let assets: u128 = IsConcrete::<KsmLocation>::matches_fungible(&asset.clone()).unwrap_or_default(); | ||
assert_eq!(assets, 100u128); | ||
} | ||
|
||
// use convenient way, `KsmLocation` in `relay.rs` is `Here` | ||
let asset: MultiAsset = (Here, 100u128).into(); | ||
let amount: u128 = IsConcrete::<KsmLocation>::matches_fungible(&asset.clone()).unwrap_or_default(); | ||
assert_eq!(amount, 100u128); | ||
|
||
// the first parameter is not equal to `Here`, which not match `KsmLocation`, so asset match result is `0` | ||
let asset: MultiAsset = (X1(Parachain(1)), 100u128).into(); | ||
let assets: u128 = IsConcrete::<KsmLocation>::matches_fungible(&asset.clone()).unwrap_or_default(); | ||
assert_eq!(assets, 0); | ||
|
||
// `RelayLocation` in `para.rs` is `Parent` | ||
let asset: MultiAsset = (Parent, 100u128).into(); | ||
let assets: u128 = IsConcrete::<RelayLocation>::matches_fungible(&asset.clone()).unwrap_or_default(); | ||
assert_eq!(assets, 100); | ||
} | ||
|
||
#[test] | ||
fn test_account_location_convert() { | ||
let account = Junction::AccountId32 { | ||
network: NetworkId::Any, | ||
id: ALICE.into() | ||
}; | ||
|
||
let origin_location = AccountIdToMultiLocation::convert(ALICE); | ||
let junction: Junctions = origin_location.try_into().unwrap(); | ||
assert_eq!(junction, X1(account.clone())); | ||
|
||
let parent: MultiLocation = Parent.into(); | ||
assert_eq!(parent.parents, 1); | ||
assert_eq!(parent.interior, Here); | ||
assert_eq!(parent.contains_parents_only(1), true); | ||
|
||
let destination: MultiLocation = MultiLocation::new( | ||
1, | ||
X2( | ||
Parachain(2), | ||
account.clone(), | ||
) | ||
).into(); | ||
assert_eq!(destination.parents, 1); | ||
assert_eq!(destination.interior, X2(Parachain(2), account.clone())); | ||
|
||
let destination: MultiLocation = ( | ||
Parent, | ||
Parachain(2), | ||
account.clone(), | ||
).into(); | ||
assert_eq!(destination.parents, 1); | ||
assert_eq!(destination.interior, X2(Parachain(2), account.clone())); | ||
|
||
let destination: MultiLocation = ( | ||
Parent, | ||
account.clone() | ||
).into(); | ||
assert_eq!(destination.parents, 1); | ||
assert_eq!(destination.interior, X1(account.clone())); | ||
|
||
let destination: MultiLocation = ( | ||
Parachain(2), | ||
account.clone() | ||
).into(); | ||
assert_eq!(destination.parents, 0); | ||
assert_eq!(destination.interior, X2(Parachain(2), account.clone())); | ||
|
||
let junction = X1(account.clone()); | ||
let mut destination: MultiLocation = Parent.into(); | ||
destination.append_with(junction).unwrap(); | ||
assert_eq!(destination.parents, 1); | ||
assert_eq!(destination.interior, X1(account.clone())); | ||
} | ||
|
||
#[test] | ||
fn test_parachain_convert_location_to_account() { | ||
use xcm_executor::traits::Convert; | ||
|
||
// ParentIsDefault | ||
let parent: MultiLocation = Parent.into(); | ||
let account = para::LocationToAccountId::convert(parent); | ||
assert_eq!(account, Ok(GOD)); | ||
|
||
// SiblingParachainConvertsVia | ||
let destination: MultiLocation = ( | ||
Parent, | ||
Parachain(1), | ||
).into(); | ||
let account = para::LocationToAccountId::convert(destination); | ||
assert_eq!(account, Ok(sibling_a_account())); | ||
|
||
let alice = Junction::AccountId32 { | ||
network: NetworkId::Any, | ||
id: ALICE.into() | ||
}; | ||
|
||
// AccountId32Aliases | ||
let destination: MultiLocation = ( | ||
alice.clone() | ||
).into(); | ||
let account = para::LocationToAccountId::convert(destination); | ||
assert_eq!(account, Ok(ALICE)); | ||
|
||
// RelaychainAccountId32Aliases | ||
let destination: MultiLocation = ( | ||
Parent, | ||
alice.clone() | ||
).into(); | ||
let account = para::LocationToAccountId::convert(destination); | ||
assert_eq!(account, Ok(ALICE)); | ||
|
||
// Error case | ||
let destination: MultiLocation = ( | ||
Parent, | ||
Parachain(1), | ||
alice.clone() | ||
).into(); | ||
let account = para::LocationToAccountId::convert(destination.clone()); | ||
assert_eq!(account, Err(destination)); | ||
} | ||
|
||
#[test] | ||
fn test_relaychain_convert_location_to_account() { | ||
use xcm_executor::traits::Convert; | ||
|
||
// ChildParachainConvertsVia | ||
let destination: MultiLocation = ( | ||
Parachain(1), | ||
).into(); | ||
let account = relay::SovereignAccountOf::convert(destination); | ||
assert_eq!(account, Ok(para_a_account())); | ||
|
||
let alice = Junction::AccountId32 { | ||
network: NetworkId::Any, | ||
id: ALICE.into() | ||
}; | ||
|
||
let alice_unknown_network = Junction::AccountId32 { | ||
network: NetworkId::Polkadot, | ||
id: ALICE.into() | ||
}; | ||
|
||
// AccountId32Aliases | ||
let destination: MultiLocation = ( | ||
alice.clone() | ||
).into(); | ||
let account = relay::SovereignAccountOf::convert(destination); | ||
assert_eq!(account, Ok(ALICE)); | ||
|
||
// AccountId32Aliases with unknown-network location | ||
let destination: MultiLocation = ( | ||
alice_unknown_network.clone() | ||
).into(); | ||
let account = relay::SovereignAccountOf::convert(destination.clone()); | ||
assert_eq!(account, Err(destination)); | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.