|
1 | 1 | use fil_actors_runtime::test_utils::*; |
2 | 2 |
|
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; |
4 | 6 |
|
5 | 7 | mod util; |
6 | 8 |
|
@@ -109,3 +111,41 @@ fn cant_set_large_multiaddrs() { |
109 | 111 |
|
110 | 112 | h.check_state(&rt); |
111 | 113 | } |
| 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