Skip to content

Commit

Permalink
test: correctly handle cron vesting in tests
Browse files Browse the repository at this point in the history
1. In the test harness, check if we should vest every epoch. The queue
should already be quantized.
2. Correctly handle the fact that we vest at the _end_ of an epoch in
the cron vesting test.
  • Loading branch information
Stebalien committed Feb 21, 2025
1 parent 8a75734 commit 66b64bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
11 changes: 6 additions & 5 deletions actors/miner/tests/deadline_cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fil_actor_miner::{
};
use fil_actors_runtime::runtime::RuntimePolicy;
use fil_actors_runtime::test_utils::MockRuntime;
use fil_actors_runtime::{MessageAccumulator, EPOCHS_IN_DAY};
use fil_actors_runtime::{MessageAccumulator, EPOCHS_IN_DAY, EPOCHS_IN_HOUR};
use fvm_ipld_bitfield::BitField;
use fvm_shared::bigint::Zero;
use fvm_shared::clock::ChainEpoch;
Expand Down Expand Up @@ -91,16 +91,17 @@ fn test_vesting_on_cron() {
}
};

// move current epoch by a day so funds get vested
let new_epoch = q.quantize_up(current_epoch + EPOCHS_IN_DAY + 10);
// move current epoch by a day so funds get vested. +1 because rewards are vested at the end of
// an epoch.
let new_epoch = q.quantize_up(current_epoch + 12 * EPOCHS_IN_HOUR) + 1;
assert_locked_fn(new_epoch, true);

// no funds get vested if epoch moves by <12 hours
let new_epoch = new_epoch + (EPOCHS_IN_DAY / 2) - 100;
let new_epoch = new_epoch + (12 * EPOCHS_IN_HOUR) - 100;
assert_locked_fn(new_epoch, false);

// funds get vested again if epoch is quantised
let new_epoch = q.quantize_up(new_epoch);
let new_epoch = q.quantize_up(new_epoch) + 1;
assert_locked_fn(new_epoch, true);

h.check_state(&rt);
Expand Down
9 changes: 1 addition & 8 deletions actors/miner/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use fil_actor_miner::{
SectorReturn, SectorUpdateManifest, Sectors, State, SubmitWindowedPoStParams,
TerminateSectorsParams, TerminationDeclaration, VerifiedAllocationKey, VestingFunds,
WindowedPoSt, WithdrawBalanceParams, WithdrawBalanceReturn, CRON_EVENT_PROVING_DEADLINE,
NI_AGGREGATE_FEE_BASE_SECTOR_COUNT, NO_QUANTIZATION, REWARD_VESTING_SPEC, SECTORS_AMT_BITWIDTH,
NI_AGGREGATE_FEE_BASE_SECTOR_COUNT, NO_QUANTIZATION, SECTORS_AMT_BITWIDTH,
SECTOR_CONTENT_CHANGED,
};
use fil_actor_miner::{
Expand Down Expand Up @@ -3307,13 +3307,6 @@ enum MhCode {

fn immediately_vesting_funds(rt: &MockRuntime, state: &State) -> TokenAmount {
let curr_epoch = *rt.epoch.borrow();

let q =
QuantSpec { unit: REWARD_VESTING_SPEC.quantization, offset: state.proving_period_start };
if q.quantize_up(curr_epoch) != curr_epoch {
return TokenAmount::zero();
}

let vesting = rt.store.get_cbor::<VestingFunds>(&state.vesting_funds).unwrap().unwrap();
let mut sum = TokenAmount::zero();
for vf in vesting.funds {
Expand Down

0 comments on commit 66b64bf

Please sign in to comment.