Skip to content

Commit

Permalink
Fix ddc-staking
Browse files Browse the repository at this point in the history
  • Loading branch information
MRamanenkau committed Jul 10, 2023
1 parent 70985e4 commit 3d4e59d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions pallets/ddc-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions pallets/ddc-staking/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 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<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Test>;
pub(crate) type TestRuntimeCall = <Test as frame_system::Config>::Call;
pub(crate) type TestRuntimeCall = <Test as frame_system::Config>::RuntimeCall;

pub struct ExtBuilder {
has_edges: bool,
Expand Down
20 changes: 10 additions & 10 deletions pallets/ddc-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Test> = Default::default();
assert_eq!(settings.edge_bond_size, default_settings.edge_bond_size);
Expand Down Expand Up @@ -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::<Test>::NotController);
assert_noop!(DdcStaking::serve(RuntimeOrigin::signed(10), 1), Error::<Test>::NotController);
// 3 is a new controller.
assert_ok!(DdcStaking::serve(Origin::signed(3), 1));
assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), 1));
})
}

Expand All @@ -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.
Expand All @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d4e59d

Please sign in to comment.