Skip to content

Commit

Permalink
power actor tests part 7 (#284)
Browse files Browse the repository at this point in the history
* power actor tests part 7

* fix typo
  • Loading branch information
LesnyRumcajs authored Apr 27, 2022
1 parent f2f2a75 commit d239339
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
12 changes: 12 additions & 0 deletions actors/power/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ impl Harness {
claims.get(&miner.to_bytes()).unwrap().cloned()
}

pub fn delete_claim(&mut self, rt: &mut MockRuntime, miner: &Address) {
let mut state: State = rt.get_state();

let mut claims =
make_map_with_root_and_bitwidth::<_, Claim>(&state.claims, rt.store(), HAMT_BIT_WIDTH)
.unwrap();
claims.delete(&miner.to_bytes()).expect("Failed to delete claim");
state.claims = claims.flush().unwrap();

rt.replace_state(&state);
}

pub fn enroll_cron_event(
&self,
rt: &mut MockRuntime,
Expand Down
42 changes: 40 additions & 2 deletions actors/power/tests/power_actor_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use fil_actor_power::ext::init::{ExecParams, EXEC_METHOD};
use fil_actor_power::ext::miner::MinerConstructorParams;
use fil_actors_runtime::test_utils::{
expect_abort, ACCOUNT_ACTOR_CODE_ID, CALLER_TYPES_SIGNABLE, MINER_ACTOR_CODE_ID,
SYSTEM_ACTOR_CODE_ID,
expect_abort, expect_abort_contains_message, ACCOUNT_ACTOR_CODE_ID, CALLER_TYPES_SIGNABLE,
MINER_ACTOR_CODE_ID, SYSTEM_ACTOR_CODE_ID,
};
use fil_actors_runtime::INIT_ACTOR_ADDR;
use fvm_ipld_encoding::{BytesDe, RawBytes};
use fvm_shared::address::Address;
use fvm_shared::bigint::bigint_ser::BigIntSer;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
Expand Down Expand Up @@ -336,3 +337,40 @@ fn enroll_cron_epoch_given_negative_epoch_should_fail() {
rt.verify();
h.check_state();
}

#[test]
fn given_no_miner_claim_update_pledge_total_should_abort() {
let (mut h, mut rt) = setup();

let peer = "miner".as_bytes().to_vec();
let multiaddrs = vec![BytesDe("multiaddr".as_bytes().to_vec())];
h.create_miner(
&mut rt,
&OWNER,
&OWNER,
&MINER,
&ACTOR,
peer,
multiaddrs,
RegisteredPoStProof::StackedDRGWindow32GiBV1,
&TokenAmount::zero(),
)
.unwrap();

// explicitly delete miner claim
h.delete_claim(&mut rt, &*MINER);

rt.set_caller(*MINER_ACTOR_CODE_ID, *MINER);
rt.expect_validate_caller_type(vec![*MINER_ACTOR_CODE_ID]);
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"unknown miner",
rt.call::<PowerActor>(
Method::UpdatePledgeTotal as u64,
&RawBytes::serialize(BigIntSer(&TokenAmount::from(1_000_000))).unwrap(),
),
);

rt.verify();
h.check_state();
}

0 comments on commit d239339

Please sign in to comment.