Skip to content

Commit

Permalink
Fix incorrect deal weight calculation for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Sep 4, 2023
1 parent 63992dd commit 55f3f7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 12 additions & 7 deletions integration_tests/src/tests/replica_update_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ pub fn prove_replica_update_multi_dline_test(v: &dyn VM) {
assert!(ret_bf.get(first_sector_number_p1));
assert!(ret_bf.get(first_sector_number_p2));

let deal_weights1 = get_deal_weights(v, deal_ids[0]);
let deal_weights2 = get_deal_weights(v, deal_ids[1]);
let new_sector_info_p1 = sector_info(v, &maddr, first_sector_number_p1);
let duration = new_sector_info_p1.expiration - new_sector_info_p1.power_base_epoch;
let deal_weights1 = get_deal_weights(v, deal_ids[0], duration);
let deal_weights2 = get_deal_weights(v, deal_ids[1], duration);
assert_eq!(deal_weights1.0, new_sector_info_p1.deal_weight);
assert_eq!(deal_weights1.1, new_sector_info_p1.verified_deal_weight);
assert_eq!(old_sector_commr_p1, new_sector_info_p1.sector_key_cid.unwrap());
Expand Down Expand Up @@ -599,8 +600,9 @@ pub fn bad_post_upgrade_dispute_test(v: &dyn VM) {
assert_eq!(vec![100], bf_all(updated_sectors));

// sanity check the sector after update
let weights = get_deal_weights(v, deal_ids[0]);
let new_sector_info = sector_info(v, &maddr, sector_number);
let duration = new_sector_info.expiration - new_sector_info.power_base_epoch;
let weights = get_deal_weights(v, deal_ids[0], duration);
assert_eq!(weights.0, new_sector_info.deal_weight);
assert_eq!(weights.1, new_sector_info.verified_deal_weight);
assert_eq!(old_sector_info.sealed_cid, new_sector_info.sector_key_cid.unwrap());
Expand Down Expand Up @@ -933,9 +935,10 @@ pub fn deal_included_in_multiple_sectors_failure_test(v: &dyn VM) {
assert!(ret_bf.get(first_sector_number));
assert!(!ret_bf.get(first_sector_number + 1));

let weights1 = get_deal_weights(v, deal_ids[0]);
let weights2 = get_deal_weights(v, deal_ids[1]);
let new_sector_info_p1 = sector_info(v, &maddr, first_sector_number);
let duration = new_sector_info_p1.expiration - new_sector_info_p1.power_base_epoch;
let weights1 = get_deal_weights(v, deal_ids[0], duration);
let weights2 = get_deal_weights(v, deal_ids[1], duration);
assert_eq!(weights1.0 + weights2.0, new_sector_info_p1.deal_weight);
assert_eq!(weights1.1 + weights2.1, new_sector_info_p1.verified_deal_weight);
assert_eq!(new_sealed_cid1, new_sector_info_p1.sealed_cid);
Expand Down Expand Up @@ -1045,8 +1048,9 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) {
.matches(v.take_invocations().last().unwrap());

// sanity check the sector after update
let weights = get_deal_weights(v, deal_ids[0]);
let new_sector_info = sector_info(v, &maddr, sector_number);
let duration = new_sector_info.expiration - new_sector_info.power_base_epoch;
let weights = get_deal_weights(v, deal_ids[0], duration);
assert_eq!(weights.0, new_sector_info.deal_weight);
assert_eq!(weights.1, new_sector_info.verified_deal_weight);
assert_eq!(old_sector_info.sealed_cid, new_sector_info.sector_key_cid.unwrap());
Expand Down Expand Up @@ -1313,8 +1317,9 @@ pub fn create_miner_and_upgrade_sector(
assert_eq!(vec![100], bf_all(updated_sectors));

// sanity check the sector after update
let weights = get_deal_weights(v, deal_ids[0]);
let new_sector_info = sector_info(v, &maddr, sector_number);
let duration = new_sector_info.expiration - new_sector_info.power_base_epoch;
let weights = get_deal_weights(v, deal_ids[0], duration);
assert_eq!(weights.0, new_sector_info.deal_weight);
assert_eq!(weights.1, new_sector_info.verified_deal_weight);
assert_eq!(old_sector_info.sealed_cid, new_sector_info.sector_key_cid.unwrap());
Expand Down
10 changes: 7 additions & 3 deletions integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,14 @@ pub fn get_deal(v: &dyn VM, deal_id: DealID) -> DealProposal {
}

// return (deal_weight, verified_deal_weight)
pub fn get_deal_weights(v: &dyn VM, deal_id: DealID) -> (DealWeight, DealWeight) {
pub fn get_deal_weights(
v: &dyn VM,
deal_id: DealID,
duration: ChainEpoch,
) -> (DealWeight, DealWeight) {
let deal = get_deal(v, deal_id);
if deal.verified_deal {
return (DealWeight::zero(), DealWeight::from(deal.piece_size.0));
return (DealWeight::zero(), DealWeight::from(deal.piece_size.0 * duration as u64));
}
(DealWeight::from(deal.piece_size.0), DealWeight::zero())
(DealWeight::from(deal.piece_size.0 * duration as u64), DealWeight::zero())
}

0 comments on commit 55f3f7a

Please sign in to comment.