-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utilize SDK types for native asset balance conversion (#424)
Utilize SDK types for native asset balance conversion in the Treasury pallet setup. This change does not introduce any behavioral changes; it simply updates the code to use common types from the SDK. - [x] Does not require a CHANGELOG entry --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: fellowship-merge-bot[bot] <151052383+fellowship-merge-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
421f303
commit 7157d41
Showing
14 changed files
with
362 additions
and
180 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
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
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,96 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot 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. | ||
|
||
// Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! AssetRate pallet instance tests. | ||
|
||
use frame_support::traits::tokens::ConversionFromAssetBalance; | ||
use polkadot_runtime_common::impls::VersionedLocatableAsset; | ||
use staging_kusama_runtime::AssetRateWithNative; | ||
use xcm::prelude::*; | ||
|
||
#[test] | ||
fn native_asset_rate_works() { | ||
sp_io::TestExternalities::default().execute_with(|| { | ||
// success: native asset on Asset Hub as xcm v4 location | ||
let native = VersionedLocatableAsset::V4 { | ||
location: Location::new(0, [Parachain(1000)]), | ||
asset_id: Location::parent().into(), | ||
}; | ||
let actual = AssetRateWithNative::from_asset_balance(100, native).unwrap(); | ||
assert_eq!(actual, 100); | ||
|
||
// success: native asset on Asset Hub as xcm v3 location | ||
let native = VersionedLocatableAsset::V3 { | ||
location: xcm::v3::Location::new( | ||
0, | ||
xcm::v3::Junctions::X1(xcm::v3::Junction::Parachain(1000)), | ||
), | ||
asset_id: xcm::v3::Location::parent().into(), | ||
}; | ||
let actual = AssetRateWithNative::from_asset_balance(100, native).unwrap(); | ||
assert_eq!(actual, 100); | ||
|
||
// success: native asset on People as xcm v4 location | ||
let native = VersionedLocatableAsset::V4 { | ||
location: Location::new(0, [Parachain(1004)]), | ||
asset_id: Location::parent().into(), | ||
}; | ||
let actual = AssetRateWithNative::from_asset_balance(100, native).unwrap(); | ||
assert_eq!(actual, 100); | ||
|
||
// success: native asset on People as xcm v3 location | ||
let native = VersionedLocatableAsset::V3 { | ||
location: xcm::v3::Location::new( | ||
0, | ||
xcm::v3::Junctions::X1(xcm::v3::Junction::Parachain(1004)), | ||
), | ||
asset_id: xcm::v3::Location::parent().into(), | ||
}; | ||
let actual = AssetRateWithNative::from_asset_balance(100, native).unwrap(); | ||
assert_eq!(actual, 100); | ||
|
||
// failure: native asset on non system chain as xcm v4 location | ||
let native_non_system = VersionedLocatableAsset::V4 { | ||
location: Location::new(0, [Parachain(2000)]), | ||
asset_id: Location::parent().into(), | ||
}; | ||
assert!(AssetRateWithNative::from_asset_balance(100, native_non_system).is_err()); | ||
|
||
// failure: native asset on non system chain as xcm v3 location | ||
let native_non_system = VersionedLocatableAsset::V3 { | ||
location: xcm::v3::Location::new( | ||
0, | ||
xcm::v3::Junctions::X1(xcm::v3::Junction::Parachain(2000)), | ||
), | ||
asset_id: xcm::v3::Location::parent().into(), | ||
}; | ||
assert!(AssetRateWithNative::from_asset_balance(100, native_non_system).is_err()); | ||
|
||
// failure: some asset on Asset Hub as xcm v4 location | ||
let non_native = VersionedLocatableAsset::V4 { | ||
location: Location::new(0, [Parachain(2000)]), | ||
asset_id: Location::new(0, [PalletInstance(50), GeneralIndex(1984)]).into(), | ||
}; | ||
assert!(AssetRateWithNative::from_asset_balance(100, non_native).is_err()); | ||
|
||
// failure: native asset with invalid system chain location as xcm v4 location | ||
let native_non_system = VersionedLocatableAsset::V4 { | ||
location: Location::new(1, [Parachain(1000)]), | ||
asset_id: Location::parent().into(), | ||
}; | ||
assert!(AssetRateWithNative::from_asset_balance(100, native_non_system).is_err()); | ||
}); | ||
} |
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
Oops, something went wrong.