Skip to content

Commit

Permalink
Fix itests and miner power dependent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed May 23, 2024
1 parent beae31a commit 3b6e063
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 74 deletions.
52 changes: 30 additions & 22 deletions actors/miner/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,10 @@ impl ActorHarness {
let compact_commd = if !has_deals {
CompactCommD::empty()
} else {
let piece_cids: Vec<Cid> = deal_ids[i]
.iter()
.enumerate()
.map(|(j, _deal_id)| make_piece_cid(sector_no, j, DEFAULT_PIECE_SIZE))
.collect();

// Determine CommD from configuration in the same way as prove_commit_and_confirm
let piece_specs = make_piece_specs_from_configs(sector_no, &sector_deal_ids, &prove_cfg);
let manifest = make_activation_manifest(sector_no, &piece_specs);
let piece_cids: Vec::<Cid> = manifest.pieces.iter().map(|p| p.cid).collect();
sector_commd_from_pieces(&piece_cids)
};

Expand Down Expand Up @@ -766,22 +764,8 @@ impl ActorHarness {
cfg: ProveCommitConfig,
) -> Result<SectorOnChainInfo, ActorError> {
let sector_number = params.sector_number;
const CLIENT_ID: ActorID = 1000;

let mut piece_specs = vec![];

for deal_id in deal_ids.iter() {
piece_specs.push((DEFAULT_PIECE_SIZE, CLIENT_ID, NO_ALLOCATION_ID, *deal_id));

// TODO modify this ^ for ProveCommitCfgs that specify particular deals and piece cids
/* let verified_allocation_key = if deal.allocation_id == NO_ALLOCATION_ID {
None
} else {
Some(VerifiedAllocationKey { client: deal.client, id: deal.allocation_id })
};
*/
}

let piece_specs = make_piece_specs_from_configs(sector_number, deal_ids, &cfg);

let manifest = make_activation_manifest(sector_number, &piece_specs);
let req_activation_succ = true; // Doesn't really matter since there's only 1
let req_notif_succ = false; // CPSV could not require this as it happened in cron
Expand Down Expand Up @@ -3355,6 +3339,30 @@ pub fn make_piece_manifest(
}
}

pub fn make_piece_specs_from_configs(sector_number: u64, deal_ids: &Vec<DealID>, prove_cfg: &ProveCommitConfig) ->Vec<(u64, ActorID, AllocationID, DealID)> {
static EMPTY_VEC: Vec<ActivatedDeal> = Vec::new();
let configured_deals = prove_cfg.activated_deals.get(&sector_number).unwrap_or(&EMPTY_VEC);
// The old configuration system had duplicated information between cfg and precommit inputs
// To ensure passed in configuration is internally consistent check that cfg deals are a subset
// of precommitted deal ids
assert!(deal_ids.len() >= configured_deals.len());
let mut piece_specs = vec![];
const DEFAULT_CLIENT_ID: ActorID = 1000;

for (i, deal_id) in deal_ids.iter().enumerate() {
if i < configured_deals.len() {
let deal = configured_deals.get(i).unwrap();
// Configured deals don't specify deal_id use deal_ids configuration info
// Piece specs don't specify piece cid but deterministically derive it so ignore deal.Cid
piece_specs.push((deal.size.0, deal.client, deal.allocation_id, deal_id.clone()));
} else {
piece_specs.push((DEFAULT_PIECE_SIZE, DEFAULT_CLIENT_ID, NO_ALLOCATION_ID, deal_id.clone()));
}
}

piece_specs
}

pub fn claims_from_pieces(pieces: &[PieceActivationManifest]) -> Vec<AllocationClaim> {
pieces
.iter()
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/src/expects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Expect {
params: Some(params),
value: Some(TokenAmount::zero()),
subinvocs: Some(vec![]),
events,
events: Some(events),
..Default::default()
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Expect {
params: Some(params),
value: Some(TokenAmount::zero()),
subinvocs: Some(vec![Expect::burn(STORAGE_MARKET_ACTOR_ID, None)]),
events,
events: Some(events),
..Default::default()
}
}
Expand Down Expand Up @@ -256,7 +256,7 @@ impl Expect {
.unwrap(),
),
subinvocs: Some(burn_invocs),
events: claim_events,
events: Some(claim_events),
..Default::default()
}]),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/tests/commit_post_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ pub fn aggregate_one_precommit_expires_test(v: &dyn VM) {
Expect::power_update_pledge(miner_id, None),
Expect::burn(miner_id, None),
]),
events,
events: Some(events),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/src/tests/extend_sectors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) {
from: miner_id,
to: VERIFIED_REGISTRY_ACTOR_ADDR,
method: VerifregMethod::ClaimAllocations as u64,
events: vec![Expect::build_verifreg_event(
events: Some(vec![Expect::build_verifreg_event(
"claim",
claim_id,
verified_client.id().unwrap(),
miner_id,
)],
)]),
..Default::default()
},
Expect::reward_this_epoch(miner_id),
Expand All @@ -698,13 +698,13 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) {
PowerPair { raw: StoragePower::zero(), qa: 9 * old_power.qa },
),
]),
events: vec![Expect::build_sector_activation_event(
events: Some(vec![Expect::build_sector_activation_event(
"sector-updated",
miner_id,
sector_number,
Some(unsealed_cid),
&pieces,
)],
)]),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
11 changes: 6 additions & 5 deletions integration_tests/src/tests/prove_commit3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) {
})
.unwrap(),
),
events: vec![
events: Some(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 @@ -323,17 +323,18 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) {
),
value: Some(TokenAmount::zero()),
subinvocs: Some(vec![]),
events: deal_ids_s3
events: Some(
deal_ids_s3
.iter()
.chain(deal_ids_s4.iter())
.map(|deal_id| {
Expect::build_market_event("deal-activated", *deal_id, client_id, miner_id)
})
.collect::<Vec<_>>(),
.collect::<Vec<_>>()),
..Default::default()
},
]),
events,
events: Some(events),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
10 changes: 5 additions & 5 deletions integration_tests/src/tests/replica_update3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
})
.unwrap(),
),
events: vec![
events: Some(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 @@ -387,18 +387,18 @@ pub fn prove_replica_update2_test(v: &dyn VM) {
),
value: Some(TokenAmount::zero()),
subinvocs: Some(vec![]),
events: deal_ids_s3
events: Some(deal_ids_s3
.iter()
.chain(deal_ids_s4.iter())
.map(|deal_id| {
Expect::build_market_event("deal-activated", *deal_id, client_id, miner_id)
})
.collect::<Vec<_>>(),
.collect::<Vec<_>>()),

..Default::default()
},
]),
events,
events: Some(events),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/src/tests/replica_update_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) {
from: miner_id,
to: VERIFIED_REGISTRY_ACTOR_ADDR,
method: VerifregMethod::ClaimAllocations as u64,
events: vec![claim_event],
events: Some(vec![claim_event]),
..Default::default()
},
Expect::reward_this_epoch(miner_id),
Expand All @@ -1072,13 +1072,13 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) {
PowerPair { raw: StoragePower::zero(), qa: 9 * old_power.qa },
),
]),
events: vec![Expect::build_sector_activation_event(
events: Some(vec![Expect::build_sector_activation_event(
"sector-updated",
miner_id,
sector_number,
Some(unsealed_cid),
&pieces,
)],
)]),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/tests/terminate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub fn terminate_sectors_test(v: &dyn VM) {
),
Expect::power_update_claim(miner_id, sector_power.neg()),
]),
events: vec![expect_event],
events: Some(vec![expect_event]),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn remove_datacap_simple_successful_path_test(v: &dyn VM) {
subinvocs: None,
..Default::default()
}]),
events: vec![verifier_balance_event(verifier1.id().unwrap(), verifier_datacap)],
events: Some(vec![verifier_balance_event(verifier1.id().unwrap(), verifier_datacap)]),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
18 changes: 9 additions & 9 deletions integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub fn precommit_sectors_v2_expect_code(
.unwrap(),
),
subinvocs: Some(invocs),
events,
events: Some(events),
..Default::default()
};
expect.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -438,7 +438,7 @@ pub fn prove_commit_sectors(
Expect::power_update_pledge(miner_id, None),
Expect::burn(miner_id, Some(expected_fee)),
]),
events,
events: Some(events),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -804,7 +804,7 @@ pub fn verifreg_add_verifier(v: &dyn VM, verifier: &Address, data_cap: StoragePo
DATACAP_TOKEN_ACTOR_ADDR,
*verifier,
)]),
events: vec![verifier_balance_event(verifier.id().unwrap(), data_cap)],
events: Some(vec![verifier_balance_event(verifier.id().unwrap(), data_cap)]),
..Default::default()
}]),
..Default::default()
Expand Down Expand Up @@ -864,7 +864,7 @@ pub fn verifreg_add_client(
)]),
..Default::default()
}]),
events: vec![verifier_balance_event(verifier.id().unwrap(), updated_verifier_balance)],
events: Some(vec![verifier_balance_event(verifier.id().unwrap(), updated_verifier_balance)]),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -956,7 +956,7 @@ pub fn verifreg_remove_expired_allocations(
)]),
..Default::default()
}]),
events: expected_events,
events: Some(expected_events),
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -1218,12 +1218,12 @@ pub fn market_publish_deal(
})
.unwrap(),
),
events: vec![Expect::build_verifreg_event(
events: Some(vec![Expect::build_verifreg_event(
"allocation",
alloc_id,
deal_client.id().unwrap(),
miner_id.id().unwrap(),
)],
)]),
..Default::default()
}]),
..Default::default()
Expand All @@ -1240,12 +1240,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(
events: Some(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());
Expand Down
42 changes: 22 additions & 20 deletions vm_api/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct ExpectInvocation {
pub exit_code: ExitCode,
pub return_value: Option<ReturnValue>,
pub subinvocs: Option<Vec<ExpectInvocation>>,
pub events: Vec<EmittedEvent>,
pub events: Option<Vec<EmittedEvent>>,
}

impl ExpectInvocation {
Expand Down Expand Up @@ -116,25 +116,27 @@ impl ExpectInvocation {
}

// match emitted events
let emitted_events = &invoc.events;
let expected_events = &self.events;
assert_eq!(
emitted_events.len(),
expected_events.len(),
"{} {} emitted={}, expected={}, {:?}, {:?}",
id,
"length of expected and emitted events do not match",
emitted_events.len(),
expected_events.len(),
emitted_events,
expected_events
);
if let Some(expected_events) = &self.events {
let emitted_events = &invoc.events;
assert_eq!(
emitted_events.len(),
expected_events.len(),
"{} {} emitted={}, expected={}, {:?}, {:?}",
id,
"length of expected and emitted events do not match",
emitted_events.len(),
expected_events.len(),
emitted_events,
expected_events
);


// use the zip method to iterate over the emitted events and expected_events
// vectors at the same time
for (emitted, expected) in emitted_events.iter().zip(expected_events.iter()) {
// only try to match if required fields match
assert_eq!(*emitted, *expected);
// use the zip method to iterate over the emitted events and expected_events
// vectors at the same time
for (emitted, expected) in emitted_events.iter().zip(expected_events.iter()) {
// only try to match if required fields match
assert_eq!(*emitted, *expected);
}
}

if let Some(expect_subinvocs) = &self.subinvocs {
Expand Down Expand Up @@ -207,7 +209,7 @@ impl Default for ExpectInvocation {
exit_code: ExitCode::OK,
return_value: None,
subinvocs: None,
events: vec![],
events: None,
}
}
}

0 comments on commit 3b6e063

Please sign in to comment.