Skip to content

Commit 089a24a

Browse files
committed
Fix CI: rustfmt wrap and forbid-saturating-math in mock
- cargo fmt wraps the add_stake() call in AddStakeRecycleV1/AddStakeBurnV1 - mock charge_weight replaces saturating_add with checked_add().unwrap() to satisfy the ForbidSaturatingMath custom lint
1 parent 0216e94 commit 089a24a

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

chain-extensions/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,8 @@ where
587587
}
588588
FunctionId::AddStakeRecycleV1 => {
589589
let add_stake_weight =
590-
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::add_stake();
590+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::add_stake(
591+
);
591592
let recycle_weight =
592593
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::recycle_alpha();
593594

@@ -643,7 +644,8 @@ where
643644
}
644645
FunctionId::AddStakeBurnV1 => {
645646
let add_stake_weight =
646-
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::add_stake();
647+
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::add_stake(
648+
);
647649
let burn_weight =
648650
<<T as pallet_subtensor::Config>::WeightInfo as SubtensorWeightInfo>::burn_alpha();
649651

chain-extensions/src/tests.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,10 +1286,11 @@ impl SubtensorExtensionEnv<AccountId> for MockEnv {
12861286
}
12871287

12881288
fn charge_weight(&mut self, weight: Weight) -> Result<(), DispatchError> {
1289-
let cumulative = self
1290-
.charged_weight
1291-
.unwrap_or_default()
1292-
.saturating_add(weight);
1289+
let prev = self.charged_weight.unwrap_or_default();
1290+
let cumulative = Weight::from_parts(
1291+
prev.ref_time().checked_add(weight.ref_time()).unwrap(),
1292+
prev.proof_size().checked_add(weight.proof_size()).unwrap(),
1293+
);
12931294
if let Some(expected) = self.expected_weight
12941295
&& (cumulative.ref_time() > expected.ref_time()
12951296
|| cumulative.proof_size() > expected.proof_size())

0 commit comments

Comments
 (0)