Skip to content

Commit 34a9e8c

Browse files
committed
Miner: Export ChangeOwnerAddress
1 parent 573f45d commit 34a9e8c

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

actors/miner/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub enum Method {
131131
ChangeMultiaddrsExported = frc42_dispatch::method_hash!("ChangeMultiaddrs"),
132132
ConfirmUpdateWorkerKeyExported = frc42_dispatch::method_hash!("ConfirmUpdateWorkerKey"),
133133
RepayDebtExported = frc42_dispatch::method_hash!("RepayDebt"),
134+
ChangeOwnerAddressExported = frc42_dispatch::method_hash!("ChangeOwnerAddress"),
134135
ChangeBenificiaryExported = frc42_dispatch::method_hash!("ChangeBeneficiary"),
135136
GetBeneficiaryExported = frc42_dispatch::method_hash!("GetBeneficiary"),
136137
GetOwnerExported = frc42_dispatch::method_hash!("GetOwner"),
@@ -5023,7 +5024,7 @@ impl ActorCode for Actor {
50235024
Self::repay_debt(rt)?;
50245025
Ok(RawBytes::default())
50255026
}
5026-
Some(Method::ChangeOwnerAddress) => {
5027+
Some(Method::ChangeOwnerAddress) | Some(Method::ChangeOwnerAddressExported) => {
50275028
Self::change_owner_address(rt, cbor::deserialize_params(params)?)?;
50285029
Ok(RawBytes::default())
50295030
}

actors/miner/tests/change_owner_address_test.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use fil_actor_miner::{Actor, Method};
12
use fil_actors_runtime::test_utils::{
2-
expect_abort, new_bls_addr, MockRuntime, ACCOUNT_ACTOR_CODE_ID, MULTISIG_ACTOR_CODE_ID,
3+
expect_abort, expect_abort_contains_message, make_identity_cid, new_bls_addr, MockRuntime,
4+
ACCOUNT_ACTOR_CODE_ID, MULTISIG_ACTOR_CODE_ID,
35
};
6+
use fvm_ipld_encoding::RawBytes;
47
use fvm_shared::econ::TokenAmount;
58
use fvm_shared::{address::Address, error::ExitCode};
69

@@ -52,6 +55,47 @@ fn successful_change() {
5255
h.check_state(&rt);
5356
}
5457

58+
#[test]
59+
fn change_owner_address_restricted_correctly() {
60+
let (h, mut rt) = setup();
61+
62+
let params = &RawBytes::serialize(NEW_ADDRESS).unwrap();
63+
rt.set_caller(make_identity_cid(b"1234"), h.owner);
64+
65+
// fail to call the unexported method
66+
67+
expect_abort_contains_message(
68+
ExitCode::USR_FORBIDDEN,
69+
"must be built-in",
70+
rt.call::<Actor>(Method::ChangeOwnerAddress as u64, &params),
71+
);
72+
73+
// can call the exported method
74+
75+
rt.expect_validate_caller_addr(vec![h.owner]);
76+
rt.call::<Actor>(Method::ChangeOwnerAddressExported as u64, params).unwrap();
77+
78+
rt.verify();
79+
80+
let info = h.get_info(&rt);
81+
assert_eq!(h.owner, info.owner);
82+
assert_eq!(NEW_ADDRESS, info.pending_owner_address.unwrap());
83+
84+
// new owner can also call the exported method
85+
86+
rt.expect_validate_caller_addr(vec![NEW_ADDRESS]);
87+
rt.set_caller(make_identity_cid(b"1234"), NEW_ADDRESS);
88+
rt.call::<Actor>(Method::ChangeOwnerAddressExported as u64, params).unwrap();
89+
90+
rt.verify();
91+
let info = h.get_info(&rt);
92+
assert_eq!(NEW_ADDRESS, info.owner);
93+
assert_eq!(NEW_ADDRESS, info.beneficiary);
94+
assert!(info.pending_owner_address.is_none());
95+
96+
h.check_state(&rt);
97+
}
98+
5599
#[test]
56100
fn successful_keep_beneficiary_when_change_owner() {
57101
let (mut h, mut rt) = setup();

0 commit comments

Comments
 (0)