Skip to content

Commit

Permalink
Replace actors cids to builtin.types in mockruntime (#629)
Browse files Browse the repository at this point in the history
Co-authored-by: lyswifter <ly70835@163.com>
  • Loading branch information
lyswifter and lyswifter authored Sep 16, 2022
1 parent ff3d01f commit 18c2291
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 108 deletions.
9 changes: 5 additions & 4 deletions actors/market/tests/activate_deal_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use fil_actor_market::{ActivateDealsParams, Actor as MarketActor, Method};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::test_utils::*;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
Expand All @@ -25,7 +26,7 @@ fn fail_when_caller_is_not_the_provider_of_the_deal() {

let params = ActivateDealsParams { deal_ids: vec![deal_id], sector_expiry };

rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
expect_abort(
ExitCode::USR_FORBIDDEN,
Expand All @@ -39,7 +40,7 @@ fn fail_when_caller_is_not_the_provider_of_the_deal() {
#[test]
fn fail_when_caller_is_not_a_storage_miner_actor() {
let mut rt = setup();
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, PROVIDER_ADDR);

let params = ActivateDealsParams { deal_ids: vec![], sector_expiry: 0 };
Expand All @@ -57,7 +58,7 @@ fn fail_when_deal_has_not_been_published_before() {
let mut rt = setup();
let params = ActivateDealsParams { deal_ids: vec![DealID::from(42u32)], sector_expiry: 0 };

rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
expect_abort(
ExitCode::USR_NOT_FOUND,
Expand All @@ -84,7 +85,7 @@ fn fail_when_deal_has_already_been_activated() {
);
activate_deals(&mut rt, sector_expiry, PROVIDER_ADDR, 0, &[deal_id]);

rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
let params = ActivateDealsParams { deal_ids: vec![deal_id], sector_expiry };
expect_abort(
Expand Down
15 changes: 8 additions & 7 deletions actors/market/tests/compute_data_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use fil_actor_market::{
SectorDataSpec,
};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::test_utils::*;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::error::ExitCode;
Expand Down Expand Up @@ -64,7 +65,7 @@ mod compute_data_commitment {
ExitCode::OK,
);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);

let ret: ComputeDataCommitmentReturn = rt
.call::<MarketActor>(
Expand Down Expand Up @@ -97,7 +98,7 @@ mod compute_data_commitment {
ExitCode::OK,
);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);

let ret: ComputeDataCommitmentReturn = rt
.call::<MarketActor>(
Expand Down Expand Up @@ -171,7 +172,7 @@ mod compute_data_commitment {
ExitCode::OK,
);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);

let ret: ComputeDataCommitmentReturn = rt
.call::<MarketActor>(
Expand Down Expand Up @@ -199,7 +200,7 @@ mod compute_data_commitment {
};
let param = ComputeDataCommitmentParams { inputs: vec![input] };
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
expect_abort(
ExitCode::USR_NOT_FOUND,
rt.call::<MarketActor>(
Expand Down Expand Up @@ -239,7 +240,7 @@ mod compute_data_commitment {
ExitCode::USR_ILLEGAL_ARGUMENT,
);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
expect_abort(
ExitCode::USR_ILLEGAL_ARGUMENT,
rt.call::<MarketActor>(
Expand Down Expand Up @@ -285,7 +286,7 @@ mod compute_data_commitment {
ExitCode::OK,
); // first sector is computed
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
expect_abort(
ExitCode::USR_NOT_FOUND,
rt.call::<MarketActor>(
Expand Down Expand Up @@ -336,7 +337,7 @@ mod compute_data_commitment {
ExitCode::USR_ILLEGAL_ARGUMENT,
);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
expect_abort(
ExitCode::USR_ILLEGAL_ARGUMENT,
rt.call::<MarketActor>(
Expand Down
6 changes: 4 additions & 2 deletions actors/market/tests/cron_tick_timedout_deals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use fil_actor_market::{
};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::test_utils::*;
use fil_actors_runtime::{BURNT_FUNDS_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR};
use fil_actors_runtime::{
BURNT_FUNDS_ACTOR_ADDR, CALLER_TYPES_SIGNABLE, VERIFIED_REGISTRY_ACTOR_ADDR,
};
use fvm_ipld_encoding::RawBytes;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::signature::Signature;
Expand Down Expand Up @@ -85,7 +87,7 @@ fn publishing_timed_out_deal_again_should_work_after_cron_tick_as_it_should_no_l
let client_deal_proposal =
ClientDealProposal { proposal: deal_proposal2.clone(), client_signature: sig };
let params = PublishStorageDealsParams { deals: vec![client_deal_proposal] };
rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);
expect_query_network_info(&mut rt);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR);
Expand Down
22 changes: 11 additions & 11 deletions actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use fil_actor_reward::Method as RewardMethod;
use fil_actor_verifreg::UseBytesParams;
use fil_actors_runtime::{
network::EPOCHS_IN_DAY,
runtime::{Policy, Runtime},
runtime::{builtins::Type, Policy, Runtime},
test_utils::*,
ActorError, SetMultimap, BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR, REWARD_ACTOR_ADDR,
STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
ActorError, SetMultimap, BURNT_FUNDS_ACTOR_ADDR, CALLER_TYPES_SIGNABLE, CRON_ACTOR_ADDR,
REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
VERIFIED_REGISTRY_ACTOR_ADDR,
};
use fvm_ipld_encoding::{to_vec, RawBytes};
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn add_provider_funds(rt: &mut MockRuntime, amount: TokenAmount, addrs: &Min
rt.set_value(amount.clone());
rt.set_address_actor_type(addrs.provider, *MINER_ACTOR_CODE_ID);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, addrs.owner);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());

expect_provider_control_address(rt, addrs.provider, addrs.owner, addrs.worker);

Expand All @@ -179,7 +179,7 @@ pub fn add_participant_funds(rt: &mut MockRuntime, addr: Address, amount: TokenA

rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, addr);

rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());

assert!(rt
.call::<MarketActor>(Method::AddBalance as u64, &RawBytes::serialize(addr).unwrap())
Expand Down Expand Up @@ -279,7 +279,7 @@ pub fn activate_deals_raw(
) -> Result<RawBytes, ActorError> {
rt.set_epoch(current_epoch);
rt.set_caller(*MINER_ACTOR_CODE_ID, provider);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);

let params = ActivateDealsParams { deal_ids: deal_ids.to_vec(), sector_expiry };

Expand Down Expand Up @@ -437,7 +437,7 @@ pub fn publish_deals(
addrs: &MinerAddresses,
publish_deals: &[DealProposal],
) -> Vec<DealID> {
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());

let return_value = GetControlAddressesReturnParams {
owner: addrs.owner,
Expand Down Expand Up @@ -527,7 +527,7 @@ pub fn publish_deals_expect_abort(
proposal: DealProposal,
expected_exit_code: ExitCode,
) {
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(
rt,
miner_addresses.provider,
Expand Down Expand Up @@ -710,7 +710,7 @@ where
rt.set_epoch(current_epoch);
post_setup(&mut rt, &mut deal_proposal);

rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);
expect_query_network_info(&mut rt);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR);
Expand Down Expand Up @@ -929,7 +929,7 @@ pub fn terminate_deals_raw(
deal_ids: &[DealID],
) -> Result<RawBytes, ActorError> {
rt.set_caller(*MINER_ACTOR_CODE_ID, miner_addr);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);

let params = OnMinerSectorsTerminateParams { epoch: rt.epoch, deal_ids: deal_ids.to_vec() };

Expand All @@ -953,7 +953,7 @@ pub fn verify_deals_for_activation<F>(
where
F: Fn(usize) -> Option<Vec<PieceInfo>>,
{
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, provider);

for (i, sd) in sector_deals.iter().enumerate() {
Expand Down
32 changes: 16 additions & 16 deletions actors/market/tests/market_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use fil_actor_market::{
use fil_actor_verifreg::UseBytesParams;
use fil_actors_runtime::cbor::deserialize;
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::runtime::{Policy, Runtime};
use fil_actors_runtime::runtime::{builtins::Type, Policy, Runtime};
use fil_actors_runtime::test_utils::*;
use fil_actors_runtime::{
make_empty_map, ActorError, SetMultimap, BURNT_FUNDS_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
VERIFIED_REGISTRY_ACTOR_ADDR,
make_empty_map, ActorError, SetMultimap, BURNT_FUNDS_ACTOR_ADDR, CALLER_TYPES_SIGNABLE,
SYSTEM_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR,
};
use fvm_ipld_amt::Amt;
use fvm_ipld_encoding::{to_vec, RawBytes};
Expand Down Expand Up @@ -193,7 +193,7 @@ fn adds_to_provider_escrow_funds() {
for tc in &test_cases {
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, *caller_addr);
rt.set_value(TokenAmount::from_atto(tc.delta));
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);

assert_eq!(
Expand Down Expand Up @@ -370,7 +370,7 @@ fn fails_unless_called_by_an_account_actor() {
let mut rt = setup();

rt.set_value(TokenAmount::from_atto(10));
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());

rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
assert_eq!(
Expand Down Expand Up @@ -405,7 +405,7 @@ fn adds_to_non_provider_funds() {
for tc in &test_cases {
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, *caller_addr);
rt.set_value(TokenAmount::from_atto(tc.delta));
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());

assert_eq!(
RawBytes::default(),
Expand Down Expand Up @@ -749,7 +749,7 @@ fn provider_and_client_addresses_are_resolved_before_persisting_state_and_sent_t
// add funds for provider using it's BLS address -> will be resolved and persisted
rt.value_received = deal.provider_collateral.clone();
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, OWNER_ADDR);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, provider_resolved, OWNER_ADDR, WORKER_ADDR);

assert_eq!(
Expand All @@ -766,7 +766,7 @@ fn provider_and_client_addresses_are_resolved_before_persisting_state_and_sent_t

// publish deal using the BLS addresses
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());

expect_provider_control_address(&mut rt, provider_resolved, OWNER_ADDR, WORKER_ADDR);
expect_query_network_info(&mut rt);
Expand Down Expand Up @@ -1291,7 +1291,7 @@ fn cannot_publish_the_same_deal_twice_before_a_cron_tick() {
let params = PublishStorageDealsParams {
deals: vec![ClientDealProposal { proposal: d2.clone(), client_signature: sig }],
};
rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);
expect_query_network_info(&mut rt);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR);
Expand Down Expand Up @@ -1337,7 +1337,7 @@ fn fail_when_current_epoch_greater_than_start_epoch_of_deal() {
end_epoch,
);

rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
rt.set_epoch(start_epoch + 1);
let params = ActivateDealsParams { deal_ids: vec![deal_id], sector_expiry };
Expand All @@ -1364,7 +1364,7 @@ fn fail_when_end_epoch_of_deal_greater_than_sector_expiry() {
end_epoch,
);

rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
let params = ActivateDealsParams { deal_ids: vec![deal_id], sector_expiry: end_epoch - 1 };
expect_abort(
Expand Down Expand Up @@ -1401,7 +1401,7 @@ fn fail_to_activate_all_deals_if_one_deal_fails() {
end_epoch + 1,
);

rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*MINER_ACTOR_CODE_ID, PROVIDER_ADDR);
let params = ActivateDealsParams { deal_ids: vec![deal_id1, deal_id2], sector_expiry };
expect_abort(
Expand Down Expand Up @@ -1659,7 +1659,7 @@ fn insufficient_client_balance_in_a_batch() {
deal1.provider_balance_requirement().add(deal2.provider_balance_requirement());
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, OWNER_ADDR);
rt.set_value(provider_funds);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);

assert_eq!(
Expand Down Expand Up @@ -1691,7 +1691,7 @@ fn insufficient_client_balance_in_a_batch() {
],
};

rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);
expect_query_network_info(&mut rt);

Expand Down Expand Up @@ -1772,7 +1772,7 @@ fn insufficient_provider_balance_in_a_batch() {
// Provider has enough for only the second deal
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, OWNER_ADDR);
rt.set_value(deal2.provider_balance_requirement().clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone());
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);

assert_eq!(
Expand Down Expand Up @@ -1808,7 +1808,7 @@ fn insufficient_provider_balance_in_a_batch() {
],
};

rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]);
rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec());
expect_provider_control_address(&mut rt, PROVIDER_ADDR, OWNER_ADDR, WORKER_ADDR);
expect_query_network_info(&mut rt);

Expand Down
3 changes: 2 additions & 1 deletion actors/market/tests/on_miner_sectors_terminate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::convert::TryInto;

use fil_actor_market::{Actor as MarketActor, Method, OnMinerSectorsTerminateParams};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::test_utils::*;
use fvm_ipld_encoding::RawBytes;
Expand Down Expand Up @@ -298,7 +299,7 @@ fn do_not_terminate_deal_if_end_epoch_is_equal_to_or_less_than_current_epoch() {
#[test]
fn fail_when_caller_is_not_a_storage_miner_actor() {
let mut rt = setup();
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
rt.expect_validate_caller_type(vec![Type::Miner]);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, PROVIDER_ADDR);
let params = OnMinerSectorsTerminateParams { epoch: rt.epoch, deal_ids: vec![] };

Expand Down
Loading

0 comments on commit 18c2291

Please sign in to comment.