Skip to content

Commit abb573c

Browse files
Stebalienmriise
authored andcommitted
feat: use consts for addrs (filecoin-project#660)
* feat: use consts for addrs And expose actor IDs so we don't need to call `.id().unwrap()` to retrieve them. * remove old TODO and extern crate refs Co-authored-by: mriise <me@mriise.net>
1 parent 6c879d3 commit abb573c

46 files changed

Lines changed: 670 additions & 451 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
@@ -45,7 +45,7 @@ impl Actor {
4545
BS: Blockstore,
4646
RT: Runtime<BS>,
4747
{
48-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
48+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
4949
match address.protocol() {
5050
Protocol::Secp256k1 | Protocol::BLS => {}
5151
protocol => {

actors/account/tests/account_actor_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ macro_rules! account_constructor_tests {
105105
caller_type: SYSTEM_ACTOR_CODE_ID.clone(),
106106
..Default::default()
107107
};
108-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
108+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
109109

110110
if exit_code.is_success() {
111111
rt.call::<AccountActor>(1, &RawBytes::serialize(addr).unwrap()).unwrap();
@@ -157,13 +157,13 @@ account_constructor_tests! {
157157
fn authenticate_message() {
158158
let mut rt = MockRuntime {
159159
receiver: Address::new_id(100),
160-
caller: *SYSTEM_ACTOR_ADDR,
160+
caller: SYSTEM_ACTOR_ADDR,
161161
caller_type: *SYSTEM_ACTOR_CODE_ID,
162162
..Default::default()
163163
};
164164

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

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

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
@@ -81,7 +81,7 @@ impl Actor {
8181
BS: Blockstore,
8282
RT: Runtime<BS>,
8383
{
84-
rt.validate_immediate_caller_is(std::iter::once(&*SYSTEM_ACTOR_ADDR))?;
84+
rt.validate_immediate_caller_is(std::iter::once(&SYSTEM_ACTOR_ADDR))?;
8585

8686
let st = State::new(rt.store()).map_err(|e| {
8787
e.downcast_default(ExitCode::USR_ILLEGAL_STATE, "Failed to create market state")
@@ -785,7 +785,7 @@ impl Actor {
785785
BS: Blockstore,
786786
RT: Runtime<BS>,
787787
{
788-
rt.validate_immediate_caller_is(std::iter::once(&*CRON_ACTOR_ADDR))?;
788+
rt.validate_immediate_caller_is(std::iter::once(&CRON_ACTOR_ADDR))?;
789789

790790
let mut amount_slashed = TokenAmount::zero();
791791
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: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn timed_out_deal_is_slashed_and_deleted() {
4141
// do a cron tick for it -> should time out and get slashed
4242
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
4343
rt.expect_send(
44-
*BURNT_FUNDS_ACTOR_ADDR,
44+
BURNT_FUNDS_ACTOR_ADDR,
4545
METHOD_SEND,
4646
RawBytes::default(),
4747
deal_proposal.provider_collateral.clone(),
@@ -114,7 +114,7 @@ fn publishing_timed_out_deal_again_should_work_after_cron_tick_as_it_should_no_l
114114
// do a cron tick for it -> should time out and get slashed
115115
rt.set_epoch(process_epoch(START_EPOCH, deal_id));
116116
rt.expect_send(
117-
*BURNT_FUNDS_ACTOR_ADDR,
117+
BURNT_FUNDS_ACTOR_ADDR,
118118
METHOD_SEND,
119119
RawBytes::default(),
120120
deal_proposal.provider_collateral.clone(),
@@ -177,9 +177,36 @@ fn timed_out_and_verified_deals_are_slashed_deleted() {
177177
// ONLY deal1 and deal2 should be sent to the Registry actor
178178
rt.set_epoch(process_epoch(START_EPOCH, *deal_ids.last().unwrap()));
179179

180+
// expected sends to the registry actor
181+
let param1 = RestoreBytesParams {
182+
address: deal1.client,
183+
deal_size: StoragePower::from(deal1.piece_size.0),
184+
};
185+
let param2 = RestoreBytesParams {
186+
address: deal2.client,
187+
deal_size: StoragePower::from(deal2.piece_size.0),
188+
};
189+
190+
rt.expect_send(
191+
VERIFIED_REGISTRY_ACTOR_ADDR,
192+
ext::verifreg::RESTORE_BYTES_METHOD as u64,
193+
RawBytes::serialize(param1).unwrap(),
194+
TokenAmount::zero(),
195+
RawBytes::default(),
196+
ExitCode::OK,
197+
);
198+
rt.expect_send(
199+
VERIFIED_REGISTRY_ACTOR_ADDR,
200+
ext::verifreg::RESTORE_BYTES_METHOD as u64,
201+
RawBytes::serialize(param2).unwrap(),
202+
TokenAmount::zero(),
203+
RawBytes::default(),
204+
ExitCode::OK,
205+
);
206+
180207
let expected_burn = 3 * &deal1.provider_collateral;
181208
rt.expect_send(
182-
*BURNT_FUNDS_ACTOR_ADDR,
209+
BURNT_FUNDS_ACTOR_ADDR,
183210
METHOD_SEND,
184211
RawBytes::default(),
185212
expected_burn,

actors/market/tests/harness.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ pub fn setup() -> MockRuntime {
8585
]);
8686

8787
let mut rt = MockRuntime {
88-
receiver: *STORAGE_MARKET_ACTOR_ADDR,
89-
caller: *SYSTEM_ACTOR_ADDR,
88+
receiver: STORAGE_MARKET_ACTOR_ADDR,
89+
caller: SYSTEM_ACTOR_ADDR,
9090
caller_type: *INIT_ACTOR_CODE_ID,
9191
actor_code_cids,
9292
balance: RefCell::new(TokenAmount::from_whole(10)),
@@ -114,7 +114,7 @@ pub fn check_state_with_expected(rt: &MockRuntime, expected_patterns: &[Regex])
114114
}
115115

116116
pub fn construct_and_verify(rt: &mut MockRuntime) {
117-
rt.expect_validate_caller_addr(vec![*SYSTEM_ACTOR_ADDR]);
117+
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);
118118
assert_eq!(
119119
RawBytes::default(),
120120
rt.call::<MarketActor>(METHOD_CONSTRUCTOR, &RawBytes::default()).unwrap()
@@ -371,7 +371,7 @@ pub fn cron_tick_and_assert_balances(
371371
let mut payment_end = d.end_epoch;
372372
if s.slash_epoch != EPOCH_UNDEFINED {
373373
rt.expect_send(
374-
*BURNT_FUNDS_ACTOR_ADDR,
374+
BURNT_FUNDS_ACTOR_ADDR,
375375
METHOD_SEND,
376376
RawBytes::default(),
377377
d.provider_collateral.clone(),
@@ -515,9 +515,9 @@ pub fn publish_deals(
515515
new_allocations: vec![alloc_id],
516516
};
517517
rt.expect_send(
518-
*DATACAP_TOKEN_ACTOR_ADDR,
519-
ext::datacap::TRANSFER_FROM_METHOD as u64,
520-
serialize(&params, "transfer from params").unwrap(),
518+
VERIFIED_REGISTRY_ACTOR_ADDR,
519+
ext::verifreg::USE_BYTES_METHOD as u64,
520+
param,
521521
TokenAmount::zero(),
522522
serialize(
523523
&TransferFromReturn {
@@ -628,8 +628,8 @@ pub fn cron_tick(rt: &mut MockRuntime) {
628628
}
629629

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

634634
rt.call::<MarketActor>(Method::CronTick as u64, &RawBytes::default())
635635
}
@@ -652,15 +652,15 @@ pub fn expect_query_network_info(rt: &mut MockRuntime) {
652652
this_epoch_reward_smoothed: epoch_reward_smooth,
653653
};
654654
rt.expect_send(
655-
*REWARD_ACTOR_ADDR,
655+
REWARD_ACTOR_ADDR,
656656
RewardMethod::ThisEpochReward as u64,
657657
RawBytes::default(),
658658
TokenAmount::zero(),
659659
RawBytes::serialize(current_reward).unwrap(),
660660
ExitCode::OK,
661661
);
662662
rt.expect_send(
663-
*STORAGE_POWER_ACTOR_ADDR,
663+
STORAGE_POWER_ACTOR_ADDR,
664664
PowerMethod::CurrentTotalPower as u64,
665665
RawBytes::default(),
666666
TokenAmount::zero(),

0 commit comments

Comments
 (0)