diff --git a/actors/market/tests/activate_deal_failures.rs b/actors/market/tests/activate_deal_failures.rs index c3e59a779..6ab720455 100644 --- a/actors/market/tests/activate_deal_failures.rs +++ b/actors/market/tests/activate_deal_failures.rs @@ -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; @@ -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, @@ -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 }; @@ -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, @@ -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( diff --git a/actors/market/tests/compute_data_commitment.rs b/actors/market/tests/compute_data_commitment.rs index a310b6c9c..6b431a9b5 100644 --- a/actors/market/tests/compute_data_commitment.rs +++ b/actors/market/tests/compute_data_commitment.rs @@ -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; @@ -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::( @@ -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::( @@ -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::( @@ -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::( @@ -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::( @@ -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::( @@ -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::( diff --git a/actors/market/tests/cron_tick_timedout_deals.rs b/actors/market/tests/cron_tick_timedout_deals.rs index 5da65f6d3..a3922805d 100644 --- a/actors/market/tests/cron_tick_timedout_deals.rs +++ b/actors/market/tests/cron_tick_timedout_deals.rs @@ -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; @@ -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); diff --git a/actors/market/tests/harness.rs b/actors/market/tests/harness.rs index 12afd4957..9e644bc2c 100644 --- a/actors/market/tests/harness.rs +++ b/actors/market/tests/harness.rs @@ -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}; @@ -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); @@ -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::(Method::AddBalance as u64, &RawBytes::serialize(addr).unwrap()) @@ -279,7 +279,7 @@ pub fn activate_deals_raw( ) -> Result { 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 }; @@ -437,7 +437,7 @@ pub fn publish_deals( addrs: &MinerAddresses, publish_deals: &[DealProposal], ) -> Vec { - 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, @@ -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, @@ -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); @@ -929,7 +929,7 @@ pub fn terminate_deals_raw( deal_ids: &[DealID], ) -> Result { 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() }; @@ -953,7 +953,7 @@ pub fn verify_deals_for_activation( where F: Fn(usize) -> Option>, { - 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() { diff --git a/actors/market/tests/market_actor_test.rs b/actors/market/tests/market_actor_test.rs index 3f3a449cd..98cff123b 100644 --- a/actors/market/tests/market_actor_test.rs +++ b/actors/market/tests/market_actor_test.rs @@ -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}; @@ -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!( @@ -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!( @@ -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(), @@ -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!( @@ -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); @@ -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); @@ -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 }; @@ -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( @@ -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( @@ -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!( @@ -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); @@ -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!( @@ -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); diff --git a/actors/market/tests/on_miner_sectors_terminate.rs b/actors/market/tests/on_miner_sectors_terminate.rs index a150711ea..030a36f0a 100644 --- a/actors/market/tests/on_miner_sectors_terminate.rs +++ b/actors/market/tests/on_miner_sectors_terminate.rs @@ -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; @@ -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![] }; diff --git a/actors/market/tests/publish_storage_deals_failures.rs b/actors/market/tests/publish_storage_deals_failures.rs index 85cf85b98..38b4315d0 100644 --- a/actors/market/tests/publish_storage_deals_failures.rs +++ b/actors/market/tests/publish_storage_deals_failures.rs @@ -9,6 +9,7 @@ use fil_actor_market::{ use fil_actors_runtime::network::EPOCHS_IN_DAY; use fil_actors_runtime::runtime::Policy; use fil_actors_runtime::test_utils::*; +use fil_actors_runtime::CALLER_TYPES_SIGNABLE; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; use fvm_shared::bigint::BigInt; @@ -254,7 +255,7 @@ fn fail_when_provider_has_some_funds_but_not_enough_for_a_deal() { deals: vec![ClientDealProposal { proposal: deal1.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); @@ -314,7 +315,7 @@ fn fail_when_deals_have_different_providers() { ], }; - 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); @@ -375,7 +376,7 @@ fn fail_when_caller_is_not_of_signable_type() { }; let w = Address::new_id(1000); rt.set_caller(*MINER_ACTOR_CODE_ID, w); - 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_abort( ExitCode::USR_FORBIDDEN, rt.call::( @@ -391,7 +392,7 @@ fn fail_when_no_deals_in_params() { let mut rt = setup(); let params = PublishStorageDealsParams { deals: vec![] }; rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_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()); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, rt.call::( @@ -416,7 +417,7 @@ fn fail_to_resolve_provider_address() { deals: vec![ClientDealProposal { proposal: deal, client_signature: sig }], }; rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_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()); expect_abort( ExitCode::USR_NOT_FOUND, rt.call::( @@ -439,7 +440,7 @@ fn caller_is_not_the_same_as_the_worker_address_for_miner() { deals: vec![ClientDealProposal { proposal: deal, 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); rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, Address::new_id(999)); expect_abort( @@ -468,7 +469,7 @@ fn fails_if_provider_is_not_a_storage_miner_actor() { deals: vec![ClientDealProposal { proposal: deal, 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()); rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR); expect_abort( ExitCode::USR_ILLEGAL_ARGUMENT, diff --git a/actors/market/tests/verify_deals_for_activation_test.rs b/actors/market/tests/verify_deals_for_activation_test.rs index 2f8d80fd4..425b89eff 100644 --- a/actors/market/tests/verify_deals_for_activation_test.rs +++ b/actors/market/tests/verify_deals_for_activation_test.rs @@ -5,6 +5,7 @@ mod harness; use fil_actor_market::policy::detail::deal_weight; use fil_actor_market::{Actor as MarketActor, Method, SectorDeals, VerifyDealsForActivationParams}; +use fil_actors_runtime::runtime::builtins::Type; use fil_actors_runtime::test_utils::{ expect_abort, expect_abort_contains_message, make_piece_cid, ACCOUNT_ACTOR_CODE_ID, MINER_ACTOR_CODE_ID, @@ -156,7 +157,7 @@ fn fail_when_caller_is_not_a_storage_miner_actor() { generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, WORKER_ADDR); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); let params = VerifyDealsForActivationParams { sectors: vec![SectorDeals { @@ -189,7 +190,7 @@ fn fail_when_deal_proposal_is_not_found() { }], }; 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::( @@ -209,7 +210,7 @@ fn fail_when_caller_is_not_the_provider() { generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); rt.set_caller(*MINER_ACTOR_CODE_ID, Address::new_id(205)); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); let params = VerifyDealsForActivationParams { sectors: vec![SectorDeals { @@ -238,7 +239,7 @@ fn fail_when_current_epoch_is_greater_than_proposal_start_epoch() { rt.set_epoch(START_EPOCH + 1); 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 params = VerifyDealsForActivationParams { sectors: vec![SectorDeals { @@ -266,7 +267,7 @@ fn fail_when_deal_end_epoch_is_greater_than_sector_expiration() { generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); 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 params = VerifyDealsForActivationParams { sectors: vec![SectorDeals { @@ -294,7 +295,7 @@ fn fail_when_the_same_deal_id_is_passed_multiple_times() { generate_and_publish_deal(&mut rt, CLIENT_ADDR, &MINER_ADDRESSES, START_EPOCH, END_EPOCH); 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 params = VerifyDealsForActivationParams { sectors: vec![SectorDeals { diff --git a/actors/miner/tests/miner_actor_test_wpost.rs b/actors/miner/tests/miner_actor_test_wpost.rs index b3f03142b..6817181d4 100644 --- a/actors/miner/tests/miner_actor_test_wpost.rs +++ b/actors/miner/tests/miner_actor_test_wpost.rs @@ -4,6 +4,7 @@ use fil_actor_miner as miner; use fil_actor_miner::PowerPair; use fil_actors_runtime::runtime::DomainSeparationTag; use fil_actors_runtime::test_utils::*; +use fil_actors_runtime::CALLER_TYPES_SIGNABLE; use fvm_ipld_bitfield::BitField; use fvm_ipld_encoding::RawBytes; use fvm_shared::clock::ChainEpoch; @@ -1030,7 +1031,7 @@ fn cannot_dispute_posts_when_the_challenge_window_is_open() { let params = miner::DisputeWindowedPoStParams { deadline: dlinfo.index, post_index: 0 }; rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, h.worker); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); h.expect_query_network_info(&mut rt); let result = rt.call::( @@ -1091,7 +1092,7 @@ fn can_dispute_up_till_window_end_but_not_after() { // Now try to dispute. let params = miner::DisputeWindowedPoStParams { deadline: dlidx, post_index: 0 }; rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, h.worker); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); h.expect_query_network_info(&mut rt); @@ -1124,7 +1125,7 @@ fn cant_dispute_up_with_an_invalid_deadline() { let params = miner::DisputeWindowedPoStParams { deadline: 50, post_index: 0 }; rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, h.worker); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let result = rt.call::( miner::Method::DisputeWindowedPoSt as u64, diff --git a/actors/miner/tests/util.rs b/actors/miner/tests/util.rs index 063c9462a..d4e3151ba 100644 --- a/actors/miner/tests/util.rs +++ b/actors/miner/tests/util.rs @@ -36,7 +36,8 @@ use fil_actors_runtime::runtime::{DomainSeparationTag, Policy, Runtime, RuntimeP use fil_actors_runtime::test_utils::*; use fil_actors_runtime::{ ActorDowncast, ActorError, Array, DealWeight, MessageAccumulator, BURNT_FUNDS_ACTOR_ADDR, - INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, + CALLER_TYPES_SIGNABLE, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, + STORAGE_POWER_ACTOR_ADDR, }; use fvm_ipld_amt::Amt; use fvm_shared::bigint::Zero; @@ -1246,7 +1247,7 @@ impl ActorHarness { expect_success: Option, ) { rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, self.worker); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); self.expect_query_network_info(rt); @@ -1686,7 +1687,7 @@ impl ActorHarness { from: Address, fault: Option, ) -> Result<(), ActorError> { - rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).clone()); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, from); let params = ReportConsensusFaultParams { header1: vec![], header2: vec![], header_extra: vec![] }; diff --git a/actors/multisig/src/lib.rs b/actors/multisig/src/lib.rs index e3d481719..9851322e4 100644 --- a/actors/multisig/src/lib.rs +++ b/actors/multisig/src/lib.rs @@ -4,10 +4,10 @@ use std::collections::BTreeSet; use fil_actors_runtime::cbor::serialize_vec; -use fil_actors_runtime::runtime::{ActorCode, Primitives, Runtime}; +use fil_actors_runtime::runtime::{builtins::Type, ActorCode, Primitives, Runtime}; use fil_actors_runtime::{ actor_error, cbor, make_empty_map, make_map_with_root, resolve_to_actor_id, ActorContext, - ActorError, AsActorError, Map, CALLER_TYPES_SIGNABLE, INIT_ACTOR_ADDR, + ActorError, AsActorError, Map, INIT_ACTOR_ADDR, }; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::RawBytes; @@ -126,7 +126,7 @@ impl Actor { BS: Blockstore, RT: Runtime, { - rt.validate_immediate_caller_type(CALLER_TYPES_SIGNABLE.iter())?; + rt.validate_immediate_caller_type(&[Type::Account, Type::Multisig])?; let proposer: Address = rt.message().caller(); if params.value.is_negative() { @@ -180,7 +180,7 @@ impl Actor { BS: Blockstore, RT: Runtime, { - rt.validate_immediate_caller_type(CALLER_TYPES_SIGNABLE.iter())?; + rt.validate_immediate_caller_type(&[Type::Account, Type::Multisig])?; let approver: Address = rt.message().caller(); let id = params.id; @@ -216,7 +216,7 @@ impl Actor { BS: Blockstore, RT: Runtime, { - rt.validate_immediate_caller_type(CALLER_TYPES_SIGNABLE.iter())?; + rt.validate_immediate_caller_type(&[Type::Account, Type::Multisig])?; let caller_addr: Address = rt.message().caller(); rt.transaction(|st: &mut State, rt| { diff --git a/actors/multisig/tests/multisig_actor_test.rs b/actors/multisig/tests/multisig_actor_test.rs index 523ecce01..2c1adb30f 100644 --- a/actors/multisig/tests/multisig_actor_test.rs +++ b/actors/multisig/tests/multisig_actor_test.rs @@ -6,7 +6,7 @@ use fil_actor_multisig::{ use fil_actors_runtime::cbor::serialize; use fil_actors_runtime::runtime::Runtime; use fil_actors_runtime::test_utils::*; -use fil_actors_runtime::{INIT_ACTOR_ADDR, SYSTEM_ACTOR_ADDR}; +use fil_actors_runtime::{CALLER_TYPES_SIGNABLE, INIT_ACTOR_ADDR, SYSTEM_ACTOR_ADDR}; use fvm_ipld_encoding::tuple::*; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::{Address, BLS_PUB_LEN}; @@ -1550,7 +1550,7 @@ mod approval_tests { RawBytes::default(), ExitCode::OK, ); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let params = TxnIDParams { id: TxnID(0), proposal_hash: Vec::::new() }; rt.call::(Method::Approve as u64, &RawBytes::serialize(params).unwrap()) .unwrap(); @@ -1612,7 +1612,7 @@ mod approval_tests { h.construct_and_verify(&mut rt, 1, 0, 0, signers); rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, bob); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let params = TxnIDParams { id: dne_tx_id, proposal_hash: Vec::::new() }; rt.call::(Method::Approve as u64, &RawBytes::serialize(params).unwrap()) .expect_err("should fail on approve of non existent tx id"); diff --git a/actors/multisig/tests/util.rs b/actors/multisig/tests/util.rs index 1ff3bba74..fdb96a94f 100644 --- a/actors/multisig/tests/util.rs +++ b/actors/multisig/tests/util.rs @@ -5,8 +5,8 @@ use fil_actor_multisig::{ }; use fil_actor_multisig::{ChangeNumApprovalsThresholdParams, LockBalanceParams}; use fil_actors_runtime::test_utils::*; -use fil_actors_runtime::INIT_ACTOR_ADDR; use fil_actors_runtime::{make_map_with_root, ActorError}; +use fil_actors_runtime::{CALLER_TYPES_SIGNABLE, INIT_ACTOR_ADDR}; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; use fvm_shared::clock::ChainEpoch; @@ -125,7 +125,7 @@ impl ActorHarness { method: MethodNum, params: RawBytes, ) -> Result { - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let propose_params = ProposeParams { to, value, method, params }; let ret = rt.call::(Method::Propose as u64, &RawBytes::serialize(propose_params).unwrap()); @@ -139,7 +139,7 @@ impl ActorHarness { txn_id: TxnID, proposal_hash: [u8; 32], ) -> Result { - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let approve_params = TxnIDParams { id: txn_id, proposal_hash: Vec::::from(proposal_hash) }; let ret = @@ -154,7 +154,7 @@ impl ActorHarness { txn_id: TxnID, proposal_hash: [u8; 32], ) -> Result { - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let cancel_params = TxnIDParams { id: txn_id, proposal_hash: Vec::::from(proposal_hash) }; let ret = diff --git a/actors/paych/tests/paych_actor_test.rs b/actors/paych/tests/paych_actor_test.rs index c36cf1c62..f250fe277 100644 --- a/actors/paych/tests/paych_actor_test.rs +++ b/actors/paych/tests/paych_actor_test.rs @@ -12,6 +12,7 @@ use fil_actor_paych::{ Actor as PaychActor, ConstructorParams, LaneState, Merge, Method, ModVerifyParams, SignedVoucher, State as PState, UpdateChannelStateParams, MAX_LANE, SETTLE_DELAY, }; +use fil_actors_runtime::runtime::builtins::Type; use fil_actors_runtime::runtime::Runtime; use fil_actors_runtime::test_utils::*; use fil_actors_runtime::INIT_ACTOR_ADDR; @@ -67,6 +68,7 @@ fn check_state(rt: &MockRuntime) { } mod paych_constructor { + use fil_actors_runtime::runtime::builtins::Type; use fvm_shared::METHOD_CONSTRUCTOR; use fvm_shared::METHOD_SEND; use num_traits::Zero; @@ -106,7 +108,7 @@ mod paych_constructor { #[test] fn actor_doesnt_exist_test() { let mut rt = construct_runtime(); - rt.expect_validate_caller_type(vec![*INIT_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Init]); let params = ConstructorParams { to: Address::new_id(TEST_PAYCH_ADDR), from: Address::new_id(TEST_PAYER_ADDR), @@ -185,7 +187,7 @@ mod paych_constructor { ..Default::default() }; - rt.expect_validate_caller_type(vec![*INIT_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Init]); let params = ConstructorParams { to: test_case.to_addr, from: test_case.from_addr }; expect_abort( &mut rt, @@ -224,7 +226,7 @@ mod paych_constructor { ExitCode::OK, ); - rt.expect_validate_caller_type(vec![*INIT_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Init]); let params = ConstructorParams { from: non_id_addr, to: to_addr }; expect_abort( &mut rt, @@ -261,7 +263,7 @@ mod paych_constructor { ExitCode::OK, ); - rt.expect_validate_caller_type(vec![*INIT_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Init]); let params = ConstructorParams { from: from_addr, to: non_id_addr }; expect_abort( &mut rt, @@ -1199,7 +1201,7 @@ fn require_add_new_lane(rt: &mut MockRuntime, param: LaneParams) -> SignedVouche fn construct_and_verify(rt: &mut MockRuntime, sender: Address, receiver: Address) { let params = ConstructorParams { from: sender, to: receiver }; - rt.expect_validate_caller_type(vec![*INIT_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Init]); call(rt, METHOD_CONSTRUCTOR, &RawBytes::serialize(¶ms).unwrap()); rt.verify(); let sender_id = rt.id_addresses.get(&sender).unwrap_or(&sender); diff --git a/actors/power/src/lib.rs b/actors/power/src/lib.rs index 4b6c4b5b2..93f022613 100644 --- a/actors/power/src/lib.rs +++ b/actors/power/src/lib.rs @@ -10,7 +10,7 @@ use fil_actors_runtime::runtime::builtins::Type; use fil_actors_runtime::runtime::{ActorCode, Runtime}; use fil_actors_runtime::{ actor_error, cbor, make_map_with_root_and_bitwidth, ActorDowncast, ActorError, Multimap, - CALLER_TYPES_SIGNABLE, CRON_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, SYSTEM_ACTOR_ADDR, + CRON_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, SYSTEM_ACTOR_ADDR, }; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::RawBytes; @@ -92,7 +92,7 @@ impl Actor { BS: Blockstore, RT: Runtime, { - rt.validate_immediate_caller_type(CALLER_TYPES_SIGNABLE.iter())?; + rt.validate_immediate_caller_type(&[Type::Account, Type::Multisig])?; let value = rt.message().value_received(); let constructor_params = RawBytes::serialize(ext::miner::MinerConstructorParams { diff --git a/actors/power/tests/harness/mod.rs b/actors/power/tests/harness/mod.rs index 5a6ad643d..c168403bc 100644 --- a/actors/power/tests/harness/mod.rs +++ b/actors/power/tests/harness/mod.rs @@ -13,6 +13,7 @@ use fil_actor_power::CRON_QUEUE_HAMT_BITWIDTH; use fil_actors_runtime::runtime::RuntimePolicy; use fil_actors_runtime::test_utils::CRON_ACTOR_CODE_ID; use fil_actors_runtime::Multimap; +use fil_actors_runtime::CALLER_TYPES_SIGNABLE; use fil_actors_runtime::CRON_ACTOR_ADDR; use fil_actors_runtime::REWARD_ACTOR_ADDR; use fvm_ipld_blockstore::Blockstore; @@ -44,10 +45,10 @@ use fil_actor_power::{ UpdateClaimedPowerParams, }; use fil_actors_runtime::builtin::HAMT_BIT_WIDTH; +use fil_actors_runtime::runtime::builtins::Type; use fil_actors_runtime::runtime::Runtime; use fil_actors_runtime::test_utils::{ - MockRuntime, ACCOUNT_ACTOR_CODE_ID, MINER_ACTOR_CODE_ID, MULTISIG_ACTOR_CODE_ID, - SYSTEM_ACTOR_CODE_ID, + MockRuntime, ACCOUNT_ACTOR_CODE_ID, MINER_ACTOR_CODE_ID, SYSTEM_ACTOR_CODE_ID, }; use fil_actors_runtime::{ make_map_with_root_and_bitwidth, ActorError, Map, INIT_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, @@ -140,7 +141,7 @@ impl Harness { rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, *owner); rt.set_value(value.clone()); rt.set_balance(value.clone()); - rt.expect_validate_caller_type(vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let miner_ctor_params = MinerConstructorParams { owner: *owner, @@ -245,7 +246,7 @@ impl Harness { payload: &RawBytes, ) -> Result<(), ActorError> { rt.set_caller(*MINER_ACTOR_CODE_ID, miner_address.to_owned()); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); let params = RawBytes::serialize(EnrollCronEventParams { event_epoch: epoch, payload: payload.clone(), @@ -287,7 +288,7 @@ impl Harness { let prev = st.total_pledge_collateral; rt.set_caller(*MINER_ACTOR_CODE_ID, miner); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); rt.call::( Method::UpdatePledgeTotal as MethodNum, &RawBytes::serialize(delta).unwrap(), @@ -324,7 +325,7 @@ impl Harness { quality_adjusted_delta: qa_delta.clone(), }; rt.set_caller(*MINER_ACTOR_CODE_ID, miner); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); rt.call::( Method::UpdateClaimedPower as MethodNum, &RawBytes::serialize(params).unwrap(), @@ -448,7 +449,7 @@ impl Harness { seal_info: SealVerifyInfo, ) -> Result<(), ActorError> { rt.expect_gas_charge(GAS_ON_SUBMIT_VERIFY_SEAL); - 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, miner_address); rt.call::( Method::SubmitPoRepForBulkVerify as u64, diff --git a/actors/power/tests/power_actor_tests.rs b/actors/power/tests/power_actor_tests.rs index c090725bc..5be4416bd 100644 --- a/actors/power/tests/power_actor_tests.rs +++ b/actors/power/tests/power_actor_tests.rs @@ -1,10 +1,11 @@ use fil_actor_power::ext::init::{ExecParams, EXEC_METHOD}; use fil_actor_power::ext::miner::MinerConstructorParams; +use fil_actors_runtime::runtime::builtins::Type; use fil_actors_runtime::test_utils::{ - expect_abort, expect_abort_contains_message, ACCOUNT_ACTOR_CODE_ID, CALLER_TYPES_SIGNABLE, - MINER_ACTOR_CODE_ID, SYSTEM_ACTOR_CODE_ID, + expect_abort, expect_abort_contains_message, ACCOUNT_ACTOR_CODE_ID, MINER_ACTOR_CODE_ID, + SYSTEM_ACTOR_CODE_ID, }; -use fil_actors_runtime::{runtime::Policy, INIT_ACTOR_ADDR}; +use fil_actors_runtime::{runtime::Policy, CALLER_TYPES_SIGNABLE, INIT_ACTOR_ADDR}; use fvm_ipld_encoding::{BytesDe, RawBytes}; use fvm_shared::address::Address; use fvm_shared::bigint::bigint_ser::BigIntSer; @@ -90,7 +91,7 @@ fn create_miner_given_caller_is_not_of_signable_type_should_fail() { }; rt.set_caller(*MINER_ACTOR_CODE_ID, *OWNER); - rt.expect_validate_caller_type(CALLER_TYPES_SIGNABLE.to_vec()); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); expect_abort( ExitCode::USR_FORBIDDEN, rt.call::( @@ -121,7 +122,7 @@ fn create_miner_given_send_to_init_actor_fails_should_fail() { rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, *OWNER); rt.value_received = TokenAmount::from_atto(10); rt.set_balance(TokenAmount::from_atto(10)); - rt.expect_validate_caller_type(CALLER_TYPES_SIGNABLE.to_vec()); + rt.expect_validate_caller_type((*CALLER_TYPES_SIGNABLE).to_vec()); let message_params = ExecParams { code_cid: *MINER_ACTOR_CODE_ID, @@ -166,7 +167,7 @@ fn claimed_power_given_caller_is_not_storage_miner_should_fail() { }; rt.set_caller(*SYSTEM_ACTOR_CODE_ID, *MINER); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); expect_abort( ExitCode::USR_FORBIDDEN, @@ -190,7 +191,7 @@ fn claimed_power_given_claim_does_not_exist_should_fail() { }; rt.set_caller(*MINER_ACTOR_CODE_ID, *MINER); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); expect_abort( ExitCode::USR_NOT_FOUND, @@ -447,7 +448,7 @@ fn enroll_cron_epoch_given_negative_epoch_should_fail() { let (h, mut rt) = setup(); rt.set_caller(*MINER_ACTOR_CODE_ID, *MINER); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); let params = EnrollCronEventParams { event_epoch: -1, @@ -598,7 +599,7 @@ fn given_no_miner_claim_update_pledge_total_should_abort() { h.delete_claim(&mut rt, &*MINER); rt.set_caller(*MINER_ACTOR_CODE_ID, *MINER); - rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]); + rt.expect_validate_caller_type(vec![Type::Miner]); expect_abort_contains_message( ExitCode::USR_FORBIDDEN, "unknown miner", diff --git a/runtime/src/test_utils.rs b/runtime/src/test_utils.rs index cca3916ce..ab96c13d3 100644 --- a/runtime/src/test_utils.rs +++ b/runtime/src/test_utils.rs @@ -83,8 +83,6 @@ lazy_static::lazy_static! { ] .into_iter() .collect(); - pub static ref CALLER_TYPES_SIGNABLE: Vec = - vec![*ACCOUNT_ACTOR_CODE_ID, *MULTISIG_ACTOR_CODE_ID]; pub static ref NON_SINGLETON_CODES: BTreeMap = { let mut map = BTreeMap::new(); map.insert(*ACCOUNT_ACTOR_CODE_ID, ()); @@ -139,7 +137,7 @@ pub struct MockRuntime { pub struct Expectations { pub expect_validate_caller_any: bool, pub expect_validate_caller_addr: Option>, - pub expect_validate_caller_type: Option>, + pub expect_validate_caller_type: Option>, pub expect_sends: VecDeque, pub expect_create_actor: Option, pub expect_delete_actor: Option
, @@ -511,7 +509,7 @@ impl MockRuntime { } #[allow(dead_code)] - pub fn expect_validate_caller_type(&mut self, types: Vec) { + pub fn expect_validate_caller_type(&mut self, types: Vec) { assert!(!types.is_empty(), "addrs must be non-empty"); self.expectations.borrow_mut().expect_validate_caller_type = Some(types); } @@ -734,14 +732,7 @@ impl Runtime> for MockRuntime { "unexpected validate caller code" ); - let find_by_type = |typ| { - (*ACTOR_TYPES) - .iter() - .find_map(|(cid, t)| if t == typ { Some(cid) } else { None }) - .cloned() - .unwrap() - }; - let types: Vec = types.into_iter().map(find_by_type).collect(); + let types: Vec = types.into_iter().copied().collect(); let expected_caller_type = self.expectations.borrow_mut().expect_validate_caller_type.clone().unwrap(); assert_eq!( @@ -750,8 +741,9 @@ impl Runtime> for MockRuntime { types, expected_caller_type, ); + let call_type = self.resolve_builtin_actor_type(&self.caller_type).unwrap(); for expected in &types { - if &self.caller_type == expected { + if &call_type == expected { self.expectations.borrow_mut().expect_validate_caller_type = None; return Ok(()); }