Skip to content

Commit 26dd561

Browse files
committed
Miner: Export ChangeMultiaddrs
1 parent 4812c4c commit 26dd561

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

actors/miner/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub enum Method {
128128
ChangeWorkerAddressExported = frc42_dispatch::method_hash!("ChangeWorkerAddress"),
129129
ChangePeerIDExported = frc42_dispatch::method_hash!("ChangePeerID"),
130130
WithdrawBalanceExported = frc42_dispatch::method_hash!("WithdrawBalance"),
131+
ChangeMultiaddrsExported = frc42_dispatch::method_hash!("ChangeMultiaddrs"),
131132
ChangeBenificiaryExported = frc42_dispatch::method_hash!("ChangeBeneficiary"),
132133
GetBeneficiaryExported = frc42_dispatch::method_hash!("GetBeneficiary"),
133134
GetOwnerExported = frc42_dispatch::method_hash!("GetOwner"),
@@ -5000,7 +5001,7 @@ impl ActorCode for Actor {
50005001
Self::confirm_sector_proofs_valid(rt, cbor::deserialize_params(params)?)?;
50015002
Ok(RawBytes::default())
50025003
}
5003-
Some(Method::ChangeMultiaddrs) => {
5004+
Some(Method::ChangeMultiaddrs) | Some(Method::ChangeMultiaddrsExported) => {
50045005
Self::change_multiaddresses(rt, cbor::deserialize_params(params)?)?;
50055006
Ok(RawBytes::default())
50065007
}

actors/miner/tests/miner_actor_test_peer_info.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use fil_actors_runtime::test_utils::*;
22

3-
use fvm_ipld_encoding::BytesDe;
3+
use fil_actor_miner::{Actor, ChangeMultiaddrsParams, Method};
4+
use fvm_ipld_encoding::{BytesDe, RawBytes};
5+
use fvm_shared::error::ExitCode;
46

57
mod util;
68

@@ -109,3 +111,41 @@ fn cant_set_large_multiaddrs() {
109111

110112
h.check_state(&rt);
111113
}
114+
115+
#[test]
116+
fn change_multiaddrs_restricted_correctly() {
117+
let mut rt = MockRuntime::default();
118+
let h = util::ActorHarness::new(0);
119+
120+
h.construct_and_verify(&mut rt);
121+
122+
let new_multiaddrs = vec![BytesDe(vec![1, 3, 3, 7])];
123+
124+
let params =
125+
&RawBytes::serialize(ChangeMultiaddrsParams { new_multi_addrs: new_multiaddrs.clone() })
126+
.unwrap();
127+
128+
rt.set_caller(make_identity_cid(b"1234"), h.worker);
129+
130+
// fail to call the unexported method
131+
132+
expect_abort_contains_message(
133+
ExitCode::USR_FORBIDDEN,
134+
"must be built-in",
135+
rt.call::<Actor>(Method::ChangeMultiaddrs as u64, params),
136+
);
137+
138+
// call the exported method
139+
140+
rt.expect_validate_caller_addr(h.caller_addrs());
141+
142+
rt.call::<Actor>(Method::ChangeMultiaddrsExported as u64, params).unwrap();
143+
rt.verify();
144+
145+
let state = h.get_state(&rt);
146+
let info = state.get_info(&rt.store).unwrap();
147+
148+
assert_eq!(new_multiaddrs, info.multi_address);
149+
150+
h.check_state(&rt);
151+
}

0 commit comments

Comments
 (0)