Skip to content

Commit

Permalink
feat: use consts for addrs
Browse files Browse the repository at this point in the history
And expose actor IDs so we don't need to call `.id().unwrap()` to
retrieve them.
  • Loading branch information
Stebalien committed Sep 15, 2022
1 parent fe531cb commit af836ea
Show file tree
Hide file tree
Showing 44 changed files with 390 additions and 381 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion actors/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
match address.protocol() {
Protocol::Secp256k1 | Protocol::BLS => {}
protocol => {
Expand Down
6 changes: 3 additions & 3 deletions actors/account/tests/account_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ macro_rules! account_constructor_tests {
caller_type: SYSTEM_ACTOR_CODE_ID.clone(),
..Default::default()
};
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);

if exit_code.is_success() {
rt.call::<AccountActor>(1, &RawBytes::serialize(addr).unwrap()).unwrap();
Expand Down Expand Up @@ -82,13 +82,13 @@ account_constructor_tests! {
fn authenticate_message() {
let mut rt = MockRuntime {
receiver: Address::new_id(100),
caller: *SYSTEM_ACTOR_ADDR,
caller: SYSTEM_ACTOR_ADDR,
caller_type: *SYSTEM_ACTOR_CODE_ID,
..Default::default()
};

let addr = Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap();
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);

rt.call::<AccountActor>(1, &RawBytes::serialize(addr).unwrap()).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
rt.create(&State { entries: params.entries })?;
Ok(())
}
Expand All @@ -59,7 +59,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;

let st: State = rt.state()?;
for entry in st.entries {
Expand Down
6 changes: 3 additions & 3 deletions actors/cron/tests/cron_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn check_state(rt: &MockRuntime) {
fn construct_runtime() -> MockRuntime {
MockRuntime {
receiver: Address::new_id(100),
caller: *SYSTEM_ACTOR_ADDR,
caller: SYSTEM_ACTOR_ADDR,
caller_type: *SYSTEM_ACTOR_CODE_ID,
..Default::default()
}
Expand Down Expand Up @@ -114,14 +114,14 @@ fn epoch_tick_with_entries() {
}

fn construct_and_verify(rt: &mut MockRuntime, params: &ConstructorParams) {
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
let ret = rt.call::<CronActor>(1, &RawBytes::serialize(&params).unwrap()).unwrap();
assert_eq!(RawBytes::default(), ret);
rt.verify();
}

fn epoch_tick_and_verify(rt: &mut MockRuntime) {
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
let ret = rt.call::<CronActor>(2, &RawBytes::default()).unwrap();
assert_eq!(RawBytes::default(), ret);
rt.verify();
Expand Down
8 changes: 4 additions & 4 deletions actors/init/tests/init_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn check_state(rt: &MockRuntime) {
fn construct_runtime() -> MockRuntime {
MockRuntime {
receiver: Address::new_id(1000),
caller: *SYSTEM_ACTOR_ADDR,
caller: SYSTEM_ACTOR_ADDR,
caller_type: *SYSTEM_ACTOR_CODE_ID,
..Default::default()
}
Expand Down Expand Up @@ -163,7 +163,7 @@ fn create_storage_miner() {
construct_and_verify(&mut rt);

// only the storage power actor can create a miner
rt.set_caller(*POWER_ACTOR_CODE_ID, *STORAGE_POWER_ACTOR_ADDR);
rt.set_caller(*POWER_ACTOR_CODE_ID, STORAGE_POWER_ACTOR_ADDR);

let unique_address = Address::new_actor(b"miner");
rt.new_actor_addr = Some(unique_address);
Expand Down Expand Up @@ -248,7 +248,7 @@ fn sending_constructor_failure() {
construct_and_verify(&mut rt);

// Only the storage power actor can create a miner
rt.set_caller(*POWER_ACTOR_CODE_ID, *STORAGE_POWER_ACTOR_ADDR);
rt.set_caller(*POWER_ACTOR_CODE_ID, STORAGE_POWER_ACTOR_ADDR);

// Assign new address for the storage actor miner
let unique_address = Address::new_actor(b"miner");
Expand Down Expand Up @@ -288,7 +288,7 @@ fn sending_constructor_failure() {
}

fn construct_and_verify(rt: &mut MockRuntime) {
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
let params = ConstructorParams { network_name: "mock".to_string() };
let ret =
rt.call::<InitActor>(METHOD_CONSTRUCTOR, &RawBytes::serialize(&params).unwrap()).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;

let st = State::new(rt.store()).map_err(|e| {
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "Failed to create market state")
Expand Down Expand Up @@ -766,7 +766,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*CRON_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&CRON_ACTOR_ADDR))?;

let mut amount_slashed = TokenAmount::zero();
let curr_epoch = rt.curr_epoch();
Expand Down
2 changes: 1 addition & 1 deletion actors/market/tests/cron_tick_deal_slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn slash_multiple_deals_in_the_same_epoch() {
+ &deal_proposal2.provider_collateral
+ &deal_proposal3.provider_collateral;
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
total_slashed,
Expand Down
10 changes: 5 additions & 5 deletions actors/market/tests/cron_tick_timedout_deals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn timed_out_deal_is_slashed_and_deleted() {
// do a cron tick for it -> should time out and get slashed
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
deal_proposal.provider_collateral.clone(),
Expand Down Expand Up @@ -116,7 +116,7 @@ fn publishing_timed_out_deal_again_should_work_after_cron_tick_as_it_should_no_l
// do a cron tick for it -> should time out and get slashed
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
deal_proposal.provider_collateral.clone(),
Expand Down Expand Up @@ -189,15 +189,15 @@ fn timed_out_and_verified_deals_are_slashed_deleted_and_sent_to_the_registry_act
};

rt.expect_send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
VERIFIED_REGISTRY_ACTOR_ADDR,
ext::verifreg::RESTORE_BYTES_METHOD as u64,
RawBytes::serialize(param1).unwrap(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
rt.expect_send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
VERIFIED_REGISTRY_ACTOR_ADDR,
ext::verifreg::RESTORE_BYTES_METHOD as u64,
RawBytes::serialize(param2).unwrap(),
TokenAmount::zero(),
Expand All @@ -207,7 +207,7 @@ fn timed_out_and_verified_deals_are_slashed_deleted_and_sent_to_the_registry_act

let expected_burn = 3 * &deal1.provider_collateral;
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
expected_burn,
Expand Down
18 changes: 9 additions & 9 deletions actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub fn setup() -> MockRuntime {
]);

let mut rt = MockRuntime {
receiver: *STORAGE_MARKET_ACTOR_ADDR,
caller: *SYSTEM_ACTOR_ADDR,
receiver: STORAGE_MARKET_ACTOR_ADDR,
caller: SYSTEM_ACTOR_ADDR,
caller_type: *INIT_ACTOR_CODE_ID,
actor_code_cids,
balance: RefCell::new(TokenAmount::from_whole(10)),
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn check_state_with_expected(rt: &MockRuntime, expected_patterns: &[Regex])
}

pub fn construct_and_verify(rt: &mut MockRuntime) {
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
assert_eq!(
RawBytes::default(),
rt.call::<MarketActor>(METHOD_CONSTRUCTOR, &RawBytes::default()).unwrap()
Expand Down Expand Up @@ -365,7 +365,7 @@ pub fn cron_tick_and_assert_balances(
let mut payment_end = d.end_epoch;
if s.slash_epoch != EPOCH_UNDEFINED {
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
d.provider_collateral.clone(),
Expand Down Expand Up @@ -488,7 +488,7 @@ pub fn publish_deals(
.unwrap();

rt.expect_send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
VERIFIED_REGISTRY_ACTOR_ADDR,
ext::verifreg::USE_BYTES_METHOD as u64,
param,
TokenAmount::zero(),
Expand Down Expand Up @@ -587,8 +587,8 @@ pub fn cron_tick(rt: &mut MockRuntime) {
}

pub fn cron_tick_raw(rt: &mut MockRuntime) -> Result<RawBytes, ActorError> {
rt.expect_validate_caller_addr(vec![*CRON_ACTOR_ADDR]);
rt.set_caller(*CRON_ACTOR_CODE_ID, *CRON_ACTOR_ADDR);
rt.expect_validate_caller_addr(vec![CRON_ACTOR_ADDR]);
rt.set_caller(*CRON_ACTOR_CODE_ID, CRON_ACTOR_ADDR);

rt.call::<MarketActor>(Method::CronTick as u64, &RawBytes::default())
}
Expand All @@ -611,15 +611,15 @@ pub fn expect_query_network_info(rt: &mut MockRuntime) {
this_epoch_reward_smoothed: epoch_reward_smooth,
};
rt.expect_send(
*REWARD_ACTOR_ADDR,
REWARD_ACTOR_ADDR,
RewardMethod::ThisEpochReward as u64,
RawBytes::default(),
TokenAmount::zero(),
RawBytes::serialize(current_reward).unwrap(),
ExitCode::OK,
);
rt.expect_send(
*STORAGE_POWER_ACTOR_ADDR,
STORAGE_POWER_ACTOR_ADDR,
PowerMethod::CurrentTotalPower as u64,
RawBytes::default(),
TokenAmount::zero(),
Expand Down
12 changes: 6 additions & 6 deletions actors/market/tests/market_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ fn test_remove_all_error() {
fn simple_construction() {
let mut rt = MockRuntime {
receiver: Address::new_id(100),
caller: *SYSTEM_ACTOR_ADDR,
caller: SYSTEM_ACTOR_ADDR,
caller_type: *INIT_ACTOR_CODE_ID,
..Default::default()
};

rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);

assert_eq!(
RawBytes::default(),
Expand Down Expand Up @@ -802,7 +802,7 @@ fn provider_and_client_addresses_are_resolved_before_persisting_state_and_sent_t
.unwrap();

rt.expect_send(
*VERIFIED_REGISTRY_ACTOR_ADDR,
VERIFIED_REGISTRY_ACTOR_ADDR,
ext::verifreg::USE_BYTES_METHOD as u64,
param,
TokenAmount::zero(),
Expand Down Expand Up @@ -1248,7 +1248,7 @@ fn slash_a_deal_and_make_payment_for_another_deal_in_the_same_epoch() {

// cron tick will slash deal1 and make payment for deal2
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
d1.provider_collateral.clone(),
Expand Down Expand Up @@ -1491,7 +1491,7 @@ fn locked_fund_tracking_states() {
let curr = process_epoch(start_epoch, deal_id3);
rt.set_epoch(curr);
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
d3.provider_collateral.clone(),
Expand Down Expand Up @@ -1532,7 +1532,7 @@ fn locked_fund_tracking_states() {
clc = TokenAmount::zero();
plc = TokenAmount::zero();
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
d1.provider_collateral,
Expand Down
2 changes: 1 addition & 1 deletion actors/market/tests/random_cron_epoch_during_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn cron_processing_of_deal_after_missed_activation_should_fail_and_slash() {

// FIXME: cron_tick calls 'VERIFIED_REGISTRY_ACTOR_ADDR' with the 'USE_BYTES_METHOD' method.
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
RawBytes::default(),
deal_proposal.provider_collateral.clone(),
Expand Down
8 changes: 4 additions & 4 deletions actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(&[*INIT_ACTOR_ADDR])?;
rt.validate_immediate_caller_is(std::iter::once(&INIT_ACTOR_ADDR))?;

check_control_addresses(rt.policy(), &params.control_addresses)?;
check_peer_info(rt.policy(), &params.peer_id, &params.multi_addresses)?;
Expand Down Expand Up @@ -2045,7 +2045,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(iter::once(&*STORAGE_POWER_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(iter::once(&STORAGE_POWER_ACTOR_ADDR))?;

// This should be enforced by the power actor. We log here just in case
// something goes wrong.
Expand Down Expand Up @@ -3067,7 +3067,7 @@ impl Actor {
let (pledge_delta_total, to_burn) = rt.transaction(|st: &mut State, rt| {
let mut pledge_delta_total = TokenAmount::zero();

rt.validate_immediate_caller_is(std::iter::once(&*REWARD_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&REWARD_ACTOR_ADDR))?;

let (reward_to_lock, locked_reward_vesting_spec) =
locked_reward_from_reward(params.reward);
Expand Down Expand Up @@ -3531,7 +3531,7 @@ impl Actor {
BS: Blockstore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*STORAGE_POWER_ACTOR_ADDR))?;
rt.validate_immediate_caller_is(std::iter::once(&STORAGE_POWER_ACTOR_ADDR))?;

let payload: CronEventPayload = from_slice(&params.event_payload).map_err(|e| {
actor_error!(
Expand Down
Loading

0 comments on commit af836ea

Please sign in to comment.