mirror of
https://github.com/pezkuwichain/pezkuwi-runtime-templates.git
synced 2026-04-22 06:47:55 +00:00
Upgrade evm-template to stable2412 (#407)
This commit is contained in:
@@ -8,6 +8,8 @@ use sp_std::{
|
||||
prelude::*,
|
||||
};
|
||||
use xcm::latest::Location;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use xcm::v3::MultiLocation;
|
||||
|
||||
use crate::{
|
||||
types::{AccountId, AssetId, Balance},
|
||||
@@ -30,20 +32,35 @@ pallet_assets::runtime_benchmarks_enabled! {
|
||||
// Our AssetType. For now we only handle Xcm Assets
|
||||
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
|
||||
pub enum AssetType {
|
||||
Xcm(xcm::v3::Location),
|
||||
Xcm(xcm::v4::Location),
|
||||
}
|
||||
impl Default for AssetType {
|
||||
fn default() -> Self {
|
||||
Self::Xcm(xcm::v3::Location::here())
|
||||
Self::Xcm(xcm::v4::Location::here())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<xcm::v3::Location> for AssetType {
|
||||
fn from(location: xcm::v3::Location) -> Self {
|
||||
impl From<xcm::v4::Location> for AssetType {
|
||||
fn from(location: xcm::v4::Location) -> Self {
|
||||
Self::Xcm(location)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn convert_v3_to_v4(v3: MultiLocation) -> Option<xcm::v4::Location> {
|
||||
Some(xcm::v4::Location {
|
||||
parents: v3.parents,
|
||||
interior: xcm::v4::Junctions::try_from(v3.interior).ok()?, // Returns None if conversion fails
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl From<MultiLocation> for AssetType {
|
||||
fn from(value: MultiLocation) -> Self {
|
||||
Self::Xcm(convert_v3_to_v4(value).unwrap_or(xcm::v4::Location::default()))
|
||||
}
|
||||
}
|
||||
|
||||
// This can be removed once we fully adopt xcm::v4 everywhere
|
||||
impl TryFrom<Location> for AssetType {
|
||||
type Error = ();
|
||||
@@ -53,7 +70,7 @@ impl TryFrom<Location> for AssetType {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AssetType> for Option<xcm::v3::Location> {
|
||||
impl From<AssetType> for Option<xcm::v4::Location> {
|
||||
fn from(val: AssetType) -> Self {
|
||||
match val {
|
||||
AssetType::Xcm(location) => Some(location),
|
||||
@@ -130,7 +147,7 @@ impl pallet_asset_manager::AssetRegistrar<Runtime> for AssetRegistrar {
|
||||
// This is the dispatch info of destroy
|
||||
RuntimeCall::Assets(pallet_assets::Call::<Runtime>::start_destroy { id: asset.into() })
|
||||
.get_dispatch_info()
|
||||
.weight
|
||||
.call_weight
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,55 +300,106 @@ mod tests {
|
||||
#[test]
|
||||
fn test_asset_type_default() {
|
||||
let default_asset_type = AssetType::default();
|
||||
assert_eq!(
|
||||
default_asset_type,
|
||||
AssetType::Xcm(xcm::v3::Location {
|
||||
parents: 0,
|
||||
interior: xcm::v3::Junctions::Here
|
||||
})
|
||||
);
|
||||
match default_asset_type {
|
||||
AssetType::Xcm(location) => {
|
||||
assert_eq!(location, xcm::v4::Location::here());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
#[test]
|
||||
fn test_asset_type_from_location_v3() {
|
||||
let location = xcm::v3::Location {
|
||||
parents: 0,
|
||||
interior: xcm::v3::Junctions::X1(xcm::v3::Junction::OnlyChild),
|
||||
};
|
||||
let asset_type = AssetType::from(location);
|
||||
let location =
|
||||
xcm::v3::MultiLocation { parents: 1, interior: xcm::v3::Junctions::Here };
|
||||
|
||||
assert_eq!(asset_type, AssetType::Xcm(location));
|
||||
// Use the From implementation directly
|
||||
let asset_type = AssetType::from(location);
|
||||
assert!(matches!(asset_type, AssetType::Xcm(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_type_try_from_location_v4() {
|
||||
let location =
|
||||
xcm::latest::Location { parents: 0, interior: xcm::latest::Junctions::Here };
|
||||
let old_location: xcm::v3::Location =
|
||||
xcm::v3::Location { parents: 0, interior: xcm::v3::Junctions::Here };
|
||||
let asset_type = AssetType::try_from(location)
|
||||
.expect("AssetType conversion from location v4 failed");
|
||||
|
||||
assert_eq!(asset_type, AssetType::Xcm(old_location));
|
||||
let location = xcm::v4::Location { parents: 1, interior: xcm::v4::Junctions::Here };
|
||||
let asset_type = AssetType::from(location.clone());
|
||||
match asset_type {
|
||||
AssetType::Xcm(loc) => assert_eq!(loc, location),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_type_into_location() {
|
||||
let location = xcm::v3::Location { parents: 0, interior: xcm::v3::Junctions::Here };
|
||||
let asset_type = AssetType::Xcm(location);
|
||||
let converted: Option<xcm::v3::Location> = asset_type.into();
|
||||
assert_eq!(converted, Some(location));
|
||||
let location = xcm::v4::Location::here();
|
||||
let asset_type = AssetType::Xcm(location.clone());
|
||||
let result: Option<xcm::v4::Location> = asset_type.into();
|
||||
assert_eq!(result, Some(location));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_asset_type_into_asset_id() {
|
||||
let location = xcm::v3::Location { parents: 0, interior: xcm::v3::Junctions::Here };
|
||||
let expected_asset_id: u128 = 114990615950639921045101060455076456094;
|
||||
let location = xcm::v4::Location { parents: 1, interior: xcm::v4::Junctions::Here };
|
||||
let asset_type = AssetType::Xcm(location);
|
||||
let asset_id: AssetId = asset_type.into();
|
||||
assert!(asset_id > 0);
|
||||
}
|
||||
|
||||
let asset_id = AssetId::from(asset_type);
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
#[test]
|
||||
fn test_convert_v3_to_v4() {
|
||||
use std::sync::Arc;
|
||||
|
||||
assert_eq!(asset_id, expected_asset_id);
|
||||
use xcm::v3::{Junction as JunctionV3, Junctions as JunctionsV3, MultiLocation};
|
||||
|
||||
use crate::configs::convert_v3_to_v4;
|
||||
|
||||
// Test with Here junctions
|
||||
let v3_location = MultiLocation { parents: 1, interior: JunctionsV3::Here };
|
||||
let v4_location = convert_v3_to_v4(v3_location).unwrap();
|
||||
assert_eq!(v4_location.parents, 1);
|
||||
assert_eq!(v4_location.interior, xcm::v4::Junctions::Here);
|
||||
|
||||
// Test with X1 junction
|
||||
let v3_location = MultiLocation {
|
||||
parents: 0,
|
||||
interior: JunctionsV3::X1(JunctionV3::Parachain(1000)),
|
||||
};
|
||||
let v4_location = convert_v3_to_v4(v3_location).unwrap();
|
||||
assert_eq!(v4_location.parents, 0);
|
||||
|
||||
// Create X1 junction with Arc
|
||||
let junction_array = Arc::new([xcm::v4::Junction::Parachain(1000)]);
|
||||
let expected_interior = xcm::v4::Junctions::X1(junction_array);
|
||||
assert_eq!(v4_location.interior, expected_interior);
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
#[test]
|
||||
fn test_from_multilocation_for_asset_type() {
|
||||
use std::sync::Arc;
|
||||
|
||||
use xcm::v3::{Junction as JunctionV3, Junctions as JunctionsV3, MultiLocation};
|
||||
|
||||
// Test with valid conversion
|
||||
let v3_location = MultiLocation { parents: 1, interior: JunctionsV3::Here };
|
||||
let asset_type = AssetType::from(v3_location);
|
||||
assert!(matches!(asset_type, AssetType::Xcm(_)));
|
||||
|
||||
// Test with more complex location
|
||||
let v3_location = MultiLocation {
|
||||
parents: 0,
|
||||
interior: JunctionsV3::X1(JunctionV3::Parachain(1000)),
|
||||
};
|
||||
let asset_type = AssetType::from(v3_location);
|
||||
match asset_type {
|
||||
AssetType::Xcm(location) => {
|
||||
assert_eq!(location.parents, 0);
|
||||
|
||||
// Create X1 junction with Arc
|
||||
let junction_array = Arc::new([xcm::v4::Junction::Parachain(1000)]);
|
||||
let expected_interior = xcm::v4::Junctions::X1(junction_array);
|
||||
assert_eq!(location.interior, expected_interior);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user