From 7ad472678048ccc20fe9bd496034dcd55af4cef7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 22 Sep 2023 09:10:30 -0700 Subject: [PATCH] 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). --- actors/paych/tests/paych_actor_test.rs | 8 ++++---- runtime/src/test_utils.rs | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/actors/paych/tests/paych_actor_test.rs b/actors/paych/tests/paych_actor_test.rs index d256a458e..70c3b25f5 100644 --- a/actors/paych/tests/paych_actor_test.rs +++ b/actors/paych/tests/paych_actor_test.rs @@ -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, @@ -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, @@ -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] diff --git a/runtime/src/test_utils.rs b/runtime/src/test_utils.rs index d60e6f7a5..dbe571d5e 100644 --- a/runtime/src/test_utils.rs +++ b/runtime/src/test_utils.rs @@ -473,6 +473,10 @@ impl MockRuntime { self.policy = policy; } + pub fn is_deleted(&self) -> bool { + self.state.borrow().is_none() + } + pub fn get_state(&self) -> T { self.store_get(self.state.borrow().as_ref().unwrap()) } @@ -1186,6 +1190,7 @@ impl Runtime for MockRuntime { 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;