Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anorth committed Aug 11, 2023
1 parent 2118025 commit b67d97e
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 91 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,10 +1191,13 @@ impl Actor {
.get_cid(usi.sector_info.seal_proof)?;
if let Some(ref declared_commd) = usi.update.new_unsealed_cid {
if !declared_commd.eq(&computed_commd) {
info!(
"unsealed CID does not match with deals: expected {}, got {}, sector: {}",
computed_commd, declared_commd, usi.update.sector_number
);
return Err(actor_error!(
illegal_argument,
"unsealed CID does not match deals for sector {}, expected {} was {}",
usi.update.sector_number,
computed_commd,
declared_commd
));
}
}
let dl = usi.update.deadline;
Expand Down
48 changes: 25 additions & 23 deletions integration_tests/src/tests/extend_sectors_test.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
use fil_actor_market::{DealMetaArray, SectorDeals, State as MarketState};
use fvm_ipld_bitfield::BitField;
use fvm_shared::address::Address;
use fvm_shared::bigint::Zero;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::{PaddedPieceSize, PieceInfo};
use fvm_shared::sector::{RegisteredSealProof, SectorNumber, StoragePower};

use fil_actor_market::{DealMetaArray, State as MarketState};
use fil_actor_miner::{
max_prove_commit_duration, power_for_sector, ExpirationExtension, ExpirationExtension2,
ExtendSectorExpiration2Params, ExtendSectorExpirationParams, Method as MinerMethod, PowerPair,
ProveReplicaUpdatesParams2, ReplicaUpdate2, SectorClaim, Sectors, State as MinerState,
};
use fil_actor_verifreg::Method as VerifregMethod;
use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::test_utils::{make_piece_cid, make_sealed_cid};
use fil_actors_runtime::test_utils::make_sealed_cid;
use fil_actors_runtime::{
DealWeight, EPOCHS_IN_DAY, STORAGE_MARKET_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR,
};
use fvm_ipld_bitfield::BitField;
use fvm_shared::address::Address;
use fvm_shared::bigint::Zero;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::PaddedPieceSize;
use fvm_shared::sector::{RegisteredSealProof, SectorNumber, StoragePower};
use vm_api::trace::ExpectInvocation;
use vm_api::util::{apply_ok, get_state, mutate_state, DynBlockstore};
use vm_api::VM;
Expand All @@ -25,9 +26,9 @@ use crate::expects::Expect;
use crate::util::{
advance_by_deadline_to_epoch, advance_by_deadline_to_epoch_while_proving,
advance_by_deadline_to_index, advance_to_proving_deadline, bf_all, create_accounts,
create_miner, cron_tick, expect_invariants, invariant_failure_patterns, market_add_balance,
market_publish_deal, miner_precommit_sector, miner_prove_sector, sector_deadline,
submit_windowed_post, verifreg_add_client, verifreg_add_verifier,
create_miner, cron_tick, expect_invariants, get_deal, invariant_failure_patterns,
market_add_balance, market_publish_deal, miner_precommit_sector, miner_prove_sector,
sector_deadline, submit_windowed_post, verifreg_add_client, verifreg_add_verifier,
};

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -592,17 +593,26 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) {
.ids;

// replica update
let new_cid = make_sealed_cid(b"replica1");
let new_sealed_cid = make_sealed_cid(b"replica1");
let deal = get_deal(v, deal_ids[0]);
let new_unsealed_cid = v
.primitives()
.compute_unsealed_sector_cid(
seal_proof,
&[PieceInfo { size: deal.piece_size, cid: deal.piece_cid }],
)
.unwrap();

let (d_idx, p_idx) = sector_deadline(v, &miner_id, sector_number);
let replica_update = ReplicaUpdate2 {
sector_number,
deadline: d_idx,
partition: p_idx,
new_sealed_cid: new_cid,
new_sealed_cid,
deals: deal_ids.clone(),
update_proof_type: fvm_shared::sector::RegisteredUpdateProof::StackedDRG32GiBV1,
replica_proof: vec![],
new_unsealed_cid: make_piece_cid(b"unsealed from itest vm"),
new_unsealed_cid,
};
let updated_sectors: BitField = apply_ok(
v,
Expand Down Expand Up @@ -636,14 +646,6 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) {
method: VerifregMethod::ClaimAllocations as u64,
..Default::default()
},
Expect::market_verify_deals(
miner_id,
vec![SectorDeals {
sector_type: seal_proof,
sector_expiry: initial_sector_info.expiration,
deal_ids: deal_ids.clone(),
}],
),
Expect::reward_this_epoch(miner_id),
Expect::power_current_total(miner_id),
Expect::power_update_pledge(miner_id, None),
Expand Down
87 changes: 52 additions & 35 deletions integration_tests/src/tests/replica_update_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
use fvm_ipld_bitfield::BitField;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
use fvm_shared::bigint::{BigInt, Zero};
use fvm_shared::clock::ChainEpoch;
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::piece::{PaddedPieceSize, PieceInfo};
use fvm_shared::sector::SectorSize;
use fvm_shared::sector::StoragePower;
use fvm_shared::sector::{RegisteredSealProof, SectorNumber};

use fil_actor_cron::Method as CronMethod;
use fil_actor_market::{Method as MarketMethod, SectorDeals};
use fil_actor_market::Method as MarketMethod;
use fil_actor_miner::{
power_for_sector, DisputeWindowedPoStParams, ExpirationExtension, ExtendSectorExpirationParams,
Method as MinerMethod, PowerPair, ProveCommitSectorParams, ProveReplicaUpdatesParams,
Expand All @@ -8,23 +21,11 @@ use fil_actor_miner::{
};
use fil_actor_verifreg::Method as VerifregMethod;
use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::test_utils::{make_piece_cid, make_sealed_cid};
use fil_actors_runtime::test_utils::make_sealed_cid;
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;
use fil_actors_runtime::{
Array, CRON_ACTOR_ADDR, EPOCHS_IN_DAY, STORAGE_MARKET_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
};
use fvm_ipld_bitfield::BitField;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
use fvm_shared::bigint::{BigInt, Zero};
use fvm_shared::clock::ChainEpoch;
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::piece::PaddedPieceSize;
use fvm_shared::sector::SectorSize;
use fvm_shared::sector::StoragePower;
use fvm_shared::sector::{RegisteredSealProof, SectorNumber};
use vm_api::trace::ExpectInvocation;
use vm_api::util::{apply_code, apply_ok, get_state, mutate_state, DynBlockstore};
use vm_api::VM;
Expand All @@ -33,7 +34,7 @@ use crate::expects::Expect;
use crate::util::{
advance_by_deadline_to_epoch, advance_by_deadline_to_index, advance_to_proving_deadline,
assert_invariants, bf_all, check_sector_active, check_sector_faulty, create_accounts,
create_miner, deadline_state, declare_recovery, expect_invariants, get_network_stats,
create_miner, deadline_state, declare_recovery, expect_invariants, get_deal, get_network_stats,
invariant_failure_patterns, make_bitfield, market_publish_deal, miner_balance, miner_power,
precommit_sectors, prove_commit_sectors, sector_info, submit_invalid_post,
submit_windowed_post, verifreg_add_client, verifreg_add_verifier,
Expand Down Expand Up @@ -975,16 +976,24 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) {
);

// replica update
let new_cid = make_sealed_cid(b"replica1");
let new_sealed_cid = make_sealed_cid(b"replica1");
let deal = get_deal(v, deal_ids[0]);
let new_unsealed_cid = v
.primitives()
.compute_unsealed_sector_cid(
seal_proof,
&[PieceInfo { size: deal.piece_size, cid: deal.piece_cid }],
)
.unwrap();
let replica_update = ReplicaUpdate2 {
sector_number,
deadline: d_idx,
partition: p_idx,
new_sealed_cid: new_cid,
new_sealed_cid,
deals: deal_ids.clone(),
update_proof_type: fvm_shared::sector::RegisteredUpdateProof::StackedDRG32GiBV1,
replica_proof: vec![],
new_unsealed_cid: make_piece_cid(b"unsealed from itest vm"),
new_unsealed_cid,
};
let updated_sectors: BitField = apply_ok(
v,
Expand Down Expand Up @@ -1018,14 +1027,6 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) {
method: VerifregMethod::ClaimAllocations as u64,
..Default::default()
},
Expect::market_verify_deals(
maddr,
vec![SectorDeals {
sector_type: seal_proof,
sector_expiry: old_sector_info.expiration,
deal_ids: deal_ids.clone(),
}],
),
Expect::reward_this_epoch(maddr),
Expect::power_current_total(maddr),
Expect::power_update_pledge(maddr, None),
Expand All @@ -1044,7 +1045,7 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) {
assert_eq!(1, new_sector_info.deal_ids.len());
assert_eq!(deal_ids[0], new_sector_info.deal_ids[0]);
assert_eq!(old_sector_info.sealed_cid, new_sector_info.sector_key_cid.unwrap());
assert_eq!(new_cid, new_sector_info.sealed_cid);
assert_eq!(new_sealed_cid, new_sector_info.sealed_cid);
}

pub fn replica_update_verified_deal_max_term_violated_test(v: &dyn VM) {
Expand Down Expand Up @@ -1084,16 +1085,24 @@ pub fn replica_update_verified_deal_max_term_violated_test(v: &dyn VM) {
);

// replica update
let new_cid = make_sealed_cid(b"replica1");
let new_sealed_cid = make_sealed_cid(b"replica1");
let deal = get_deal(v, deal_ids[0]);
let new_unsealed_cid = v
.primitives()
.compute_unsealed_sector_cid(
seal_proof,
&[PieceInfo { size: deal.piece_size, cid: deal.piece_cid }],
)
.unwrap();
let replica_update = ReplicaUpdate2 {
sector_number,
deadline: d_idx,
partition: p_idx,
new_sealed_cid: new_cid,
new_sealed_cid,
deals: deal_ids,
update_proof_type: fvm_shared::sector::RegisteredUpdateProof::StackedDRG32GiBV1,
replica_proof: vec![],
new_unsealed_cid: make_piece_cid(b"unsealed from itest vm"),
new_unsealed_cid,
};
apply_code(
v,
Expand Down Expand Up @@ -1273,13 +1282,13 @@ pub fn create_miner_and_upgrade_sector(
let deal_ids = create_deals(1, v, worker, worker, maddr);

// replica update
let new_cid = make_sealed_cid(b"replica1");
let new_sealed_cid = make_sealed_cid(b"replica1");
let updated_sectors: BitField = if !v2 {
let replica_update = ReplicaUpdate {
sector_number,
deadline: d_idx,
partition: p_idx,
new_sealed_cid: new_cid,
new_sealed_cid,
deals: deal_ids.clone(),
update_proof_type: fvm_shared::sector::RegisteredUpdateProof::StackedDRG32GiBV1,
replica_proof: vec![],
Expand All @@ -1293,15 +1302,23 @@ pub fn create_miner_and_upgrade_sector(
Some(ProveReplicaUpdatesParams { updates: vec![replica_update] }),
)
} else {
let deal = get_deal(v, deal_ids[0]);
let new_unsealed_cid = v
.primitives()
.compute_unsealed_sector_cid(
seal_proof,
&[PieceInfo { size: deal.piece_size, cid: deal.piece_cid }],
)
.unwrap();
let replica_update = ReplicaUpdate2 {
sector_number,
deadline: d_idx,
partition: p_idx,
new_sealed_cid: new_cid,
new_sealed_cid,
deals: deal_ids.clone(),
update_proof_type: fvm_shared::sector::RegisteredUpdateProof::StackedDRG32GiBV1,
replica_proof: vec![],
new_unsealed_cid: make_piece_cid(b"unsealed from itest vm"),
new_unsealed_cid,
};
apply_ok(
v,
Expand All @@ -1321,6 +1338,6 @@ pub fn create_miner_and_upgrade_sector(
assert_eq!(1, new_sector_info.deal_ids.len());
assert_eq!(deal_ids[0], new_sector_info.deal_ids[0]);
assert_eq!(old_sector_info.sealed_cid, new_sector_info.sector_key_cid.unwrap());
assert_eq!(new_cid, new_sector_info.sealed_cid);
assert_eq!(new_sealed_cid, new_sector_info.sealed_cid);
(new_sector_info, worker, maddr, d_idx, p_idx, seal_proof.sector_size().unwrap())
}
58 changes: 34 additions & 24 deletions integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
use std::cmp::min;

use frc46_token::receiver::FRC46TokenReceived;
use frc46_token::receiver::FRC46_TOKEN_TYPE;
use frc46_token::token::types::TransferFromParams;
use frc46_token::token::types::TransferParams;
use fvm_actor_utils::receiver::UniversalReceiverParams;
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::BytesDe;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::signature::Signature;
use fvm_shared::crypto::signature::SignatureType;
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::PaddedPieceSize;
use fvm_shared::randomness::Randomness;
use fvm_shared::sector::PoStProof;
use fvm_shared::sector::RegisteredPoStProof;
use fvm_shared::sector::RegisteredSealProof;
use fvm_shared::sector::SectorNumber;
use fvm_shared::sector::StoragePower;
use num_traits::Zero;

use fil_actor_cron::Method as CronMethod;
use fil_actor_datacap::Method as DataCapMethod;
use fil_actor_market::ClientDealProposal;
Expand Down Expand Up @@ -46,41 +71,18 @@ 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::{DATACAP_TOKEN_ACTOR_ID, VERIFIED_REGISTRY_ACTOR_ID};
use frc46_token::receiver::FRC46TokenReceived;
use frc46_token::receiver::FRC46_TOKEN_TYPE;
use frc46_token::token::types::TransferFromParams;
use frc46_token::token::types::TransferParams;
use fvm_actor_utils::receiver::UniversalReceiverParams;
use fvm_ipld_bitfield::BitField;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::BytesDe;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::signature::Signature;
use fvm_shared::crypto::signature::SignatureType;
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::PaddedPieceSize;
use fvm_shared::randomness::Randomness;
use fvm_shared::sector::PoStProof;
use fvm_shared::sector::RegisteredPoStProof;
use fvm_shared::sector::RegisteredSealProof;
use fvm_shared::sector::SectorNumber;
use fvm_shared::sector::StoragePower;
use num_traits::Zero;
use vm_api::trace::ExpectInvocation;
use vm_api::util::apply_ok;
use vm_api::util::get_state;
use vm_api::util::DynBlockstore;
use vm_api::VM;

use crate::expects::Expect;
use crate::*;

use super::make_bitfield;
use super::miner_dline_info;
use super::sector_deadline;
use crate::expects::Expect;

pub fn cron_tick(v: &dyn VM) {
apply_ok(
Expand Down Expand Up @@ -1175,3 +1177,11 @@ pub fn generate_deal_proposal(
client_collateral: client_collateral.clone(),
}
}

pub fn get_deal(v: &dyn VM, deal_id: DealID) -> DealProposal {
let actor = v.actor(&STORAGE_MARKET_ACTOR_ADDR).unwrap();
let bs = DynBlockstore::wrap(v.blockstore());
let state: fil_actor_market::State =
RawBytes::new(bs.get(&actor.state).unwrap().unwrap()).deserialize().unwrap();
state.get_proposal(&bs, deal_id).unwrap()
}
1 change: 1 addition & 0 deletions test_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fvm_ipld_blockstore = { workspace = true }
fvm_ipld_encoding = { workspace = true }
fvm_ipld_hamt = { workspace = true }
fvm_shared = { workspace = true }
integer-encoding = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true }
vm_api = { workspace = true }
Expand Down
Loading

0 comments on commit b67d97e

Please sign in to comment.