Skip to content

Commit

Permalink
fix one test for legacy cron behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
alexytsu committed Aug 23, 2023
1 parent dc585f6 commit 5b01d4a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ fn deal_proposal_is_internally_valid(
}

/// Compute a deal CID using the runtime.
pub(crate) fn rt_deal_cid(rt: &impl Runtime, proposal: &DealProposal) -> Result<Cid, ActorError> {
pub fn rt_deal_cid(rt: &impl Runtime, proposal: &DealProposal) -> Result<Cid, ActorError> {
let data = serialize(proposal, "deal proposal")?;
rt_serialized_deal_cid(rt, data.bytes())
}
Expand Down
26 changes: 23 additions & 3 deletions actors/market/tests/cron_tick_deal_expiry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use fil_actor_market::{rt_deal_cid, State};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::runtime::{Policy, Runtime};
use fvm_shared::clock::ChainEpoch;

mod harness;
Expand Down Expand Up @@ -51,6 +52,7 @@ fn deal_is_correctly_processed_if_first_cron_after_expiry() {
check_state(&rt);
}

// this test needs to have the deal injected into the market actor state to simulate legacy deals
#[test]
fn regular_payments_till_deal_expires_and_then_locked_funds_are_unlocked() {
let start_epoch = Policy::default().deal_updates_interval;
Expand All @@ -70,6 +72,10 @@ fn regular_payments_till_deal_expires_and_then_locked_funds_are_unlocked() {
assert_eq!(0, deal_id);
let deal_proposal = get_deal_proposal(&rt, deal_id);

{
hack_trigger_legacy_deal(&rt, deal_id, start_epoch);
}

// move the current epoch to startEpoch + 5 so payment is made
// this skip of 5 epochs is unrealistic, but later demonstrates that the re-scheduled
// epoch distribution is robust to this.
Expand Down Expand Up @@ -119,11 +125,25 @@ fn regular_payments_till_deal_expires_and_then_locked_funds_are_unlocked() {
assert_eq!(duration * &deal_proposal.storage_price_per_epoch, pay);
assert!(slashed.is_zero());

// deal should be deleted as it should have expired
assert_deal_deleted(&rt, deal_id, deal_proposal);
check_state(&rt);
}

fn hack_trigger_legacy_deal(
rt: &fil_actors_runtime::test_utils::MockRuntime,
deal_id: u64,
start_epoch: i64,
) {
// HACK: factor this in a better way later
// this currently is needed to simulate legacy deals
let mut state = rt.get_state::<State>();
let mut deal_state = state.remove_deal_state(rt.store(), deal_id).unwrap().unwrap();
deal_state.last_updated_epoch = start_epoch;
state.put_deal_states(rt.store(), &[(deal_id, deal_state)]).unwrap();
let proposal = state.find_proposal(rt.store(), deal_id).unwrap().unwrap();
state.remove_pending_deal(rt.store(), rt_deal_cid(rt, &proposal).unwrap()).unwrap();
rt.replace_state(&state);
}

#[test]
fn payment_for_a_deal_if_deal_is_already_expired_before_a_cron_tick() {
let start = 5;
Expand Down

0 comments on commit 5b01d4a

Please sign in to comment.