Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Dec 16, 2023
1 parent c8431e5 commit c880ed2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pallets/dapp-staking-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,9 @@ pub mod pallet {
let earliest_staked_era = ledger
.earliest_staked_era()
.ok_or(Error::<T>::InternalClaimStakerError)?;
let era_rewards = EraRewards::<T>::get(Self::era_reward_span_index(earliest_staked_era))
.ok_or(Error::<T>::NoClaimableRewards)?;
let era_rewards =
EraRewards::<T>::get(Self::era_reward_span_index(earliest_staked_era))
.ok_or(Error::<T>::NoClaimableRewards)?;

// The last era for which we can theoretically claim rewards.
// And indicator if we know the period's ending era.
Expand Down
6 changes: 3 additions & 3 deletions pallets/dapp-staking-v3/src/test/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1467,10 +1467,10 @@ pub(crate) fn required_number_of_reward_claims(account: AccountId) -> u32 {
};

let era_span_length: EraNumber = <Test as Config>::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();

Expand Down
1 change: 1 addition & 0 deletions precompiles/dapps-staking-v3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ std = [
"pallet-balances/std",
"sp-arithmetic/std",
]
runtime-benchmarks = ["pallet-dapp-staking-v3/runtime-benchmarks"]
16 changes: 16 additions & 0 deletions precompiles/dapps-staking-v3/src/test/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ impl CycleConfiguration for DummyCycleConfiguration {
}
}

// Just to satsify the trait bound
#[cfg(feature = "runtime-benchmarks")]
pub struct BenchmarkHelper<SC, ACC>(sp_std::marker::PhantomData<(SC, ACC)>);
#[cfg(feature = "runtime-benchmarks")]
impl pallet_dapp_staking_v3::BenchmarkHelper<MockSmartContract, AccountId>
for BenchmarkHelper<MockSmartContract, AccountId>
{
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;
Expand All @@ -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<Test>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = BenchmarkHelper<MockSmartContract, AccountId>;
}

construct_runtime!(
Expand Down

0 comments on commit c880ed2

Please sign in to comment.