|
2 | 2 |
|
3 | 3 | use super::*; |
4 | 4 | use cumulus_primitives_core::ParaId; |
| 5 | +use frame_support::traits::ContainsPair; |
5 | 6 | use frame_support::{assert_err, assert_noop, assert_ok, traits::Currency}; |
6 | 7 | use mock::*; |
7 | 8 | use orml_traits::{ConcreteFungibleAsset, MultiCurrency}; |
| 9 | +use orml_xcm_support::MultiNativeAsset; |
8 | 10 | use parity_scale_codec::Encode; |
9 | 11 | use polkadot_parachain_primitives::primitives::Sibling; |
10 | 12 | use sp_runtime::{traits::AccountIdConversion, AccountId32}; |
@@ -1957,3 +1959,153 @@ fn set_migration_phase_should_work() { |
1957 | 1959 | assert_eq!(MigrationPhase::Completed, MigrationStatus::<para::Runtime>::get()); |
1958 | 1960 | }); |
1959 | 1961 | } |
| 1962 | + |
| 1963 | +// AbsoluteReserveProviderMigrationPhase and |
| 1964 | +// RelativeReserveProviderMigrationPhase |
| 1965 | +const PARACHAIN: Junction = Parachain(1); |
| 1966 | +const GENERAL_INDEX: Junction = GeneralIndex(1); |
| 1967 | + |
| 1968 | +fn concrete_fungible(id: Location) -> Asset { |
| 1969 | + (id, 1).into() |
| 1970 | +} |
| 1971 | + |
| 1972 | +#[test] |
| 1973 | +fn parent_as_reserve_chain() { |
| 1974 | + TestNet::reset(); |
| 1975 | + |
| 1976 | + ParaA::execute_with(|| { |
| 1977 | + assert_eq!( |
| 1978 | + AbsoluteReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 1979 | + 1, |
| 1980 | + [GENERAL_INDEX] |
| 1981 | + ))), |
| 1982 | + Some(Location::parent()) |
| 1983 | + ); |
| 1984 | + assert_eq!( |
| 1985 | + RelativeReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 1986 | + 1, |
| 1987 | + [GENERAL_INDEX] |
| 1988 | + ))), |
| 1989 | + Some(Location::parent()) |
| 1990 | + ); |
| 1991 | + }); |
| 1992 | +} |
| 1993 | + |
| 1994 | +#[test] |
| 1995 | +fn sibling_parachain_as_reserve_chain() { |
| 1996 | + TestNet::reset(); |
| 1997 | + |
| 1998 | + ParaA::execute_with(|| { |
| 1999 | + assert_eq!( |
| 2000 | + AbsoluteReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 2001 | + 1, |
| 2002 | + [PARACHAIN, GENERAL_INDEX] |
| 2003 | + ))), |
| 2004 | + Some(Location::new(1, [PARACHAIN])) |
| 2005 | + ); |
| 2006 | + assert_eq!( |
| 2007 | + RelativeReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 2008 | + 1, |
| 2009 | + [PARACHAIN, GENERAL_INDEX] |
| 2010 | + ))), |
| 2011 | + Some(Location::new(1, [PARACHAIN])) |
| 2012 | + ); |
| 2013 | + }); |
| 2014 | +} |
| 2015 | + |
| 2016 | +#[test] |
| 2017 | +fn child_parachain_as_reserve_chain() { |
| 2018 | + TestNet::reset(); |
| 2019 | + |
| 2020 | + ParaA::execute_with(|| { |
| 2021 | + assert_eq!( |
| 2022 | + AbsoluteReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 2023 | + 0, |
| 2024 | + [PARACHAIN, GENERAL_INDEX] |
| 2025 | + ))), |
| 2026 | + Some(PARACHAIN.into()) |
| 2027 | + ); |
| 2028 | + assert_eq!( |
| 2029 | + RelativeReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 2030 | + 0, |
| 2031 | + [PARACHAIN, GENERAL_INDEX] |
| 2032 | + ))), |
| 2033 | + Some(PARACHAIN.into()) |
| 2034 | + ); |
| 2035 | + }); |
| 2036 | +} |
| 2037 | + |
| 2038 | +#[test] |
| 2039 | +fn no_reserve_chain_for_absolute_self_for_relative() { |
| 2040 | + TestNet::reset(); |
| 2041 | + |
| 2042 | + ParaA::execute_with(|| { |
| 2043 | + assert_eq!( |
| 2044 | + AbsoluteReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 2045 | + 0, |
| 2046 | + [Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())] |
| 2047 | + ))), |
| 2048 | + None |
| 2049 | + ); |
| 2050 | + assert_eq!( |
| 2051 | + RelativeReserveProviderMigrationPhase::<para::Runtime>::reserve(&concrete_fungible(Location::new( |
| 2052 | + 0, |
| 2053 | + [Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())] |
| 2054 | + ))), |
| 2055 | + Some(Location::here()) |
| 2056 | + ); |
| 2057 | + }); |
| 2058 | +} |
| 2059 | + |
| 2060 | +#[test] |
| 2061 | +fn non_chain_part_works() { |
| 2062 | + assert_eq!(ParaXTokens::non_chain_part(&Location::parent()), None); |
| 2063 | + assert_eq!(ParaXTokens::non_chain_part(&Location::new(1, [PARACHAIN])), None); |
| 2064 | + assert_eq!(ParaXTokens::non_chain_part(&Location::new(0, [PARACHAIN])), None); |
| 2065 | + |
| 2066 | + assert_eq!( |
| 2067 | + ParaXTokens::non_chain_part(&Location::new(1, [GENERAL_INDEX])), |
| 2068 | + Some(GENERAL_INDEX.into()) |
| 2069 | + ); |
| 2070 | + assert_eq!( |
| 2071 | + ParaXTokens::non_chain_part(&Location::new(1, [GENERAL_INDEX, GENERAL_INDEX])), |
| 2072 | + Some((GENERAL_INDEX, GENERAL_INDEX).into()) |
| 2073 | + ); |
| 2074 | + assert_eq!( |
| 2075 | + ParaXTokens::non_chain_part(&Location::new(1, [PARACHAIN, GENERAL_INDEX])), |
| 2076 | + Some(GENERAL_INDEX.into()) |
| 2077 | + ); |
| 2078 | + assert_eq!( |
| 2079 | + ParaXTokens::non_chain_part(&Location::new(0, [PARACHAIN, GENERAL_INDEX])), |
| 2080 | + Some(GENERAL_INDEX.into()) |
| 2081 | + ); |
| 2082 | +} |
| 2083 | + |
| 2084 | +#[test] |
| 2085 | +fn multi_native_asset() { |
| 2086 | + TestNet::reset(); |
| 2087 | + |
| 2088 | + ParaA::execute_with(|| { |
| 2089 | + assert!( |
| 2090 | + MultiNativeAsset::<AbsoluteReserveProviderMigrationPhase<para::Runtime>>::contains( |
| 2091 | + &Asset { |
| 2092 | + fun: Fungible(10), |
| 2093 | + id: AssetId(Location::parent()) |
| 2094 | + }, |
| 2095 | + &Parent.into() |
| 2096 | + ) |
| 2097 | + ); |
| 2098 | + assert!( |
| 2099 | + MultiNativeAsset::<AbsoluteReserveProviderMigrationPhase<para::Runtime>>::contains( |
| 2100 | + &Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), |
| 2101 | + &Location::new(1, [Parachain(1)]), |
| 2102 | + ) |
| 2103 | + ); |
| 2104 | + assert!( |
| 2105 | + !MultiNativeAsset::<AbsoluteReserveProviderMigrationPhase<para::Runtime>>::contains( |
| 2106 | + &Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100), |
| 2107 | + &Location::parent(), |
| 2108 | + ) |
| 2109 | + ); |
| 2110 | + }); |
| 2111 | +} |
0 commit comments