|  | 
|  | 1 | +use fil_actor_miner::{Actor, Method}; | 
| 1 | 2 | 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, | 
| 3 | 5 | }; | 
|  | 6 | +use fvm_ipld_encoding::RawBytes; | 
| 4 | 7 | use fvm_shared::econ::TokenAmount; | 
| 5 | 8 | use fvm_shared::{address::Address, error::ExitCode}; | 
| 6 | 9 | 
 | 
| @@ -52,6 +55,47 @@ fn successful_change() { | 
| 52 | 55 |     h.check_state(&rt); | 
| 53 | 56 | } | 
| 54 | 57 | 
 | 
|  | 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, ¶ms), | 
|  | 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 | + | 
| 55 | 99 | #[test] | 
| 56 | 100 | fn successful_keep_beneficiary_when_change_owner() { | 
| 57 | 101 |     let (mut h, mut rt) = setup(); | 
|  | 
0 commit comments