From 9e19d322b60ac3bf137128502b039afca8f1202f Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Mon, 8 Jan 2024 19:32:09 +0400 Subject: [PATCH] itests partially complete --- integration_tests/src/expects.rs | 37 +++-- .../src/tests/commit_post_test.rs | 46 +++++- .../src/tests/prove_commit2_test.rs | 30 +++- .../src/tests/replica_update2_test.rs | 155 ++++++++++++------ .../src/tests/verified_claim_test.rs | 9 +- .../src/tests/verifreg_remove_datacap_test.rs | 4 +- integration_tests/src/util/workflows.rs | 80 ++++++--- 7 files changed, 268 insertions(+), 93 deletions(-) diff --git a/integration_tests/src/expects.rs b/integration_tests/src/expects.rs index 0d8f4368d..e0637089a 100644 --- a/integration_tests/src/expects.rs +++ b/integration_tests/src/expects.rs @@ -6,13 +6,13 @@ use fvm_ipld_bitfield::BitField; use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; +use fvm_shared::bigint::BigInt; use fvm_shared::clock::ChainEpoch; use fvm_shared::deal::DealID; use fvm_shared::econ::TokenAmount; +use fvm_shared::piece::PaddedPieceSize; use fvm_shared::sector::{RegisteredSealProof, SectorNumber}; use fvm_shared::{ActorID, METHOD_SEND}; -use fvm_shared::bigint::BigInt; -use fvm_shared::piece::PaddedPieceSize; use num_traits::Zero; use fil_actor_account::types::AuthenticateMessageParams; @@ -25,7 +25,12 @@ use fil_actor_miner::ext::verifreg::ClaimID; use fil_actor_miner::{IsControllingAddressParam, PowerPair}; use fil_actor_power::{UpdateClaimedPowerParams, UpdatePledgeTotalParams}; use fil_actor_verifreg::GetClaimsParams; -use fil_actors_runtime::{BURNT_FUNDS_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ID, EventBuilder, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ID, STORAGE_POWER_ACTOR_ADDR, STORAGE_POWER_ACTOR_ID, VERIFIED_REGISTRY_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ID}; +use fil_actors_runtime::{ + EventBuilder, BURNT_FUNDS_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ID, + REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ID, + STORAGE_POWER_ACTOR_ADDR, STORAGE_POWER_ACTOR_ID, VERIFIED_REGISTRY_ACTOR_ADDR, + VERIFIED_REGISTRY_ACTOR_ID, +}; use vm_api::trace::{EmittedEvent, ExpectInvocation}; @@ -213,6 +218,7 @@ impl Expect { amount: TokenAmount, operator_data: RawBytes, burn: bool, + alloc_events: Vec, ) -> ExpectInvocation { let payload = IpldBlock::serialize_cbor(&FRC46TokenReceived { from, @@ -244,11 +250,13 @@ impl Expect { .unwrap(), ), subinvocs: Some(burn_invocs), + events: alloc_events, ..Default::default() }]), ..Default::default() } } + pub fn verifreg_get_claims( from: ActorID, miner: ActorID, @@ -361,11 +369,21 @@ impl Expect { } } - pub fn build_market_event(typ: &str, deal_id: &DealID, client: &ActorID, provider: &ActorID) -> EmittedEvent { + pub fn build_market_event( + typ: &str, + deal_id: &DealID, + client: &ActorID, + provider: &ActorID, + ) -> EmittedEvent { EmittedEvent { emitter: STORAGE_MARKET_ACTOR_ID, - event: EventBuilder::new().typ(typ).field_indexed("id", &deal_id).field_indexed("client", &client). - field_indexed("provider", &provider).build().unwrap(), + event: EventBuilder::new() + .typ(typ) + .field_indexed("id", &deal_id) + .field_indexed("client", &client) + .field_indexed("provider", &provider) + .build() + .unwrap(), } } @@ -402,9 +420,6 @@ impl Expect { .field("piece-size", &BigInt::from(piece.1 .0)); } - EmittedEvent { - emitter: *miner_id, - event: base_event.build().unwrap(), - } + EmittedEvent { emitter: *miner_id, event: base_event.build().unwrap() } } -} \ No newline at end of file +} diff --git a/integration_tests/src/tests/commit_post_test.rs b/integration_tests/src/tests/commit_post_test.rs index 7cf317f28..786657d39 100644 --- a/integration_tests/src/tests/commit_post_test.rs +++ b/integration_tests/src/tests/commit_post_test.rs @@ -1,3 +1,4 @@ +use cid::Cid; use export_macro::vm_test; use fvm_ipld_bitfield::BitField; use fvm_ipld_encoding::ipld_block::IpldBlock; @@ -6,6 +7,7 @@ use fvm_shared::address::Address; use fvm_shared::bigint::Zero; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; +use fvm_shared::piece::PaddedPieceSize; use fvm_shared::randomness::Randomness; use fvm_shared::sector::{PoStProof, RegisteredSealProof, SectorNumber, MAX_SECTOR_NUMBER}; @@ -29,7 +31,7 @@ use fil_actors_runtime::{ CRON_ACTOR_ADDR, CRON_ACTOR_ID, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, STORAGE_POWER_ACTOR_ID, SYSTEM_ACTOR_ADDR, }; -use vm_api::trace::ExpectInvocation; +use vm_api::trace::{EmittedEvent, ExpectInvocation}; use vm_api::util::{apply_code, apply_ok, get_state, DynBlockstore}; use vm_api::VM; @@ -63,7 +65,20 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { // precommit and advance to prove commit time let sector_number: SectorNumber = 100; - precommit_sectors_v2(v, 1, 1, vec![], &worker, &id_addr, seal_proof, sector_number, true, None); + let infos = precommit_sectors_v2( + v, + 1, + 1, + vec![], + &worker, + &id_addr, + seal_proof, + sector_number, + true, + None, + ); + let pc = &infos[0]; + let unsealed_cid = pc.info.unsealed_cid.get_cid(pc.info.seal_proof).unwrap(); let balances = miner_balance(v, &id_addr); assert!(balances.pre_commit_deposit.is_positive()); @@ -101,6 +116,7 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { ) .unwrap(); assert_eq!(ExitCode::OK, res.code); + let pieces: Vec<(Cid, PaddedPieceSize)> = vec![]; ExpectInvocation { to: CRON_ACTOR_ADDR, method: CronMethod::EpochTick as u64, @@ -119,6 +135,13 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { id_addr.id().unwrap(), None, )]), + events: vec![Expect::build_sector_activation_event( + "sector-activated", + &id_addr.id().unwrap(), + §or_number, + &unsealed_cid, + &pieces, + )], ..Default::default() }, Expect::reward_update_kpi(), @@ -708,7 +731,7 @@ pub fn aggregate_one_precommit_expires_test(v: &dyn VM) { None, ); - let all_precommits = [early_precommits, later_precommits].concat(); + let all_precommits = [early_precommits, later_precommits.clone()].concat(); let sector_nos_bf = BitField::try_from_bits(all_precommits.iter().map(|info| info.info.sector_number)).unwrap(); @@ -747,6 +770,22 @@ pub fn aggregate_one_precommit_expires_test(v: &dyn VM) { MinerMethod::ProveCommitAggregate as u64, Some(prove_params), ); + + let events: Vec = later_precommits + .iter() + .map(|info| { + let pieces: Vec<(Cid, PaddedPieceSize)> = vec![]; + let unsealed_cid = &info.info.unsealed_cid.get_cid(info.info.seal_proof).unwrap(); + Expect::build_sector_activation_event( + "sector-activated", + &miner_id, + &info.info.sector_number, + unsealed_cid, + &pieces, + ) + }) + .collect(); + ExpectInvocation { from: worker_id, to: miner_addr, @@ -758,6 +797,7 @@ pub fn aggregate_one_precommit_expires_test(v: &dyn VM) { Expect::power_update_pledge(miner_id, None), Expect::burn(miner_id, None), ]), + events, ..Default::default() } .matches(v.take_invocations().last().unwrap()); diff --git a/integration_tests/src/tests/prove_commit2_test.rs b/integration_tests/src/tests/prove_commit2_test.rs index ca48b428f..5ff23c693 100644 --- a/integration_tests/src/tests/prove_commit2_test.rs +++ b/integration_tests/src/tests/prove_commit2_test.rs @@ -1,3 +1,4 @@ +use cid::Cid; use export_macro::vm_test; use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_ipld_encoding::RawBytes; @@ -27,7 +28,7 @@ use fil_actors_runtime::test_utils::make_piece_cid; use fil_actors_runtime::{ EPOCHS_IN_DAY, EPOCHS_IN_YEAR, STORAGE_MARKET_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR, }; -use vm_api::trace::ExpectInvocation; +use vm_api::trace::{EmittedEvent, ExpectInvocation}; use vm_api::util::apply_ok; use vm_api::VM; @@ -207,7 +208,7 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { v, meta.len(), meta.len(), - meta, + meta.clone(), &worker, &maddr, seal_proof, @@ -236,6 +237,25 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { MinerMethod::ProveCommitSectors3 as u64, Some(params.clone()), ); + + let events: Vec = manifests + .iter() + .enumerate() + .map(|(i, sa)| { + let unsealed_cid = meta.get(i).unwrap().commd.get_cid(seal_proof).unwrap(); + + let pieces: Vec<(Cid, PaddedPieceSize)> = + sa.pieces.iter().map(|p| (p.cid, p.size)).collect(); + Expect::build_sector_activation_event( + "sector-activated", + &miner_id, + &sa.sector_number, + &unsealed_cid, + &pieces, + ) + }) + .collect(); + ExpectInvocation { from: worker_id, to: maddr, @@ -286,6 +306,11 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { }) .unwrap(), ), + events: vec![ + Expect::build_verifreg_event("claim", &alloc_ids_s2[0], &client_id, &miner_id), + Expect::build_verifreg_event("claim", &alloc_ids_s2[1], &client_id, &miner_id), + Expect::build_verifreg_event("claim", &alloc_ids_s4[0], &client_id, &miner_id), + ], ..Default::default() }, Expect::reward_this_epoch(miner_id), @@ -318,6 +343,7 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { ..Default::default() }, ]), + events, ..Default::default() } .matches(v.take_invocations().last().unwrap()); diff --git a/integration_tests/src/tests/replica_update2_test.rs b/integration_tests/src/tests/replica_update2_test.rs index a07045768..25875d055 100644 --- a/integration_tests/src/tests/replica_update2_test.rs +++ b/integration_tests/src/tests/replica_update2_test.rs @@ -1,3 +1,4 @@ +use cid::Cid; use export_macro::vm_test; use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_ipld_encoding::RawBytes; @@ -5,10 +6,11 @@ use fvm_shared::bigint::BigInt; use fvm_shared::clock::ChainEpoch; use fvm_shared::deal::DealID; use fvm_shared::econ::TokenAmount; -use fvm_shared::piece::PaddedPieceSize; +use fvm_shared::piece::{PaddedPieceSize, PieceInfo}; use fvm_shared::sector::{ RegisteredAggregateProof, RegisteredSealProof, SectorNumber, StoragePower, }; +use integer_encoding::VarInt; use num_traits::Zero; use fil_actor_market::Method as MarketMethod; @@ -29,7 +31,7 @@ use fil_actors_runtime::test_utils::{make_piece_cid, make_sealed_cid}; use fil_actors_runtime::{ EPOCHS_IN_DAY, EPOCHS_IN_YEAR, STORAGE_MARKET_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR, }; -use vm_api::trace::ExpectInvocation; +use vm_api::trace::{EmittedEvent, ExpectInvocation}; use vm_api::util::apply_ok; use vm_api::VM; @@ -45,6 +47,24 @@ use crate::util::{ #[vm_test] pub fn prove_replica_update2_test(v: &dyn VM) { + // TODO: move this code somewhere more accessible. + // This change was made during a long rebase during which structural change was not practical. + v.mut_primitives().override_compute_unsealed_sector_cid( + |proof_type: RegisteredSealProof, pis: &[PieceInfo]| { + if pis.is_empty() { + return Ok(CompactCommD::empty().get_cid(proof_type).unwrap()); + } + let mut buf: Vec = Vec::new(); + let ptv: i64 = proof_type.into(); + buf.extend(ptv.encode_var_vec()); + for p in pis { + buf.extend(&p.cid.to_bytes()); + buf.extend(p.size.0.encode_var_vec()) + } + Ok(make_piece_cid(&buf)) + }, + ); + let policy = Policy::default(); let addrs = create_accounts(v, 3, &TokenAmount::from_whole(10_000)); let seal_proof = RegisteredSealProof::StackedDRG32GiBV1P1; @@ -72,55 +92,10 @@ pub fn prove_replica_update2_test(v: &dyn VM) { pieces: vec![], }) .collect(); - let meta: Vec = (0..activations.len()) - .map(|_| PrecommitMetadata { deals: vec![], commd: CompactCommD::empty() }) - .collect(); - let sector_expiry = v.epoch() + claim_term_min + 60 * EPOCHS_IN_DAY; - precommit_sectors_v2( - v, - meta.len(), - meta.len(), - meta, - &worker, - &maddr, - seal_proof, - first_sector_number, - true, - Some(sector_expiry), - ); - - let activation_epoch = v.epoch() + policy.pre_commit_challenge_delay + 1; - advance_by_deadline_to_epoch(v, &maddr, activation_epoch); - let proofs = vec![RawBytes::new(vec![1, 2, 3, 4]); activations.len()]; - let params = ProveCommitSectors3Params { - sector_activations: activations, - sector_proofs: proofs, - aggregate_proof: RawBytes::default(), - require_activation_success: true, - require_notification_success: true, - }; - apply_ok( - v, - &worker, - &maddr, - &TokenAmount::zero(), - MinerMethod::ProveCommitSectors3 as u64, - Some(params), - ); + let first_sector_number: SectorNumber = 100; // Advance to proving period and submit post for the partition let (dlinfo, partition) = advance_to_proving_deadline(v, &maddr, first_sector_number); let deadline = dlinfo.index; - submit_windowed_post(v, &worker, &maddr, dlinfo, partition, None); - advance_by_deadline_to_index(v, &maddr, dlinfo.index + 1); - let update_epoch = v.epoch(); - - // Note: the allocation and claim configuration here are duplicated from the prove_commit2 test. - // Register verifier and verified clients - let datacap = StoragePower::from(32_u128 << 40); - verifreg_add_verifier(v, &verifier, &datacap * 2); - verifreg_add_client(v, &verifier, &client, datacap); - - // Publish two verified allocations for half a sector each. let full_piece_size = PaddedPieceSize(sector_size as u64); let half_piece_size = PaddedPieceSize(sector_size as u64 / 2); let allocs = vec![ @@ -141,7 +116,9 @@ pub fn prove_replica_update2_test(v: &dyn VM) { expiration: 30 * EPOCHS_IN_DAY, }, ]; + // Publish two verified allocations for half a sector each. let alloc_ids_s2 = datacap_create_allocations(v, &client, &allocs); + let alloc_ids_s4 = vec![alloc_ids_s2[alloc_ids_s2.len() - 1] + 1]; // Publish a full-size deal let market_collateral = TokenAmount::from_whole(100); @@ -165,10 +142,7 @@ pub fn prove_replica_update2_test(v: &dyn VM) { let mut batcher = DealBatcher::new(v, opts); batcher.stage_with_label(client, maddr, "s4p1".to_string()); let deal_ids_s4 = batcher.publish_ok(worker).ids; - let alloc_ids_s4 = vec![alloc_ids_s2[alloc_ids_s2.len() - 1] + 1]; - // Update all sectors with a mix of data pieces, claims, and deals. - let first_sector_number: SectorNumber = 100; let manifests = vec![ // Sector 0: no pieces (CC sector) SectorUpdateManifest { @@ -248,6 +222,59 @@ pub fn prove_replica_update2_test(v: &dyn VM) { }, ]; + let meta: Vec = manifests + .iter() + .map(|sector| { + let pis: Vec = + sector.pieces.iter().map(|p| PieceInfo { size: p.size, cid: p.cid }).collect(); + let commd = v.primitives().compute_unsealed_sector_cid(seal_proof, &pis).unwrap(); + PrecommitMetadata { deals: vec![], commd: CompactCommD::of(commd) } + }) + .collect(); + + let sector_expiry = v.epoch() + claim_term_min + 60 * EPOCHS_IN_DAY; + precommit_sectors_v2( + v, + meta.len(), + meta.len(), + meta.clone(), + &worker, + &maddr, + seal_proof, + first_sector_number, + true, + Some(sector_expiry), + ); + + let activation_epoch = v.epoch() + policy.pre_commit_challenge_delay + 1; + advance_by_deadline_to_epoch(v, &maddr, activation_epoch); + let proofs = vec![RawBytes::new(vec![1, 2, 3, 4]); activations.len()]; + let params = ProveCommitSectors3Params { + sector_activations: activations, + sector_proofs: proofs, + aggregate_proof: RawBytes::default(), + require_activation_success: true, + require_notification_success: true, + }; + apply_ok( + v, + &worker, + &maddr, + &TokenAmount::zero(), + MinerMethod::ProveCommitSectors3 as u64, + Some(params), + ); + + submit_windowed_post(v, &worker, &maddr, dlinfo, partition, None); + advance_by_deadline_to_index(v, &maddr, dlinfo.index + 1); + let update_epoch = v.epoch(); + + // Note: the allocation and claim configuration here are duplicated from the prove_commit2 test. + // Register verifier and verified clients + let datacap = StoragePower::from(32_u128 << 40); + verifreg_add_verifier(v, &verifier, &datacap * 2); + verifreg_add_client(v, &verifier, &client, datacap); + // Replica update let update_proof = seal_proof.registered_update_proof().unwrap(); let proofs = vec![RawBytes::new(vec![1, 2, 3, 4]); manifests.len()]; @@ -275,6 +302,26 @@ pub fn prove_replica_update2_test(v: &dyn VM) { .map(|p| p.size.0 * 9) .sum::(), ); + + let events: Vec = manifests + .iter() + .enumerate() + .map(|(i, sa)| { + let pieces: Vec<(Cid, PaddedPieceSize)> = + sa.pieces.iter().map(|p| (p.cid, p.size)).collect(); + + let unsealed_cid = meta.get(i).unwrap().commd.get_cid(seal_proof).unwrap(); + + Expect::build_sector_activation_event( + "sector-updated", + &miner_id, + &sa.sector, + &unsealed_cid, + &pieces, + ) + }) + .collect(); + ExpectInvocation { from: worker_id, to: maddr, @@ -325,6 +372,11 @@ pub fn prove_replica_update2_test(v: &dyn VM) { }) .unwrap(), ), + events: vec![ + Expect::build_verifreg_event("claim", &alloc_ids_s2[0], &client_id, &miner_id), + Expect::build_verifreg_event("claim", &alloc_ids_s2[1], &client_id, &miner_id), + Expect::build_verifreg_event("claim", &alloc_ids_s4[0], &client_id, &miner_id), + ], ..Default::default() }, Expect::reward_this_epoch(miner_id), @@ -358,6 +410,7 @@ pub fn prove_replica_update2_test(v: &dyn VM) { ..Default::default() }, ]), + events, ..Default::default() } .matches(v.take_invocations().last().unwrap()); diff --git a/integration_tests/src/tests/verified_claim_test.rs b/integration_tests/src/tests/verified_claim_test.rs index 7c3020040..0c66a6c04 100644 --- a/integration_tests/src/tests/verified_claim_test.rs +++ b/integration_tests/src/tests/verified_claim_test.rs @@ -437,7 +437,14 @@ pub fn expired_allocations_test(v: &dyn VM) { let mut allocs = verifreg_state.load_allocs(&store).unwrap(); assert!(allocs.get(verified_client.id().unwrap(), alloc_id).unwrap().is_some()); - verifreg_remove_expired_allocations(v, &worker, &verified_client, vec![], deal_size, vec![alloc_id]); + verifreg_remove_expired_allocations( + v, + &worker, + &verified_client, + vec![], + deal_size, + vec![alloc_id], + ); // Allocation is gone let verifreg_state: VerifregState = get_state(v, &VERIFIED_REGISTRY_ACTOR_ADDR).unwrap(); diff --git a/integration_tests/src/tests/verifreg_remove_datacap_test.rs b/integration_tests/src/tests/verifreg_remove_datacap_test.rs index c0290bb12..599d8d4d6 100644 --- a/integration_tests/src/tests/verifreg_remove_datacap_test.rs +++ b/integration_tests/src/tests/verifreg_remove_datacap_test.rs @@ -31,7 +31,9 @@ use vm_api::VM; use crate::expects::Expect; -use crate::util::{assert_invariants, create_accounts, verifier_balance_event, verifreg_add_verifier}; +use crate::util::{ + assert_invariants, create_accounts, verifier_balance_event, verifreg_add_verifier, +}; use crate::{TEST_VERIFREG_ROOT_ADDR, TEST_VERIFREG_ROOT_ID}; #[vm_test] diff --git a/integration_tests/src/util/workflows.rs b/integration_tests/src/util/workflows.rs index 8810ecb01..8a303892e 100644 --- a/integration_tests/src/util/workflows.rs +++ b/integration_tests/src/util/workflows.rs @@ -1,5 +1,5 @@ -use std::cmp::min; use cid::Cid; +use std::cmp::min; use frc46_token::receiver::FRC46TokenReceived; use frc46_token::receiver::FRC46_TOKEN_TYPE; @@ -30,7 +30,10 @@ use num_traits::Zero; use fil_actor_cron::Method as CronMethod; use fil_actor_datacap::Method as DataCapMethod; use fil_actor_market::ext::verifreg::AllocationsResponse; -use fil_actor_market::{ClientDealProposal, DealProposal, Label, Method as MarketMethod, PublishStorageDealsParams, PublishStorageDealsReturn, SectorDeals, State as MarketState, MARKET_NOTIFY_DEAL_METHOD}; +use fil_actor_market::{ + ClientDealProposal, DealProposal, Label, Method as MarketMethod, PublishStorageDealsParams, + PublishStorageDealsReturn, SectorDeals, State as MarketState, MARKET_NOTIFY_DEAL_METHOD, +}; use fil_actor_miner::{ aggregate_pre_commit_network_fee, aggregate_prove_commit_network_fee, max_prove_commit_duration, ChangeBeneficiaryParams, CompactCommD, DeadlineInfo, @@ -44,13 +47,14 @@ use fil_actor_multisig::Method as MultisigMethod; use fil_actor_multisig::ProposeParams; use fil_actor_power::{CreateMinerParams, CreateMinerReturn, Method as PowerMethod}; use fil_actor_verifreg::ext::datacap::MintParams; -use fil_actor_verifreg::{AllocationRequest, DataCap}; use fil_actor_verifreg::AllocationRequests; use fil_actor_verifreg::ClaimExtensionRequest; use fil_actor_verifreg::{ AddVerifiedClientParams, AllocationID, ClaimID, ClaimTerm, ExtendClaimTermsParams, - Method as VerifregMethod, RemoveExpiredAllocationsParams, VerifierParams, State as VerifregState, + Method as VerifregMethod, RemoveExpiredAllocationsParams, State as VerifregState, + VerifierParams, }; +use fil_actor_verifreg::{AllocationRequest, DataCap}; use fil_actors_runtime::cbor::deserialize; use fil_actors_runtime::cbor::serialize; use fil_actors_runtime::runtime::policy_constants::{ @@ -59,7 +63,6 @@ use fil_actors_runtime::runtime::policy_constants::{ use fil_actors_runtime::runtime::Policy; use fil_actors_runtime::test_utils::make_piece_cid; use fil_actors_runtime::test_utils::make_sealed_cid; -use fil_actors_runtime::{DealWeight, EventBuilder}; use fil_actors_runtime::CRON_ACTOR_ADDR; use fil_actors_runtime::DATACAP_TOKEN_ACTOR_ADDR; use fil_actors_runtime::STORAGE_MARKET_ACTOR_ADDR; @@ -67,6 +70,7 @@ use fil_actors_runtime::STORAGE_MARKET_ACTOR_ID; use fil_actors_runtime::STORAGE_POWER_ACTOR_ADDR; use fil_actors_runtime::SYSTEM_ACTOR_ADDR; use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR; +use fil_actors_runtime::{DealWeight, EventBuilder}; use fil_actors_runtime::{DATACAP_TOKEN_ACTOR_ID, VERIFIED_REGISTRY_ACTOR_ID}; use vm_api::trace::{EmittedEvent, ExpectInvocation}; use vm_api::util::get_state; @@ -185,7 +189,7 @@ pub fn miner_prove_sector( .matches(v.take_invocations().last().unwrap()); } -#[derive(Default)] +#[derive(Default, Clone)] pub struct PrecommitMetadata { pub deals: Vec, pub commd: CompactCommD, @@ -253,9 +257,7 @@ pub fn precommit_sectors_v2_expect_code( let events: Vec = param_sectors .iter() - .map(|ps| { - Expect::build_miner_event("sector-precommitted", miner_id, ps.sector_number) - }) + .map(|ps| Expect::build_miner_event("sector-precommitted", miner_id, ps.sector_number)) .collect(); if !sectors_with_deals.is_empty() { @@ -292,7 +294,7 @@ pub fn precommit_sectors_v2_expect_code( .unwrap(), ), subinvocs: Some(invocs), - events: events, + events, ..Default::default() }; expect.matches(v.take_invocations().last().unwrap()); @@ -401,16 +403,25 @@ pub fn prove_commit_sectors( let st: MarketState = get_state(v, &STORAGE_MARKET_ACTOR_ADDR).unwrap(); let store = DynBlockstore::wrap(v.blockstore()); - let events:Vec = to_prove.iter().map(|ps| { - let mut pieces:Vec<(Cid, PaddedPieceSize)> = vec![]; - for deal_id in &ps.info.deal_ids { - let proposal = st.get_proposal(&store, *deal_id).unwrap(); - pieces.push((proposal.piece_cid, proposal.piece_size)); - } - - let unsealed_cid = &ps.info.unsealed_cid.get_cid(ps.info.seal_proof).unwrap(); - Expect::build_sector_activation_event("sector-activated", &miner_id, &ps.info.sector_number, &unsealed_cid, &pieces) - }).collect(); + let events: Vec = to_prove + .iter() + .map(|ps| { + let mut pieces: Vec<(Cid, PaddedPieceSize)> = vec![]; + for deal_id in &ps.info.deal_ids { + let proposal = st.get_proposal(&store, *deal_id).unwrap(); + pieces.push((proposal.piece_cid, proposal.piece_size)); + } + + let unsealed_cid = &ps.info.unsealed_cid.get_cid(ps.info.seal_proof).unwrap(); + Expect::build_sector_activation_event( + "sector-activated", + &miner_id, + &ps.info.sector_number, + unsealed_cid, + &pieces, + ) + }) + .collect(); let expected_fee = aggregate_prove_commit_network_fee(to_prove.len(), &TokenAmount::zero()); ExpectInvocation { @@ -424,7 +435,7 @@ pub fn prove_commit_sectors( Expect::power_update_pledge(miner_id, None), Expect::burn(miner_id, Some(expected_fee)), ]), - events: events, + events, ..Default::default() } .matches(v.take_invocations().last().unwrap()); @@ -876,7 +887,7 @@ pub fn verifreg_remove_expired_allocations( let alloc = allocs.get(client.id().unwrap(), *id).unwrap().unwrap(); Expect::build_verifreg_event( "allocation-removed", - &id, + id, &client.id().unwrap(), &alloc.provider, ) @@ -966,11 +977,21 @@ pub fn datacap_create_allocations( .unwrap(); let alloc_response: AllocationsResponse = tfer_result.recipient_data.deserialize().unwrap(); + let events: Vec = alloc_response + .new_allocations + .iter() + .enumerate() + .map(|(i, alloc_id)| { + Expect::build_verifreg_event("allocation", alloc_id, &client_id, &reqs[i].provider) + }) + .collect::>(); + Expect::datacap_transfer_to_verifreg( client_id, token_amount, operator_data, - false, // No burn + false, + events, // No burn ) .matches(v.take_invocations().last().unwrap()); @@ -1016,6 +1037,12 @@ pub fn datacap_extend_claim( token_amount, operator_data, true, // Burn + vec![Expect::build_verifreg_event( + "claim-updated", + &claim, + &client_id, + &provider.id().unwrap(), + )], ) .matches(v.take_invocations().last().unwrap()); } @@ -1188,7 +1215,12 @@ pub fn market_publish_deal( to: STORAGE_MARKET_ACTOR_ADDR, method: MarketMethod::PublishStorageDeals as u64, subinvocs: Some(expect_publish_invocs), - events: vec![Expect::build_market_event("deal-published", &ret.ids[0], &deal_client.id().unwrap(), &miner_id.id().unwrap())], + events: vec![Expect::build_market_event( + "deal-published", + &ret.ids[0], + &deal_client.id().unwrap(), + &miner_id.id().unwrap(), + )], ..Default::default() } .matches(v.take_invocations().last().unwrap());