From 3d4e59d6ad1a9c6d44c39f8ed6e999d71c2d7433 Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 10 Jul 2023 17:44:06 +0200 Subject: [PATCH] Fix ddc-staking --- pallets/ddc-staking/Cargo.toml | 4 ++++ pallets/ddc-staking/src/mock.rs | 12 ++++++------ pallets/ddc-staking/src/tests.rs | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index 054094b61..93cc0d890 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -16,6 +16,10 @@ sp-std = { version = "4.0.0-dev", default-features = false, git = "https://githu frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } [dev-dependencies] +pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +pallet-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } +sp-tracing = { version = "5.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } substrate-test-utils = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [features] diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index bf98efab5..dea8eb524 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -48,16 +48,16 @@ impl frame_system::Config for Test { type BlockWeights = (); type BlockLength = (); type DbWeight = RocksDbWeight; - type Origin = Origin; + type RuntimeOrigin = RuntimeOrigin; type Index = AccountIndex; type BlockNumber = BlockNumber; - type Call = Call; + type RuntimeCall = RuntimeCall; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type BlockHashCount = ConstU64<250>; type Version = (); type PalletInfo = PalletInfo; @@ -75,7 +75,7 @@ impl pallet_balances::Config for Test { type MaxReserves = (); type ReserveIdentifier = [u8; 8]; type Balance = Balance; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -104,13 +104,13 @@ impl crate::pallet::Config for Test { type DefaultEdgeChillDelay = DefaultEdgeChillDelay; type DefaultStorageBondSize = DefaultStorageBondSize; type DefaultStorageChillDelay = DefaultStorageChillDelay; - type Event = Event; + type RuntimeEvent = RuntimeEvent; type UnixTime = Timestamp; type WeightInfo = (); } pub(crate) type DdcStakingCall = crate::Call; -pub(crate) type TestRuntimeCall = ::Call; +pub(crate) type TestRuntimeCall = ::RuntimeCall; pub struct ExtBuilder { has_edges: bool, diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 6bd5c8457..461f064d5 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -12,7 +12,7 @@ fn set_settings_works() { ExtBuilder::default().build_and_execute(|| { // setting works assert_ok!(DdcStaking::set_settings( - Origin::root(), + RuntimeOrigin::root(), 1, Some(ClusterSettings { edge_bond_size: 10, @@ -28,7 +28,7 @@ fn set_settings_works() { assert_eq!(settings.storage_chill_delay, 2); // removing works - assert_ok!(DdcStaking::set_settings(Origin::root(), 1, None)); + assert_ok!(DdcStaking::set_settings(RuntimeOrigin::root(), 1, None)); let settings = DdcStaking::settings(1); let default_settings: ClusterSettings = Default::default(); assert_eq!(settings.edge_bond_size, default_settings.edge_bond_size); @@ -86,16 +86,16 @@ fn change_controller_works() { assert_eq!(DdcStaking::bonded(&11), Some(10)); // 10 can control 11 who is initially a validator. - assert_ok!(DdcStaking::withdraw_unbonded(Origin::signed(10))); + assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(10))); // Change controller. - assert_ok!(DdcStaking::set_controller(Origin::signed(11), 3)); + assert_ok!(DdcStaking::set_controller(RuntimeOrigin::signed(11), 3)); assert_eq!(DdcStaking::bonded(&11), Some(3)); // 10 is no longer in control. - assert_noop!(DdcStaking::serve(Origin::signed(10), 1), Error::::NotController); + assert_noop!(DdcStaking::serve(RuntimeOrigin::signed(10), 1), Error::::NotController); // 3 is a new controller. - assert_ok!(DdcStaking::serve(Origin::signed(3), 1)); + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), 1)); }) } @@ -108,8 +108,8 @@ fn staking_should_work() { } // Add new CDN participant, account 3 controlled by 4. - assert_ok!(DdcStaking::bond(Origin::signed(3), 4, 1500)); - assert_ok!(DdcStaking::serve(Origin::signed(4), 1)); + assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, 1500)); + assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), 1)); // Account 4 controls the stash from account 3, which is 1500 units and 3 is a CDN // participant. @@ -131,7 +131,7 @@ fn staking_should_work() { DdcStaking::on_finalize(System::block_number()); // Schedule CDN participant removal. - assert_ok!(DdcStaking::chill(Origin::signed(4))); + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. let chilling = @@ -170,7 +170,7 @@ fn staking_should_work() { ); // Actual CDN participant removal. - assert_ok!(DdcStaking::chill(Origin::signed(4))); + assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Account 3 is no longer a CDN participant. assert_eq!(DdcStaking::edges(3), None);