Skip to content

Commit

Permalink
Feat/split stake extrinsic #1699 (#1717)
Browse files Browse the repository at this point in the history
The goal of this PR is to split the `stake` extrinsic into two: `stake` and `provider_boost`
Closes #1707
  • Loading branch information
shannonwells committed Apr 22, 2024
1 parent 7f5c5d4 commit 3269833
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 16 additions & 0 deletions e2e/scaffolding/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,22 @@ export async function boostProvider(source: KeyringPair, keys: KeyringPair, prov
return Promise.reject('stakeToProvider: stakeEvent should be ExtrinsicHelper.api.events.capacity.ProviderBoosted');
}
}
export async function boostProvider(keys: KeyringPair, providerId: u64, tokensToStake: bigint): Promise<void> {
const stakeOp = ExtrinsicHelper.providerBoost(keys, providerId, tokensToStake);
const [stakeEvent] = await stakeOp.fundAndSend();
assert.notEqual(stakeEvent, undefined, 'stakeToProvider: should have returned Stake event');

if (stakeEvent && ExtrinsicHelper.api.events.capacity.ProviderBoosted.is(stakeEvent)) {
let stakedCapacity = stakeEvent.data.capacity;

let expectedCapacity = tokensToStake/TokenPerCapacity/BoostAdjustment;

assert.equal(stakedCapacity, expectedCapacity, `stakeToProvider: expected ${expectedCapacity}, got ${stakedCapacity}`);
}
else {
return Promise.reject('stakeToProvider: stakeEvent should be ExtrinsicHelper.api.events.capacity.ProviderBoosted');
}
}

export async function getNextEpochBlock() {
const epochInfo = await ExtrinsicHelper.apiPromise.query.capacity.currentEpochInfo();
Expand Down
18 changes: 11 additions & 7 deletions pallets/capacity/src/tests/testing_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::mock::*;
use frame_support::{assert_ok, traits::Hooks};

use common_primitives::capacity::StakingType;
use common_primitives::capacity::{StakingType, StakingType::MaximumCapacity};
#[allow(unused)]
use sp_runtime::traits::SignedExtension;

Expand Down Expand Up @@ -90,6 +90,7 @@ pub fn setup_provider(
assert_eq!(account_staking_type, staking_type);
}
}

pub fn setup_provider(
staker: &u64,
target: &MessageSourceId,
Expand All @@ -99,12 +100,15 @@ pub fn setup_provider(
let provider_name = String::from("Cst-") + target.to_string().as_str();
register_provider(*target, provider_name);
if amount.gt(&0u64) {
assert_ok!(Capacity::stake(
RuntimeOrigin::signed(staker.clone()),
*target,
*amount,
staking_type.clone()
));
if staking_type == MaximumCapacity {
assert_ok!(Capacity::stake(RuntimeOrigin::signed(staker.clone()), *target, *amount,));
} else {
assert_ok!(Capacity::provider_boost(
RuntimeOrigin::signed(staker.clone()),
*target,
*amount
));
}
let target = Capacity::get_target_for(staker, target).unwrap();
assert_eq!(target.amount, *amount);
assert_eq!(target.staking_type, staking_type);
Expand Down

0 comments on commit 3269833

Please sign in to comment.