From 57f1d420832a3e37da7e061f18c385bc4727e652 Mon Sep 17 00:00:00 2001 From: shannonwells Date: Mon, 22 Apr 2024 11:50:22 -0700 Subject: [PATCH] some more updates after rebasing w/ origin branch --- common/primitives/src/capacity.rs | 21 --------------- e2e/scaffolding/helpers.ts | 16 ----------- node/cli/build.rs | 1 - pallets/capacity/src/benchmarking.rs | 7 +---- pallets/capacity/src/tests/other_tests.rs | 4 +-- .../src/tests/provider_boost_tests.rs | 27 +++++++++++++++++-- .../src/tests/stake_and_deposit_tests.rs | 4 +-- pallets/capacity/src/tests/testing_utils.rs | 7 ++--- .../frequency-tx-payment/src/tests/mock.rs | 2 +- .../src/tests/pallet_tests.rs | 4 +-- 10 files changed, 37 insertions(+), 56 deletions(-) diff --git a/common/primitives/src/capacity.rs b/common/primitives/src/capacity.rs index f209b8eab3..03c1fa735f 100644 --- a/common/primitives/src/capacity.rs +++ b/common/primitives/src/capacity.rs @@ -1,8 +1,5 @@ use crate::msa::MessageSourceId; -use codec::{Encode, MaxEncodedLen}; use frame_support::traits::tokens::Balance; -use scale_info::TypeInfo; -use sp_api::Decode; use sp_runtime::DispatchError; /// A trait for checking that a target MSA can be staked to. @@ -55,21 +52,3 @@ pub trait Replenishable { /// Checks if an account can be replenished. fn can_replenish(msa_id: MessageSourceId) -> bool; } - -#[derive( - Clone, Copy, Debug, Decode, Encode, TypeInfo, Eq, MaxEncodedLen, PartialEq, PartialOrd, -)] -/// The type of staking a given Staking Account is doing. -pub enum StakingType { - /// Staking account targets Providers for capacity only, no token reward - MaximumCapacity, - /// Staking account targets Providers and splits reward between capacity to the Provider - /// and token for the account holder - ProviderBoost, -} - -impl Default for StakingType { - fn default() -> Self { - StakingType::MaximumCapacity - } -} diff --git a/e2e/scaffolding/helpers.ts b/e2e/scaffolding/helpers.ts index 42cc1a07f4..c18f044f0f 100644 --- a/e2e/scaffolding/helpers.ts +++ b/e2e/scaffolding/helpers.ts @@ -447,22 +447,6 @@ 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(source: KeyringPair, keys: KeyringPair, providerId: u64, tokensToStake: bigint): Promise { - const stakeOp = ExtrinsicHelper.providerBoost(keys, providerId, tokensToStake); - const [stakeEvent] = await stakeOp.fundAndSend(source); - 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(); diff --git a/node/cli/build.rs b/node/cli/build.rs index adede271f5..487d0db051 100644 --- a/node/cli/build.rs +++ b/node/cli/build.rs @@ -6,7 +6,6 @@ use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_change feature = "frequency-no-relay", feature = "frequency-testnet" )))] - compile_error!( r#"You must enable one of these features: - Mainnet: "frequency" diff --git a/pallets/capacity/src/benchmarking.rs b/pallets/capacity/src/benchmarking.rs index 68c85029be..34f11209d4 100644 --- a/pallets/capacity/src/benchmarking.rs +++ b/pallets/capacity/src/benchmarking.rs @@ -47,7 +47,7 @@ benchmarks! { register_provider::(target, "Foo"); - }: _ (RawOrigin::Signed(caller.clone()), target, amount, staking_type) + }: _ (RawOrigin::Signed(caller.clone()), target, amount) verify { assert!(StakingAccountLedger::::contains_key(&caller)); assert!(StakingTargetLedger::::contains_key(&caller, target)); @@ -64,11 +64,6 @@ benchmarks! { } UnstakeUnlocks::::set(&caller, Some(unlocking)); - // set new unlock chunks using tuples of (value, thaw_at) - let new_unlocks: Vec<(u32, u32)> = Vec::from([(50u32, 3u32), (50u32, 5u32)]); - assert_eq!(true, staking_account.set_unlock_chunks(&new_unlocks)); - - Capacity::::set_staking_account(&caller.clone(), &staking_account); CurrentEpoch::::set(T::EpochNumber::from(5u32)); }: _ (RawOrigin::Signed(caller.clone())) diff --git a/pallets/capacity/src/tests/other_tests.rs b/pallets/capacity/src/tests/other_tests.rs index c22a7e7bfb..df9d629c80 100644 --- a/pallets/capacity/src/tests/other_tests.rs +++ b/pallets/capacity/src/tests/other_tests.rs @@ -96,7 +96,7 @@ fn set_target_details_is_successful() { target_details.amount = 10; target_details.capacity = 10; - Capacity::set_target_details_for(&staker, &target, &target_details); + Capacity::set_target_details_for(&staker, target, target_details); let stored_target_details = Capacity::get_target_for(&staker, target).unwrap(); @@ -120,7 +120,7 @@ fn set_capacity_details_is_successful() { last_replenished_epoch: 1u32, }; - Capacity::set_capacity_for(&target, &capacity_details); + Capacity::set_capacity_for(target, capacity_details); let stored_capacity_details = Capacity::get_capacity_for(target).unwrap(); diff --git a/pallets/capacity/src/tests/provider_boost_tests.rs b/pallets/capacity/src/tests/provider_boost_tests.rs index e95a0ecc36..02d15195bc 100644 --- a/pallets/capacity/src/tests/provider_boost_tests.rs +++ b/pallets/capacity/src/tests/provider_boost_tests.rs @@ -1,5 +1,7 @@ use super::{mock::*, testing_utils::*}; -use crate::*; +use crate::{ + BoostingAccountDetails, Error, Event, RewardPoolInfo, StakingAccountDetails, StakingHistory, +}; use common_primitives::{capacity::StakingType::ProviderBoost, msa::MessageSourceId}; use frame_support::{ assert_noop, assert_ok, @@ -7,7 +9,7 @@ use frame_support::{ }; #[test] -fn provider_boost_extrinsic_works() { +fn provider_boost_works() { new_test_ext().execute_with(|| { let account = 600; let target: MessageSourceId = 1; @@ -78,6 +80,27 @@ fn increase_boost_and_issue_capacity_happy_path() { }) } +#[test] +fn provider_boost_updates_boost_account_details() { + new_test_ext().execute_with(|| { + let account = 600; + let target: MessageSourceId = 1; + let amount = 500; + register_provider(target, String::from("Foo")); + assert_ok!(Capacity::provider_boost(RuntimeOrigin::signed(account), target, amount)); + let boost_details: BoostingAccountDetails = + Capacity::get_boost_details_for(account).unwrap(); + assert_eq!(boost_details.staking_details.active, 500); + assert_eq!(boost_details.staking_details.total, 500); + assert!(boost_details.last_rewards_claimed_at.is_none()); + assert_eq!(boost_details.boost_history.len(), 1); + + let expected_history = StakingHistory { reward_era: 0, total_staked: 500 }; + let actual_history = boost_details.boost_history.get(0).unwrap(); + assert_eq!(actual_history, &expected_history); + }) +} + #[test] fn provider_boost_adjusts_reward_pool_total() { new_test_ext().execute_with(|| { diff --git a/pallets/capacity/src/tests/stake_and_deposit_tests.rs b/pallets/capacity/src/tests/stake_and_deposit_tests.rs index e137c03018..4454ba052a 100644 --- a/pallets/capacity/src/tests/stake_and_deposit_tests.rs +++ b/pallets/capacity/src/tests/stake_and_deposit_tests.rs @@ -389,8 +389,8 @@ fn assert_successful_increase_stake( assert_ok!(Capacity::increase_stake_and_issue_capacity( &staker, &mut staking_account, - &target, - &staked, + target, + staked, )); assert_eq!(staking_account.total, staked); diff --git a/pallets/capacity/src/tests/testing_utils.rs b/pallets/capacity/src/tests/testing_utils.rs index bfa8e38f7f..2ecdd901c7 100644 --- a/pallets/capacity/src/tests/testing_utils.rs +++ b/pallets/capacity/src/tests/testing_utils.rs @@ -60,7 +60,7 @@ pub fn create_capacity_account_and_fund( capacity_details.total_capacity_issued = available; capacity_details.last_replenished_epoch = last_replenished; - Capacity::set_capacity_for(&target_msa_id, &capacity_details); + Capacity::set_capacity_for(target_msa_id, capacity_details.clone()); capacity_details.clone() } @@ -74,7 +74,7 @@ pub fn setup_provider( let provider_name = String::from("Cst-") + target.to_string().as_str(); register_provider(*target, provider_name); if amount.gt(&0u64) { - if staking_type == MaximumCapacity { + if staking_type == StakingType::MaximumCapacity { assert_ok!(Capacity::stake(RuntimeOrigin::signed(staker.clone()), *target, *amount,)); } else { assert_ok!(Capacity::provider_boost( @@ -85,6 +85,7 @@ pub fn setup_provider( } let target = Capacity::get_target_for(staker, target).unwrap(); assert_eq!(target.amount, *amount); - assert_eq!(target.staking_type, staking_type); + let account_staking_type = Capacity::get_staking_account_for(staker).unwrap().staking_type; + assert_eq!(account_staking_type, staking_type); } } diff --git a/pallets/frequency-tx-payment/src/tests/mock.rs b/pallets/frequency-tx-payment/src/tests/mock.rs index b7bff4206e..7d2879ea28 100644 --- a/pallets/frequency-tx-payment/src/tests/mock.rs +++ b/pallets/frequency-tx-payment/src/tests/mock.rs @@ -362,5 +362,5 @@ fn create_capacity_for(target: MessageSourceId, amount: u64) { let mut capacity_details = Capacity::get_capacity_for(target).unwrap_or_default(); let capacity: u64 = amount / (TEST_TOKEN_PER_CAPACITY as u64); capacity_details.deposit(&amount, &capacity).unwrap(); - Capacity::set_capacity_for(&target, &capacity_details); + Capacity::set_capacity_for(target, capacity_details); } diff --git a/pallets/frequency-tx-payment/src/tests/pallet_tests.rs b/pallets/frequency-tx-payment/src/tests/pallet_tests.rs index 910b9ba367..aa2754c9de 100644 --- a/pallets/frequency-tx-payment/src/tests/pallet_tests.rs +++ b/pallets/frequency-tx-payment/src/tests/pallet_tests.rs @@ -614,7 +614,7 @@ fn withdraw_fee_replenishes_capacity_account_on_new_epoch_before_deducting_fee() total_capacity_issued, last_replenished_epoch: 10, }; - Capacity::set_capacity_for(&provider_msa_id, &capacity_details); + Capacity::set_capacity_for(provider_msa_id, capacity_details); let call: &::RuntimeCall = &RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 100 }); @@ -660,7 +660,7 @@ fn withdraw_fee_does_not_replenish_if_not_new_epoch() { total_capacity_issued, last_replenished_epoch, }; - Capacity::set_capacity_for(&provider_msa_id, &capacity_details); + Capacity::set_capacity_for(provider_msa_id, capacity_details); let call: &::RuntimeCall = &RuntimeCall::Balances(BalancesCall::transfer { dest: 2, value: 100 });