diff --git a/frame/dex/src/mock.rs b/frame/dex/src/mock.rs index 9678084581fe8..56dbf1797258f 100644 --- a/frame/dex/src/mock.rs +++ b/frame/dex/src/mock.rs @@ -24,9 +24,10 @@ use frame_support::{ construct_runtime, instances::{Instance1, Instance2}, parameter_types, - traits::{ConstU32, ConstU64}, + traits::{AsEnsureOriginWithArg, ConstU32, ConstU64}, PalletId, }; +use frame_system::EnsureSigned; use sp_core::H256; use sp_keystore::{testing::KeyStore, KeystoreExt}; use sp_runtime::{ @@ -56,8 +57,8 @@ impl frame_system::Config for Test { type BaseCallFilter = frame_support::traits::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; @@ -65,7 +66,7 @@ impl frame_system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = ConstU64<250>; type DbWeight = (); type Version = (); @@ -82,7 +83,7 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); - type Event = Event; + type RuntimeEvent = RuntimeEvent; type ExistentialDeposit = ConstU64<1>; type AccountStore = System; type WeightInfo = (); @@ -92,11 +93,12 @@ impl pallet_balances::Config for Test { } impl pallet_assets::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = u64; type AssetId = u32; type Currency = Balances; type ForceOrigin = frame_system::EnsureRoot; + type CreateOrigin = AsEnsureOriginWithArg>; type AssetDeposit = ConstU64<1>; type AssetAccountDeposit = ConstU64<10>; type MetadataDepositBase = ConstU64<1>; @@ -110,11 +112,12 @@ impl pallet_assets::Config for Test { //TODO: limit creation only to dex pallet impl pallet_assets::Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Balance = u64; type AssetId = u32; type Currency = Balances; type ForceOrigin = frame_system::EnsureRoot; + type CreateOrigin = AsEnsureOriginWithArg>; type AssetDeposit = ConstU64<0>; type AssetAccountDeposit = ConstU64<0>; type MetadataDepositBase = ConstU64<0>; @@ -131,7 +134,7 @@ parameter_types! { } impl Config for Test { - type Event = Event; + type RuntimeEvent = RuntimeEvent; type Currency = Balances; type AssetBalance = ::Balance; type Assets = Assets; diff --git a/frame/dex/src/tests.rs b/frame/dex/src/tests.rs index 29b9c09042bbe..edbd6fed92683 100644 --- a/frame/dex/src/tests.rs +++ b/frame/dex/src/tests.rs @@ -26,7 +26,7 @@ fn events() -> Vec> { let result = System::events() .into_iter() .map(|r| r.event) - .filter_map(|e| if let mock::Event::Dex(inner) = e { Some(inner) } else { None }) + .filter_map(|e| if let mock::RuntimeEvent::Dex(inner) = e { Some(inner) } else { None }) .collect(); System::reset_events(); @@ -43,7 +43,7 @@ fn pools() -> Vec> { fn assets() -> Vec { // if the storage would be public: // let mut s: Vec<_> = pallet_assets::pallet::Asset::::iter().map(|x| x.0).collect(); - let mut s: Vec<_> = <::Assets>::assets().collect(); + let mut s: Vec<_> = <::Assets>::asset_ids().collect(); s.sort(); s } @@ -51,14 +51,14 @@ fn assets() -> Vec { fn pool_assets() -> Vec { // if the storage would be public: // let mut s: Vec<_> = pallet_assets::pallet::PoolAsset::::iter().map(|x| x.0).collect(); - let mut s: Vec<_> = <::PoolAssets>::assets().collect(); + let mut s: Vec<_> = <::PoolAssets>::asset_ids().collect(); s.sort(); s } fn create_tokens(owner: u64, tokens: Vec) { for token_id in tokens { - assert_ok!(Assets::force_create(Origin::root(), token_id, owner, true, 1)); + assert_ok!(Assets::force_create(RuntimeOrigin::root(), token_id, owner, true, 1)); } } @@ -87,7 +87,7 @@ fn create_pool_should_work() { create_tokens(user, vec![token_1, token_2]); - assert_ok!(Dex::create_pool(Origin::signed(user), token_2, token_1, lp_token)); + assert_ok!(Dex::create_pool(RuntimeOrigin::signed(user), token_2, token_1, lp_token)); assert_eq!(events(), [Event::::PoolCreated { creator: user, pool_id, lp_token }]); assert_eq!(pools(), vec![pool_id]); @@ -107,13 +107,13 @@ fn add_liquidity_should_work() { topup_pallet(); create_tokens(user, vec![token_1, token_2]); - assert_ok!(Dex::create_pool(Origin::signed(user), token_1, token_2, lp_token)); + assert_ok!(Dex::create_pool(RuntimeOrigin::signed(user), token_1, token_2, lp_token)); - assert_ok!(Assets::mint(Origin::signed(user), token_1, user, 1000)); - assert_ok!(Assets::mint(Origin::signed(user), token_2, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_1, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_2, user, 1000)); assert_ok!(Dex::add_liquidity( - Origin::signed(user), + RuntimeOrigin::signed(user), token_1, token_2, 10, @@ -152,13 +152,13 @@ fn remove_liquidity_should_work() { topup_pallet(); create_tokens(user, vec![token_1, token_2]); - assert_ok!(Dex::create_pool(Origin::signed(user), token_1, token_2, lp_token)); + assert_ok!(Dex::create_pool(RuntimeOrigin::signed(user), token_1, token_2, lp_token)); - assert_ok!(Assets::mint(Origin::signed(user), token_1, user, 1000)); - assert_ok!(Assets::mint(Origin::signed(user), token_2, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_1, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_2, user, 1000)); assert_ok!(Dex::add_liquidity( - Origin::signed(user), + RuntimeOrigin::signed(user), token_1, token_2, 10, @@ -169,7 +169,16 @@ fn remove_liquidity_should_work() { 2 )); - assert_ok!(Dex::remove_liquidity(Origin::signed(user), token_1, token_2, 9, 0, 0, user, 2)); + assert_ok!(Dex::remove_liquidity( + RuntimeOrigin::signed(user), + token_1, + token_2, + 9, + 0, + 0, + user, + 2 + )); assert!(events().contains(&Event::::LiquidityRemoved { who: user, @@ -202,13 +211,13 @@ fn quote_price_should_work() { topup_pallet(); create_tokens(user, vec![token_1, token_2]); - assert_ok!(Dex::create_pool(Origin::signed(user), token_1, token_2, lp_token)); + assert_ok!(Dex::create_pool(RuntimeOrigin::signed(user), token_1, token_2, lp_token)); - assert_ok!(Assets::mint(Origin::signed(user), token_1, user, 1000)); - assert_ok!(Assets::mint(Origin::signed(user), token_2, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_1, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_2, user, 1000)); assert_ok!(Dex::add_liquidity( - Origin::signed(user), + RuntimeOrigin::signed(user), token_1, token_2, 1000, @@ -233,15 +242,15 @@ fn swap_should_work() { topup_pallet(); create_tokens(user, vec![token_1, token_2]); - assert_ok!(Dex::create_pool(Origin::signed(user), token_1, token_2, lp_token)); + assert_ok!(Dex::create_pool(RuntimeOrigin::signed(user), token_1, token_2, lp_token)); - assert_ok!(Assets::mint(Origin::signed(user), token_1, user, 1000)); - assert_ok!(Assets::mint(Origin::signed(user), token_2, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_1, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_2, user, 1000)); let liquidity1 = 1000; let liquidity2 = 20; assert_ok!(Dex::add_liquidity( - Origin::signed(user), + RuntimeOrigin::signed(user), token_1, token_2, liquidity1, @@ -256,7 +265,7 @@ fn swap_should_work() { let exchange_amount = 10; assert_ok!(Dex::swap_exact_tokens_for_tokens( - Origin::signed(user), + RuntimeOrigin::signed(user), token_2, token_1, exchange_amount, @@ -284,17 +293,17 @@ fn same_asset_swap_should_fail() { create_tokens(user, vec![token_1]); assert_noop!( - Dex::create_pool(Origin::signed(user), token_1, token_1, lp_token), + Dex::create_pool(RuntimeOrigin::signed(user), token_1, token_1, lp_token), Error::::EqualAssets ); - assert_ok!(Assets::mint(Origin::signed(user), token_1, user, 1000)); + assert_ok!(Assets::mint(RuntimeOrigin::signed(user), token_1, user, 1000)); let liquidity1 = 1000; let liquidity2 = 20; assert_noop!( Dex::add_liquidity( - Origin::signed(user), + RuntimeOrigin::signed(user), token_1, token_1, liquidity1, @@ -310,7 +319,7 @@ fn same_asset_swap_should_fail() { let exchange_amount = 10; assert_noop!( Dex::swap_exact_tokens_for_tokens( - Origin::signed(user), + RuntimeOrigin::signed(user), token_1, token_1, exchange_amount,