Skip to content

Commit

Permalink
itests partially complete
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jan 8, 2024
1 parent 0485317 commit 9e19d32
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 93 deletions.
37 changes: 26 additions & 11 deletions integration_tests/src/expects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};

Expand Down Expand Up @@ -213,6 +218,7 @@ impl Expect {
amount: TokenAmount,
operator_data: RawBytes,
burn: bool,
alloc_events: Vec<EmittedEvent>,
) -> ExpectInvocation {
let payload = IpldBlock::serialize_cbor(&FRC46TokenReceived {
from,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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() }
}
}
}
46 changes: 43 additions & 3 deletions integration_tests/src/tests/commit_post_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cid::Cid;
use export_macro::vm_test;
use fvm_ipld_bitfield::BitField;
use fvm_ipld_encoding::ipld_block::IpldBlock;
Expand All @@ -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};

Expand All @@ -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;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
&sector_number,
&unsealed_cid,
&pieces,
)],
..Default::default()
},
Expect::reward_update_kpi(),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -747,6 +770,22 @@ pub fn aggregate_one_precommit_expires_test(v: &dyn VM) {
MinerMethod::ProveCommitAggregate as u64,
Some(prove_params),
);

let events: Vec<EmittedEvent> = 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,
Expand All @@ -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());
Expand Down
30 changes: 28 additions & 2 deletions integration_tests/src/tests/prove_commit2_test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cid::Cid;
use export_macro::vm_test;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::RawBytes;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -236,6 +237,25 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) {
MinerMethod::ProveCommitSectors3 as u64,
Some(params.clone()),
);

let events: Vec<EmittedEvent> = 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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -318,6 +343,7 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) {
..Default::default()
},
]),
events,
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
Loading

0 comments on commit 9e19d32

Please sign in to comment.