From c880ed203c00dba371ed138e24f1fcadc5825e74 Mon Sep 17 00:00:00 2001 From: Dino Pacandi Date: Sat, 16 Dec 2023 14:47:25 +0100 Subject: [PATCH] Fixes --- pallets/dapp-staking-v3/src/lib.rs | 5 +++-- .../dapp-staking-v3/src/test/testing_utils.rs | 6 +++--- precompiles/dapps-staking-v3/Cargo.toml | 1 + precompiles/dapps-staking-v3/src/test/mock.rs | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pallets/dapp-staking-v3/src/lib.rs b/pallets/dapp-staking-v3/src/lib.rs index 7709515fad..05e4acf419 100644 --- a/pallets/dapp-staking-v3/src/lib.rs +++ b/pallets/dapp-staking-v3/src/lib.rs @@ -1140,8 +1140,9 @@ pub mod pallet { let earliest_staked_era = ledger .earliest_staked_era() .ok_or(Error::::InternalClaimStakerError)?; - let era_rewards = EraRewards::::get(Self::era_reward_span_index(earliest_staked_era)) - .ok_or(Error::::NoClaimableRewards)?; + let era_rewards = + EraRewards::::get(Self::era_reward_span_index(earliest_staked_era)) + .ok_or(Error::::NoClaimableRewards)?; // The last era for which we can theoretically claim rewards. // And indicator if we know the period's ending era. diff --git a/pallets/dapp-staking-v3/src/test/testing_utils.rs b/pallets/dapp-staking-v3/src/test/testing_utils.rs index 29cfd9e40d..a973bba7ac 100644 --- a/pallets/dapp-staking-v3/src/test/testing_utils.rs +++ b/pallets/dapp-staking-v3/src/test/testing_utils.rs @@ -1288,7 +1288,7 @@ pub(crate) fn assert_block_bump(pre_snapshot: &MemorySnapshot) { } // 4. Verify era reward - let era_span_index = DappStaking::era_reward_index(pre_protoc_state.era); + let era_span_index = DappStaking::era_reward_span_index(pre_protoc_state.era); let maybe_pre_era_reward_span = pre_snapshot.era_rewards.get(&era_span_index); let post_era_reward_span = post_snapshot .era_rewards @@ -1467,10 +1467,10 @@ pub(crate) fn required_number_of_reward_claims(account: AccountId) -> u32 { }; let era_span_length: EraNumber = ::EraRewardSpanLength::get(); - let first = DappStaking::era_reward_index(range.0) + let first = DappStaking::era_reward_span_index(range.0) .checked_div(era_span_length) .unwrap(); - let second = DappStaking::era_reward_index(range.1) + let second = DappStaking::era_reward_span_index(range.1) .checked_div(era_span_length) .unwrap(); diff --git a/precompiles/dapps-staking-v3/Cargo.toml b/precompiles/dapps-staking-v3/Cargo.toml index e39fca63f6..9d10ccb882 100644 --- a/precompiles/dapps-staking-v3/Cargo.toml +++ b/precompiles/dapps-staking-v3/Cargo.toml @@ -59,3 +59,4 @@ std = [ "pallet-balances/std", "sp-arithmetic/std", ] +runtime-benchmarks = ["pallet-dapp-staking-v3/runtime-benchmarks"] diff --git a/precompiles/dapps-staking-v3/src/test/mock.rs b/precompiles/dapps-staking-v3/src/test/mock.rs index 250f53e278..2015ba6736 100644 --- a/precompiles/dapps-staking-v3/src/test/mock.rs +++ b/precompiles/dapps-staking-v3/src/test/mock.rs @@ -225,6 +225,20 @@ impl CycleConfiguration for DummyCycleConfiguration { } } +// Just to satsify the trait bound +#[cfg(feature = "runtime-benchmarks")] +pub struct BenchmarkHelper(sp_std::marker::PhantomData<(SC, ACC)>); +#[cfg(feature = "runtime-benchmarks")] +impl pallet_dapp_staking_v3::BenchmarkHelper + for BenchmarkHelper +{ + fn get_smart_contract(id: u32) -> MockSmartContract { + MockSmartContract::evm(H160::from_low_u64_be(id as u64)) + } + + fn set_balance(_account: &AccountId, _amount: Balance) {} +} + impl pallet_dapp_staking_v3::Config for Test { type RuntimeEvent = RuntimeEvent; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -244,6 +258,8 @@ impl pallet_dapp_staking_v3::Config for Test { type MinimumStakeAmount = ConstU128<3>; type NumberOfTiers = ConstU32<4>; type WeightInfo = pallet_dapp_staking_v3::weights::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper; } construct_runtime!(