Skip to content

Commit af836ea

Browse files
committed
feat: use consts for addrs
And expose actor IDs so we don't need to call `.id().unwrap()` to retrieve them.
1 parent fe531cb commit af836ea

44 files changed

Lines changed: 390 additions & 381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actors/account/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Actor {
4747
BS: Blockstore,
4848
RT: Runtime<BS>,
4949
{
50-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
50+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
5151
match address.protocol() {
5252
Protocol::Secp256k1 | Protocol::BLS => {}
5353
protocol => {

actors/account/tests/account_actor_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ macro_rules! account_constructor_tests {
3030
caller_type: SYSTEM_ACTOR_CODE_ID.clone(),
3131
..Default::default()
3232
};
33-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
33+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
3434

3535
if exit_code.is_success() {
3636
rt.call::<AccountActor>(1, &RawBytes::serialize(addr).unwrap()).unwrap();
@@ -82,13 +82,13 @@ account_constructor_tests! {
8282
fn authenticate_message() {
8383
let mut rt = MockRuntime {
8484
receiver: Address::new_id(100),
85-
caller: *SYSTEM_ACTOR_ADDR,
85+
caller: SYSTEM_ACTOR_ADDR,
8686
caller_type: *SYSTEM_ACTOR_CODE_ID,
8787
..Default::default()
8888
};
8989

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

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

actors/cron/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Actor {
4747
BS: Blockstore,
4848
RT: Runtime<BS>,
4949
{
50-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
50+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
5151
rt.create(&State { entries: params.entries })?;
5252
Ok(())
5353
}
@@ -59,7 +59,7 @@ impl Actor {
5959
BS: Blockstore,
6060
RT: Runtime<BS>,
6161
{
62-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
62+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
6363

6464
let st: State = rt.state()?;
6565
for entry in st.entries {

actors/cron/tests/cron_actor_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn check_state(rt: &MockRuntime) {
1919
fn construct_runtime() -> MockRuntime {
2020
MockRuntime {
2121
receiver: Address::new_id(100),
22-
caller: *SYSTEM_ACTOR_ADDR,
22+
caller: SYSTEM_ACTOR_ADDR,
2323
caller_type: *SYSTEM_ACTOR_CODE_ID,
2424
..Default::default()
2525
}
@@ -114,14 +114,14 @@ fn epoch_tick_with_entries() {
114114
}
115115

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

123123
fn epoch_tick_and_verify(rt: &mut MockRuntime) {
124-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
124+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
125125
let ret = rt.call::<CronActor>(2, &RawBytes::default()).unwrap();
126126
assert_eq!(RawBytes::default(), ret);
127127
rt.verify();

actors/init/tests/init_actor_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn check_state(rt: &MockRuntime) {
2727
fn construct_runtime() -> MockRuntime {
2828
MockRuntime {
2929
receiver: Address::new_id(1000),
30-
caller: *SYSTEM_ACTOR_ADDR,
30+
caller: SYSTEM_ACTOR_ADDR,
3131
caller_type: *SYSTEM_ACTOR_CODE_ID,
3232
..Default::default()
3333
}
@@ -163,7 +163,7 @@ fn create_storage_miner() {
163163
construct_and_verify(&mut rt);
164164

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

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

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

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

290290
fn construct_and_verify(rt: &mut MockRuntime) {
291-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
291+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
292292
let params = ConstructorParams { network_name: "mock".to_string() };
293293
let ret =
294294
rt.call::<InitActor>(METHOD_CONSTRUCTOR, &RawBytes::serialize(&params).unwrap()).unwrap();

actors/market/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Actor {
9797
BS: Blockstore,
9898
RT: Runtime<BS>,
9999
{
100-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
100+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
101101

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

771771
let mut amount_slashed = TokenAmount::zero();
772772
let curr_epoch = rt.curr_epoch();

actors/market/tests/cron_tick_deal_slashing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn slash_multiple_deals_in_the_same_epoch() {
238238
+ &deal_proposal2.provider_collateral
239239
+ &deal_proposal3.provider_collateral;
240240
rt.expect_send(
241-
*BURNT_FUNDS_ACTOR_ADDR,
241+
BURNT_FUNDS_ACTOR_ADDR,
242242
METHOD_SEND,
243243
RawBytes::default(),
244244
total_slashed,

actors/market/tests/cron_tick_timedout_deals.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn timed_out_deal_is_slashed_and_deleted() {
4343
// do a cron tick for it -> should time out and get slashed
4444
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
4545
rt.expect_send(
46-
*BURNT_FUNDS_ACTOR_ADDR,
46+
BURNT_FUNDS_ACTOR_ADDR,
4747
METHOD_SEND,
4848
RawBytes::default(),
4949
deal_proposal.provider_collateral.clone(),
@@ -116,7 +116,7 @@ fn publishing_timed_out_deal_again_should_work_after_cron_tick_as_it_should_no_l
116116
// do a cron tick for it -> should time out and get slashed
117117
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
118118
rt.expect_send(
119-
*BURNT_FUNDS_ACTOR_ADDR,
119+
BURNT_FUNDS_ACTOR_ADDR,
120120
METHOD_SEND,
121121
RawBytes::default(),
122122
deal_proposal.provider_collateral.clone(),
@@ -189,15 +189,15 @@ fn timed_out_and_verified_deals_are_slashed_deleted_and_sent_to_the_registry_act
189189
};
190190

191191
rt.expect_send(
192-
*VERIFIED_REGISTRY_ACTOR_ADDR,
192+
VERIFIED_REGISTRY_ACTOR_ADDR,
193193
ext::verifreg::RESTORE_BYTES_METHOD as u64,
194194
RawBytes::serialize(param1).unwrap(),
195195
TokenAmount::zero(),
196196
RawBytes::default(),
197197
ExitCode::OK,
198198
);
199199
rt.expect_send(
200-
*VERIFIED_REGISTRY_ACTOR_ADDR,
200+
VERIFIED_REGISTRY_ACTOR_ADDR,
201201
ext::verifreg::RESTORE_BYTES_METHOD as u64,
202202
RawBytes::serialize(param2).unwrap(),
203203
TokenAmount::zero(),
@@ -207,7 +207,7 @@ fn timed_out_and_verified_deals_are_slashed_deleted_and_sent_to_the_registry_act
207207

208208
let expected_burn = 3 * &deal1.provider_collateral;
209209
rt.expect_send(
210-
*BURNT_FUNDS_ACTOR_ADDR,
210+
BURNT_FUNDS_ACTOR_ADDR,
211211
METHOD_SEND,
212212
RawBytes::default(),
213213
expected_burn,

actors/market/tests/harness.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ pub fn setup() -> MockRuntime {
8080
]);
8181

8282
let mut rt = MockRuntime {
83-
receiver: *STORAGE_MARKET_ACTOR_ADDR,
84-
caller: *SYSTEM_ACTOR_ADDR,
83+
receiver: STORAGE_MARKET_ACTOR_ADDR,
84+
caller: SYSTEM_ACTOR_ADDR,
8585
caller_type: *INIT_ACTOR_CODE_ID,
8686
actor_code_cids,
8787
balance: RefCell::new(TokenAmount::from_whole(10)),
@@ -109,7 +109,7 @@ pub fn check_state_with_expected(rt: &MockRuntime, expected_patterns: &[Regex])
109109
}
110110

111111
pub fn construct_and_verify(rt: &mut MockRuntime) {
112-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
112+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
113113
assert_eq!(
114114
RawBytes::default(),
115115
rt.call::<MarketActor>(METHOD_CONSTRUCTOR, &RawBytes::default()).unwrap()
@@ -365,7 +365,7 @@ pub fn cron_tick_and_assert_balances(
365365
let mut payment_end = d.end_epoch;
366366
if s.slash_epoch != EPOCH_UNDEFINED {
367367
rt.expect_send(
368-
*BURNT_FUNDS_ACTOR_ADDR,
368+
BURNT_FUNDS_ACTOR_ADDR,
369369
METHOD_SEND,
370370
RawBytes::default(),
371371
d.provider_collateral.clone(),
@@ -488,7 +488,7 @@ pub fn publish_deals(
488488
.unwrap();
489489

490490
rt.expect_send(
491-
*VERIFIED_REGISTRY_ACTOR_ADDR,
491+
VERIFIED_REGISTRY_ACTOR_ADDR,
492492
ext::verifreg::USE_BYTES_METHOD as u64,
493493
param,
494494
TokenAmount::zero(),
@@ -587,8 +587,8 @@ pub fn cron_tick(rt: &mut MockRuntime) {
587587
}
588588

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

593593
rt.call::<MarketActor>(Method::CronTick as u64, &RawBytes::default())
594594
}
@@ -611,15 +611,15 @@ pub fn expect_query_network_info(rt: &mut MockRuntime) {
611611
this_epoch_reward_smoothed: epoch_reward_smooth,
612612
};
613613
rt.expect_send(
614-
*REWARD_ACTOR_ADDR,
614+
REWARD_ACTOR_ADDR,
615615
RewardMethod::ThisEpochReward as u64,
616616
RawBytes::default(),
617617
TokenAmount::zero(),
618618
RawBytes::serialize(current_reward).unwrap(),
619619
ExitCode::OK,
620620
);
621621
rt.expect_send(
622-
*STORAGE_POWER_ACTOR_ADDR,
622+
STORAGE_POWER_ACTOR_ADDR,
623623
PowerMethod::CurrentTotalPower as u64,
624624
RawBytes::default(),
625625
TokenAmount::zero(),

0 commit comments

Comments
 (0)