Skip to content

Commit

Permalink
itests work 1
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jan 8, 2024
1 parent 2ce92e6 commit 0485317
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 18 deletions.
78 changes: 71 additions & 7 deletions integration_tests/src/expects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cid::Cid;
use frc46_token::receiver::{FRC46TokenReceived, FRC46_TOKEN_TYPE};
use frc46_token::token::types::BurnParams;
use fvm_actor_utils::receiver::UniversalReceiverParams;
Expand All @@ -10,6 +11,8 @@ use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
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 @@ -22,13 +25,9 @@ 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, REWARD_ACTOR_ADDR,
STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, STORAGE_POWER_ACTOR_ID,
VERIFIED_REGISTRY_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ID,
};
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 vm_api::trace::ExpectInvocation;
use vm_api::trace::{EmittedEvent, ExpectInvocation};

/// Static helper functions for creating invocation expectations.
pub struct Expect {}
Expand Down Expand Up @@ -343,4 +342,69 @@ impl Expect {
..Default::default()
}
}
}

pub fn build_verifreg_event(
typ: &str,
id: &u64,
client: &ActorID,
provider: &ActorID,
) -> EmittedEvent {
EmittedEvent {
emitter: VERIFIED_REGISTRY_ACTOR_ID,
event: EventBuilder::new()
.typ(typ)
.field_indexed("id", &id)
.field_indexed("client", &client)
.field_indexed("provider", &provider)
.build()
.unwrap(),
}
}

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(),
}
}

pub fn build_miner_event(
typ: &str,
miner_id: ActorID,
sector_number: SectorNumber,
) -> EmittedEvent {
EmittedEvent {
emitter: miner_id,
event: EventBuilder::new()
.typ(typ)
.field_indexed("sector", &sector_number)
.build()
.unwrap(),
}
}

pub fn build_sector_activation_event(
typ: &str,
miner_id: &ActorID,
sector_number: &SectorNumber,
unsealed_cid: &Cid,
pieces: &Vec<(Cid, PaddedPieceSize)>,
) -> EmittedEvent {
let mut base_event = EventBuilder::new()
.typ(typ)
.field_indexed("sector", &sector_number)
.field_indexed("unsealed-cid", &unsealed_cid);

for piece in pieces {
base_event = base_event
.field_indexed("piece-cid", &piece.0)
.field("piece-size", &BigInt::from(piece.1 .0));
}

EmittedEvent {
emitter: *miner_id,
event: base_event.build().unwrap(),
}
}
}
2 changes: 1 addition & 1 deletion integration_tests/src/tests/verified_claim_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ 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);
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();
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/src/tests/verifreg_remove_datacap_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use vm_api::VM;

use crate::expects::Expect;

use crate::util::{assert_invariants, create_accounts, 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]
Expand Down Expand Up @@ -67,6 +67,8 @@ pub fn remove_datacap_simple_successful_path_test(v: &dyn VM) {
Some(add_verified_client_params.clone()),
);

let verifier_datacap = DataCap::from(0);

ExpectInvocation {
from: verifier1_id,
to: VERIFIED_REGISTRY_ACTOR_ADDR,
Expand All @@ -80,6 +82,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)],
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down
90 changes: 81 additions & 9 deletions integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cmp::min;
use cid::Cid;

use frc46_token::receiver::FRC46TokenReceived;
use frc46_token::receiver::FRC46_TOKEN_TYPE;
Expand Down Expand Up @@ -29,10 +30,7 @@ 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,
Expand All @@ -46,12 +44,12 @@ 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;
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,
Method as VerifregMethod, RemoveExpiredAllocationsParams, VerifierParams, State as VerifregState,
};
use fil_actors_runtime::cbor::deserialize;
use fil_actors_runtime::cbor::serialize;
Expand All @@ -61,7 +59,7 @@ 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;
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;
Expand All @@ -70,7 +68,7 @@ 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 vm_api::trace::ExpectInvocation;
use vm_api::trace::{EmittedEvent, ExpectInvocation};
use vm_api::util::get_state;
use vm_api::util::DynBlockstore;
use vm_api::util::{apply_code, apply_ok, apply_ok_implicit};
Expand Down Expand Up @@ -227,6 +225,7 @@ pub fn precommit_sectors_v2_expect_code(
let mut invocs =
vec![Expect::reward_this_epoch(miner_id), Expect::power_current_total(miner_id)];
let mut param_sectors = Vec::<SectorPreCommitInfo>::new();

let mut j = 0;
while j < batch_size && sector_idx < count {
let sector_number = sector_number_base + sector_idx as u64;
Expand All @@ -251,6 +250,14 @@ pub fn precommit_sectors_v2_expect_code(
sector_idx += 1;
j += 1;
}

let events: Vec<EmittedEvent> = param_sectors
.iter()
.map(|ps| {
Expect::build_miner_event("sector-precommitted", miner_id, ps.sector_number)
})
.collect();

if !sectors_with_deals.is_empty() {
invocs.push(Expect::market_verify_deals(miner_id, sectors_with_deals.clone()));
}
Expand Down Expand Up @@ -285,6 +292,7 @@ pub fn precommit_sectors_v2_expect_code(
.unwrap(),
),
subinvocs: Some(invocs),
events: events,
..Default::default()
};
expect.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -391,6 +399,19 @@ pub fn prove_commit_sectors(
Some(prove_commit_aggregate_params),
);

let st: MarketState = get_state(v, &STORAGE_MARKET_ACTOR_ADDR).unwrap();
let store = DynBlockstore::wrap(v.blockstore());
let events:Vec<EmittedEvent> = 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 {
from: worker_id,
Expand All @@ -403,6 +424,7 @@ pub fn prove_commit_sectors(
Expect::power_update_pledge(miner_id, None),
Expect::burn(miner_id, Some(expected_fee)),
]),
events: events,
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -703,8 +725,20 @@ pub fn submit_invalid_post(
);
}

pub fn verifier_balance_event(verifier: ActorID, data_cap: DataCap) -> EmittedEvent {
EmittedEvent {
emitter: VERIFIED_REGISTRY_ACTOR_ID,
event: EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &verifier)
.field("balance", &data_cap)
.build()
.unwrap(),
}
}

pub fn verifreg_add_verifier(v: &dyn VM, verifier: &Address, data_cap: StoragePower) {
let add_verifier_params = VerifierParams { address: *verifier, allowance: data_cap };
let add_verifier_params = VerifierParams { address: *verifier, allowance: data_cap.clone() };
// root address is msig, send proposal from root key
let proposal = ProposeParams {
to: VERIFIED_REGISTRY_ACTOR_ADDR,
Expand Down Expand Up @@ -735,6 +769,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)],
..Default::default()
}]),
..Default::default()
Expand All @@ -748,6 +783,13 @@ pub fn verifreg_add_client(
client: &Address,
allowance: StoragePower,
) {
let v_st: VerifregState = get_state(v, &VERIFIED_REGISTRY_ACTOR_ADDR).unwrap();
let store = DynBlockstore::wrap(v.blockstore());

let verifier_cap = v_st.get_verifier_cap(&store, verifier).unwrap().unwrap();

let updated_verifier_balance = verifier_cap - allowance.clone();

let verifier_id = v.resolve_id_address(verifier).unwrap().id().unwrap();
let add_client_params =
AddVerifiedClientParams { address: *client, allowance: allowance.clone() };
Expand Down Expand Up @@ -787,6 +829,7 @@ pub fn verifreg_add_client(
)]),
..Default::default()
}]),
events: vec![verifier_balance_event(verifier.id().unwrap(), updated_verifier_balance)],
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -822,7 +865,24 @@ pub fn verifreg_remove_expired_allocations(
client: &Address,
ids: Vec<AllocationID>,
datacap_refund: u64,
expected_expirations: Vec<AllocationID>,
) {
let v_st: VerifregState = get_state(v, &VERIFIED_REGISTRY_ACTOR_ADDR).unwrap();
let store = DynBlockstore::wrap(v.blockstore());
let mut allocs = v_st.load_allocs(&store).unwrap();
let expected_events: Vec<EmittedEvent> = expected_expirations
.iter()
.map(|id| {
let alloc = allocs.get(client.id().unwrap(), *id).unwrap().unwrap();
Expect::build_verifreg_event(
"allocation-removed",
&id,
&client.id().unwrap(),
&alloc.provider,
)
})
.collect();

let caller_id = v.resolve_id_address(caller).unwrap().id().unwrap();
let params =
RemoveExpiredAllocationsParams { client: client.id().unwrap(), allocation_ids: ids };
Expand Down Expand Up @@ -861,6 +921,7 @@ pub fn verifreg_remove_expired_allocations(
)]),
..Default::default()
}]),
events: expected_events,
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down Expand Up @@ -1066,6 +1127,10 @@ pub fn market_publish_deal(
}],
extensions: vec![],
};

let v_st: fil_actor_verifreg::State = get_state(v, &VERIFIED_REGISTRY_ACTOR_ADDR).unwrap();
let alloc_id = v_st.next_allocation_id - 1;

expect_publish_invocs.push(ExpectInvocation {
from: STORAGE_MARKET_ACTOR_ID,
to: DATACAP_TOKEN_ACTOR_ADDR,
Expand Down Expand Up @@ -1101,6 +1166,12 @@ pub fn market_publish_deal(
})
.unwrap(),
),
events: vec![Expect::build_verifreg_event(
"allocation",
&alloc_id,
&deal_client.id().unwrap(),
&miner_id.id().unwrap(),
)],
..Default::default()
}]),
..Default::default()
Expand All @@ -1117,6 +1188,7 @@ 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())],
..Default::default()
}
.matches(v.take_invocations().last().unwrap());
Expand Down

0 comments on commit 0485317

Please sign in to comment.