Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexytsu committed Aug 17, 2023
1 parent 90c0c3e commit 1580d3c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
14 changes: 12 additions & 2 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,19 @@ impl Actor {
st.put_deal_states(rt.store(), &[(deal_id, deal_state)])?;
}
}
Ok(())
})?;

if !total_slashed.is_zero() {
extract_send_result(rt.send_simple(
&BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
None,
total_slashed.clone(),
))?;
}

Ok(ProcessDealsReturn { terminated_deals, total_slashed })
})
Ok(ProcessDealsReturn { terminated_deals, total_slashed })
}
}

Expand Down
19 changes: 18 additions & 1 deletion actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use cid::Cid;
use fil_actor_market::{
BatchActivateDealsParams, BatchActivateDealsResult, PendingDealAllocationsMap,
PENDING_ALLOCATIONS_CONFIG,
ProcessDealsParams, ProcessDealsReturn, PENDING_ALLOCATIONS_CONFIG,
};
use frc46_token::token::types::{TransferFromParams, TransferFromReturn};
use num_traits::{FromPrimitive, Zero};
Expand Down Expand Up @@ -763,6 +763,23 @@ pub fn publish_deals_expect_abort(
rt.verify();
}

pub fn process_deal_updates(
rt: &MockRuntime,
caller: Address,
deal_ids: Vec<DealID>,
) -> ProcessDealsReturn {
let params = ProcessDealsParams { deal_ids };
let params = IpldBlock::serialize_cbor(&params).unwrap();

rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, caller);
let res =
rt.call::<MarketActor>(Method::ProcessDealUpdatesExported as u64, params).unwrap().unwrap();
let res: ProcessDealsReturn = res.deserialize().unwrap();

rt.verify();
res
}

pub fn assert_deals_not_activated(rt: &MockRuntime, _epoch: ChainEpoch, deal_ids: &[DealID]) {
let st: State = rt.get_state();

Expand Down
60 changes: 60 additions & 0 deletions actors/market/tests/process_deal_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use fil_actor_market::{
Actor as MarketActor, ClientDealProposal, Method, PublishStorageDealsParams,
};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::test_utils::*;
use fil_actors_runtime::BURNT_FUNDS_ACTOR_ADDR;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::signature::Signature;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::METHOD_SEND;

use fil_actor_market::ext::account::{AuthenticateMessageParams, AUTHENTICATE_MESSAGE_METHOD};
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::sys::SendFlags;
use num_traits::Zero;

mod harness;

use harness::*;

const START_EPOCH: ChainEpoch = 50;
const END_EPOCH: ChainEpoch = START_EPOCH + 200 * EPOCHS_IN_DAY;

#[test]
fn timedout_deal_is_slashed_and_deleted() {
let rt = setup();
let deal_id = generate_and_publish_deal(
&rt,
CLIENT_ADDR,
&MinerAddresses::default(),
START_EPOCH,
END_EPOCH,
);
let deal_proposal = get_deal_proposal(&rt, deal_id);

let c_escrow = get_balance(&rt, &CLIENT_ADDR).balance;

// do a cron tick for it -> should time out and get slashed
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
rt.expect_send_simple(
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
None,
deal_proposal.provider_collateral.clone(),
None,
ExitCode::OK,
);

process_deal_updates(&rt, CLIENT_ADDR, vec![deal_id]);

let client_acct = get_balance(&rt, &CLIENT_ADDR);
assert_eq!(c_escrow, client_acct.balance);
assert!(client_acct.locked.is_zero());
assert_account_zero(&rt, PROVIDER_ADDR);
assert_deal_deleted(&rt, deal_id, deal_proposal);

check_state(&rt);
}

0 comments on commit 1580d3c

Please sign in to comment.