-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IT: Simplify liquidity_pool test module (#1869)
* basic xtransfer tests * parachain transfer tested * fix tests * transfer relay tests * polish and minor cleans * fixes * assets tests * currency conversion tests * fix cargo fmt * fix tests * reduce xcm restricted_transfer tests * rename file * restricted ethereum tests simplified and moved to restricted * cleaning warnings * removed re-added tranche tokens tests * remove fudge from proxy tests * minor cleans * fix warnings * decouple PARA_ID and SIBLING_ID from FudgeHandle * revert liquidity-pool changes * William suggestions
- Loading branch information
Showing
25 changed files
with
4,838 additions
and
7,596 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use cfg_types::tokens::CurrencyId; | ||
use frame_support::{assert_noop, assert_ok, dispatch::RawOrigin}; | ||
use sp_runtime::{DispatchError, DispatchError::BadOrigin}; | ||
|
||
use crate::{ | ||
generic::{ | ||
config::Runtime, env::Env, envs::runtime_env::RuntimeEnv, utils::currency::default_metadata, | ||
}, | ||
utils::orml_asset_registry, | ||
}; | ||
|
||
#[test_runtimes(all)] | ||
fn authority_configured<T: Runtime>() { | ||
let mut env = RuntimeEnv::<T>::default(); | ||
|
||
env.parachain_state_mut(|| { | ||
assert_ok!(orml_asset_registry::Pallet::<T>::register_asset( | ||
RawOrigin::Root.into(), | ||
default_metadata(), | ||
Some(CurrencyId::Native) | ||
)); | ||
|
||
assert_ok!(orml_asset_registry::Pallet::<T>::register_asset( | ||
RawOrigin::Root.into(), | ||
default_metadata(), | ||
Some(CurrencyId::ForeignAsset(42)) | ||
)); | ||
|
||
assert_noop!( | ||
orml_asset_registry::Pallet::<T>::register_asset( | ||
RawOrigin::Root.into(), | ||
default_metadata(), | ||
Some(CurrencyId::Tranche(42, [1; 16])) | ||
), | ||
BadOrigin | ||
); | ||
}); | ||
} | ||
|
||
#[test_runtimes(all)] | ||
fn processor_configured<T: Runtime>() { | ||
let mut env = RuntimeEnv::<T>::default(); | ||
|
||
env.parachain_state_mut(|| { | ||
assert_noop!( | ||
orml_asset_registry::Pallet::<T>::register_asset( | ||
RawOrigin::Root.into(), | ||
default_metadata(), | ||
None | ||
), | ||
DispatchError::Other("asset-registry: AssetId is required") | ||
); | ||
}); | ||
} |
100 changes: 100 additions & 0 deletions
100
runtime/integration-tests/src/generic/cases/currency_conversions.rs
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,100 @@ | ||
use cfg_types::tokens::CurrencyId; | ||
use orml_traits::asset_registry::AssetMetadata; | ||
use runtime_common::xcm::CurrencyIdConvert; | ||
use sp_runtime::traits::Convert; | ||
use staging_xcm::{ | ||
v4::{Junction::*, Junctions::Here, Location}, | ||
VersionedLocation, | ||
}; | ||
|
||
use crate::generic::{ | ||
config::Runtime, | ||
env::Env, | ||
envs::runtime_env::RuntimeEnv, | ||
utils::{ | ||
currency::{default_metadata, CurrencyInfo, CustomCurrency}, | ||
genesis::{self, Genesis}, | ||
xcm::transferable_custom, | ||
}, | ||
}; | ||
|
||
const PARA_ID: u32 = 1000; | ||
|
||
#[test_runtimes(all)] | ||
fn convert_transferable_asset<T: Runtime>() { | ||
// The way the native currency is represented relative to its runtime | ||
let location_inner = Location::new(0, Here); | ||
|
||
// The canonical way the native currency is represented out in the wild | ||
let location_canonical = Location::new(1, Parachain(PARA_ID)); | ||
|
||
let curr = CustomCurrency( | ||
CurrencyId::ForeignAsset(1), | ||
AssetMetadata { | ||
decimals: 18, | ||
location: Some(VersionedLocation::V4(location_canonical.clone())), | ||
additional: transferable_custom(), | ||
..default_metadata() | ||
}, | ||
); | ||
|
||
let env = RuntimeEnv::<T>::from_parachain_storage( | ||
Genesis::default() | ||
.add(genesis::parachain_id::<T>(PARA_ID)) | ||
.add(genesis::assets::<T>([(curr.id(), curr.metadata())])) | ||
.storage(), | ||
); | ||
|
||
env.parachain_state(|| { | ||
assert_eq!( | ||
CurrencyIdConvert::<T>::convert(location_inner), | ||
Some(curr.id()), | ||
); | ||
|
||
assert_eq!( | ||
CurrencyIdConvert::<T>::convert(curr.id()), | ||
Some(location_canonical) | ||
) | ||
}); | ||
} | ||
|
||
#[test_runtimes(all)] | ||
fn cannot_convert_nontransferable_asset<T: Runtime>() { | ||
let curr = CustomCurrency( | ||
CurrencyId::ForeignAsset(1), | ||
AssetMetadata { | ||
decimals: 18, | ||
location: Some(VersionedLocation::V4(Location::new(1, Parachain(PARA_ID)))), | ||
additional: Default::default(), // <- Not configured for transfers | ||
..default_metadata() | ||
}, | ||
); | ||
|
||
let env = RuntimeEnv::<T>::from_parachain_storage( | ||
Genesis::default() | ||
.add(genesis::parachain_id::<T>(PARA_ID)) | ||
.add(genesis::assets::<T>([(curr.id(), curr.metadata())])) | ||
.storage(), | ||
); | ||
|
||
env.parachain_state(|| { | ||
assert_eq!( | ||
CurrencyIdConvert::<T>::convert(Location::new(0, Here)), | ||
Some(curr.id()), | ||
); | ||
|
||
assert_eq!(CurrencyIdConvert::<T>::convert(curr.id()), None); | ||
}); | ||
} | ||
|
||
#[test_runtimes(all)] | ||
fn convert_unknown_location<T: Runtime>() { | ||
let env = RuntimeEnv::<T>::default(); | ||
|
||
env.parachain_state(|| { | ||
assert_eq!( | ||
CurrencyIdConvert::<T>::convert(Location::new(0, Here)), | ||
None, | ||
); | ||
}); | ||
} |
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
Oops, something went wrong.