Skip to content

Commit 7ad4726

Browse files
authored
fix: correctly assert the state at the end of the paychan test (#1417)
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).
1 parent d918b73 commit 7ad4726

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

actors/paych/tests/paych_actor_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,14 +929,16 @@ mod actor_collect {
929929
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.from);
930930
rt.expect_validate_caller_addr(vec![st.from, st.to]);
931931
call(&rt, Method::Settle as u64, None);
932+
check_state(&rt);
932933

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

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

940+
// Collect.
941+
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.to);
940942
rt.expect_send_simple(
941943
st.to,
942944
METHOD_SEND,
@@ -946,8 +948,6 @@ mod actor_collect {
946948
ExitCode::OK,
947949
);
948950

949-
// Collect.
950-
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, st.to);
951951
rt.expect_validate_caller_addr(vec![st.from, st.to]);
952952
rt.expect_send_simple(
953953
st.from,
@@ -960,7 +960,7 @@ mod actor_collect {
960960
rt.expect_delete_actor();
961961
let res = call(&rt, Method::Collect as u64, None);
962962
assert!(res.is_none());
963-
check_state(&rt);
963+
assert!(rt.is_deleted());
964964
}
965965

966966
#[test]

runtime/src/test_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ impl<BS: Blockstore> MockRuntime<BS> {
473473
self.policy = policy;
474474
}
475475

476+
pub fn is_deleted(&self) -> bool {
477+
self.state.borrow().is_none()
478+
}
479+
476480
pub fn get_state<T: DeserializeOwned>(&self) -> T {
477481
self.store_get(self.state.borrow().as_ref().unwrap())
478482
}
@@ -1186,6 +1190,7 @@ impl<BS: Blockstore> Runtime for MockRuntime<BS> {
11861190
if *self.in_transaction.borrow() {
11871191
return Err(actor_error!(assertion_failed; "side-effect within transaction"));
11881192
}
1193+
*self.state.borrow_mut() = None;
11891194
let mut exp = self.expectations.borrow_mut();
11901195
assert!(exp.expect_delete_actor, "unexpected call to delete actor");
11911196
exp.expect_delete_actor = false;

0 commit comments

Comments
 (0)