Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update asset-registry
  • Loading branch information
mclyk committed Nov 24, 2022
commit 86689e034c96aaebaa20bab2c132bd7769a902ea
4 changes: 2 additions & 2 deletions pallets/asset-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub mod pallet {

#[pallet::config]
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// The Asset Id. This will be used to register the asset in Assets
type AssetId: Member + Parameter + Default + Copy + HasCompact + MaxEncodedLen;
Expand All @@ -55,7 +55,7 @@ pub mod pallet {
type Balance: Member + Parameter + AtLeast32BitUnsigned + Default + Copy + MaxEncodedLen;

/// Origin that is allowed to create and modify asset information
type UpdateOrigin: EnsureOrigin<Self::Origin>;
type UpdateOrigin: EnsureOrigin<Self::RuntimeOrigin>;

type WeightInfo: WeightInfo;
}
Expand Down
12 changes: 6 additions & 6 deletions pallets/asset-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
type Call = Call;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
Expand All @@ -78,7 +78,7 @@ parameter_types! {
impl pallet_balances::Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
Expand Down Expand Up @@ -143,7 +143,7 @@ impl Into<Option<MultiLocation>> for MockAssetType {
}

impl Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type Balance = u64;
type AssetId = u32;
type AssetType = MockAssetType;
Expand All @@ -166,7 +166,7 @@ pub(crate) fn events() -> Vec<super::Event<Test>> {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let Event::AssetRegistry(inner) = e {
if let RuntimeEvent::AssetRegistry(inner) = e {
Some(inner)
} else {
None
Expand Down
58 changes: 31 additions & 27 deletions pallets/asset-registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use frame_support::{assert_noop, assert_ok};
fn registering_works() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));
Expand All @@ -46,7 +46,7 @@ fn registering_works() {
fn test_asset_exists_error() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));
Expand All @@ -57,7 +57,7 @@ fn test_asset_exists_error() {
);
assert_noop!(
AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
),
Expand All @@ -70,13 +70,13 @@ fn test_asset_exists_error() {
fn test_root_can_change_units_per_second() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
));
Expand Down Expand Up @@ -107,7 +107,7 @@ fn test_regular_user_cannot_call_extrinsics() {
new_test_ext().execute_with(|| {
assert_noop!(
AssetRegistry::register_asset(
Origin::signed(1),
RuntimeOrigin::signed(1),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
),
Expand All @@ -116,15 +116,19 @@ fn test_regular_user_cannot_call_extrinsics() {

assert_noop!(
AssetRegistry::update_asset_units_per_second(
Origin::signed(1),
RuntimeOrigin::signed(1),
MockAssetType::MockAsset(1),
200u128.into(),
),
sp_runtime::DispatchError::BadOrigin
);

assert_noop!(
AssetRegistry::update_asset_type(Origin::signed(1), 1, MockAssetType::MockAsset(2),),
AssetRegistry::update_asset_type(
RuntimeOrigin::signed(1),
1,
MockAssetType::MockAsset(2),
),
sp_runtime::DispatchError::BadOrigin
);
});
Expand All @@ -134,19 +138,19 @@ fn test_regular_user_cannot_call_extrinsics() {
fn test_root_can_change_asset_id_type() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
));

assert_ok!(AssetRegistry::update_asset_type(
Origin::root(),
RuntimeOrigin::root(),
1,
MockAssetType::MockAsset(2),
));
Expand Down Expand Up @@ -194,13 +198,13 @@ fn test_root_can_change_asset_id_type() {
fn test_change_units_per_second_after_setting_it_once() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
));
Expand All @@ -214,7 +218,7 @@ fn test_change_units_per_second_after_setting_it_once() {
);

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
100u128.into(),
));
Expand Down Expand Up @@ -248,13 +252,13 @@ fn test_change_units_per_second_after_setting_it_once() {
fn test_root_can_change_units_per_second_and_then_remove() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
));
Expand All @@ -268,7 +272,7 @@ fn test_root_can_change_units_per_second_and_then_remove() {
);

assert_ok!(AssetRegistry::remove_fee_payment_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
));

Expand Down Expand Up @@ -296,19 +300,19 @@ fn test_root_can_change_units_per_second_and_then_remove() {
fn test_weight_hint_error() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
));

assert_ok!(AssetRegistry::remove_fee_payment_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1)
));
});
Expand All @@ -319,14 +323,14 @@ fn test_asset_id_non_existent_error() {
new_test_ext().execute_with(|| {
assert_noop!(
AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
),
Error::<Test>::AssetDoesNotExist
);
assert_noop!(
AssetRegistry::update_asset_type(Origin::root(), 1, MockAssetType::MockAsset(2),),
AssetRegistry::update_asset_type(RuntimeOrigin::root(), 1, MockAssetType::MockAsset(2),),
Error::<Test>::AssetDoesNotExist
);
});
Expand All @@ -336,18 +340,18 @@ fn test_asset_id_non_existent_error() {
fn test_root_can_remove_asset_association() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::update_asset_units_per_second(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1),
200u128.into(),
));

assert_ok!(AssetRegistry::deregister_asset(Origin::root(), 1,));
assert_ok!(AssetRegistry::deregister_asset(RuntimeOrigin::root(), 1,));

// Mappings are deleted
assert!(AssetRegistry::asset_type_id(MockAssetType::MockAsset(1)).is_none());
Expand Down Expand Up @@ -377,12 +381,12 @@ fn test_root_can_remove_asset_association() {
fn test_removing_without_asset_units_per_second_does_not_panic() {
new_test_ext().execute_with(|| {
assert_ok!(AssetRegistry::register_asset(
Origin::root(),
RuntimeOrigin::root(),
MockAssetType::MockAsset(1).into(),
MockAssetType::MockAsset(1),
));

assert_ok!(AssetRegistry::deregister_asset(Origin::root(), 1,));
assert_ok!(AssetRegistry::deregister_asset(RuntimeOrigin::root(), 1,));

// Mappings are deleted
assert!(AssetRegistry::asset_type_id(MockAssetType::MockAsset(1)).is_none());
Expand Down
Loading