Skip to content

Commit

Permalink
fix: correctly assert the state at the end of the paychan test (#1417)
Browse files Browse the repository at this point in the history
The actor has been deleted so the assertions should reflect that. By
removing the state from the mock runtime, this change will also let us
catch any other testing bugs (and let's us assert that the actor was
actually deleted).
  • Loading branch information
Stebalien authored Sep 22, 2023
1 parent d918b73 commit 7ad4726
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions actors/paych/tests/paych_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,14 +929,16 @@ mod actor_collect {
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.from);
rt.expect_validate_caller_addr(vec![st.from, st.to]);
call(&rt, Method::Settle as u64, None);
check_state(&rt);

let st: PState = rt.get_state();
assert_eq!(st.settling_at, SETTLE_DELAY + curr_epoch);
rt.expect_validate_caller_addr(vec![st.from, st.to]);

// wait for settlingat epoch
rt.epoch.replace(st.settling_at + 1);

// Collect.
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.to);
rt.expect_send_simple(
st.to,
METHOD_SEND,
Expand All @@ -946,8 +948,6 @@ mod actor_collect {
ExitCode::OK,
);

// Collect.
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.to);
rt.expect_validate_caller_addr(vec![st.from, st.to]);
rt.expect_send_simple(
st.from,
Expand All @@ -960,7 +960,7 @@ mod actor_collect {
rt.expect_delete_actor();
let res = call(&rt, Method::Collect as u64, None);
assert!(res.is_none());
check_state(&rt);
assert!(rt.is_deleted());
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ impl<BS: Blockstore> MockRuntime<BS> {
self.policy = policy;
}

pub fn is_deleted(&self) -> bool {
self.state.borrow().is_none()
}

pub fn get_state<T: DeserializeOwned>(&self) -> T {
self.store_get(self.state.borrow().as_ref().unwrap())
}
Expand Down Expand Up @@ -1186,6 +1190,7 @@ impl<BS: Blockstore> Runtime for MockRuntime<BS> {
if *self.in_transaction.borrow() {
return Err(actor_error!(assertion_failed; "side-effect within transaction"));
}
*self.state.borrow_mut() = None;
let mut exp = self.expectations.borrow_mut();
assert!(exp.expect_delete_actor, "unexpected call to delete actor");
exp.expect_delete_actor = false;
Expand Down

0 comments on commit 7ad4726

Please sign in to comment.