diff --git a/actors/market/src/lib.rs b/actors/market/src/lib.rs index 6ba7df4557..d68d820dfb 100644 --- a/actors/market/src/lib.rs +++ b/actors/market/src/lib.rs @@ -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 { +pub fn rt_deal_cid(rt: &impl Runtime, proposal: &DealProposal) -> Result { let data = serialize(proposal, "deal proposal")?; rt_serialized_deal_cid(rt, data.bytes()) } diff --git a/actors/market/tests/cron_tick_deal_expiry.rs b/actors/market/tests/cron_tick_deal_expiry.rs index 3517456090..75cf409ba7 100644 --- a/actors/market/tests/cron_tick_deal_expiry.rs +++ b/actors/market/tests/cron_tick_deal_expiry.rs @@ -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; @@ -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; @@ -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. @@ -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::(); + 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;