From b2721f88bb60be805c3140e77fa037ab55667294 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Wed, 25 Oct 2023 17:46:40 +0400 Subject: [PATCH] Test VM should use Rc for consistency with the MockRuntime (#1454) * test vm should use Rc * use builder for RC * review changes --- test_vm/src/lib.rs | 39 +++++++++++-------- test_vm/src/messaging.rs | 23 +++++------ .../tests/suite/authenticate_message_test.rs | 2 +- test_vm/tests/suite/batch_onboarding.rs | 2 +- .../suite/batch_onboarding_deals_test.rs | 2 +- .../tests/suite/change_beneficiary_test.rs | 6 +-- test_vm/tests/suite/change_owner_test.rs | 6 +-- test_vm/tests/suite/commit_post_test.rs | 17 ++++---- test_vm/tests/suite/datacap_tests.rs | 4 +- test_vm/tests/suite/evm_test.rs | 16 ++++---- test_vm/tests/suite/extend_sectors_test.rs | 10 ++--- test_vm/tests/suite/init_test.rs | 2 +- .../suite/market_miner_withdrawal_test.rs | 14 +++---- test_vm/tests/suite/move_partitions_test.rs | 2 +- test_vm/tests/suite/multisig_test.rs | 8 ++-- test_vm/tests/suite/power_scenario_tests.rs | 4 +- test_vm/tests/suite/publish_deals_test.rs | 32 +++++++-------- test_vm/tests/suite/replica_update_test.rs | 37 +++++++++--------- test_vm/tests/suite/terminate_test.rs | 2 +- test_vm/tests/suite/test_vm_test.rs | 4 +- test_vm/tests/suite/verified_claim_test.rs | 6 +-- .../suite/verifreg_remove_datacap_test.rs | 4 +- test_vm/tests/suite/withdraw_balance_test.rs | 5 +-- 23 files changed, 126 insertions(+), 121 deletions(-) diff --git a/test_vm/src/lib.rs b/test_vm/src/lib.rs index 4bc90acec..5de2df9aa 100644 --- a/test_vm/src/lib.rs +++ b/test_vm/src/lib.rs @@ -38,6 +38,7 @@ use fvm_shared::{MethodNum, METHOD_SEND}; use serde::ser; use std::cell::{RefCell, RefMut}; use std::collections::{BTreeMap, HashMap}; +use std::rc::Rc; use vm_api::trace::InvocationTrace; use vm_api::{new_actor, ActorState, MessageResult, VMError, VM}; @@ -50,9 +51,9 @@ mod messaging; pub use messaging::*; /// An in-memory rust-execution VM for testing builtin-actors that yields sensible stack traces and debug info -pub struct TestVM<'bs> { +pub struct TestVM { pub primitives: FakePrimitives, - pub store: &'bs MemoryBlockstore, + pub store: Rc, pub state_root: RefCell, circulating_supply: RefCell, actors_dirty: RefCell, @@ -62,13 +63,15 @@ pub struct TestVM<'bs> { invocations: RefCell>, } -impl<'bs> TestVM<'bs> { - pub fn new(store: &'bs MemoryBlockstore) -> TestVM<'bs> { +impl TestVM { + pub fn new(store: impl Into>) -> TestVM { + let store = store.into(); let mut actors = - Hamt::<&'bs MemoryBlockstore, ActorState, BytesKey, Sha256>::new_with_config( - store, + Hamt::, ActorState, BytesKey, Sha256>::new_with_config( + Rc::clone(&store), DEFAULT_HAMT_CONFIG, ); + TestVM { primitives: FakePrimitives {}, store, @@ -82,15 +85,17 @@ impl<'bs> TestVM<'bs> { } } - pub fn new_with_singletons(store: &'bs MemoryBlockstore) -> TestVM<'bs> { + pub fn new_with_singletons(store: impl Into>) -> TestVM { let reward_total = TokenAmount::from_whole(1_100_000_000i64); let faucet_total = TokenAmount::from_whole(1_000_000_000i64); - let v = TestVM::<'_>::new(store); + let store = store.into(); + + let v = TestVM::new(Rc::clone(&store)); v.set_circulating_supply(&reward_total + &faucet_total); // system - let sys_st = SystemState::new(store).unwrap(); + let sys_st = SystemState::new(&store).unwrap(); let sys_head = v.put_store(&sys_st); let sys_value = faucet_total.clone(); // delegate faucet funds to system so we can construct faucet by sending to bls addr v.set_actor( @@ -99,7 +104,7 @@ impl<'bs> TestVM<'bs> { ); // init - let init_st = InitState::new(store, "integration-test".to_string()).unwrap(); + let init_st = InitState::new(&store, "integration-test".to_string()).unwrap(); let init_head = v.put_store(&init_st); v.set_actor( &INIT_ACTOR_ADDR, @@ -239,9 +244,9 @@ impl<'bs> TestVM<'bs> { pub fn checkpoint(&self) -> Cid { // persist cache on top of latest checkpoint and clear let mut actors = - Hamt::<&'bs MemoryBlockstore, ActorState, BytesKey, Sha256>::load_with_config( + Hamt::, ActorState, BytesKey, Sha256>::load_with_config( &self.state_root.borrow(), - self.store, + Rc::clone(&self.store), DEFAULT_HAMT_CONFIG, ) .unwrap(); @@ -275,9 +280,9 @@ impl<'bs> TestVM<'bs> { } } -impl<'bs> VM for TestVM<'bs> { +impl VM for TestVM { fn blockstore(&self) -> &dyn Blockstore { - self.store + self.store.as_ref() } fn epoch(&self) -> ChainEpoch { @@ -364,7 +369,7 @@ impl<'bs> VM for TestVM<'bs> { } fn resolve_id_address(&self, address: &Address) -> Option
{ let st: InitState = get_state(self, &INIT_ACTOR_ADDR).unwrap(); - st.resolve_address(self.store, address).unwrap() + st.resolve_address(&self.store, address).unwrap() } fn set_epoch(&self, epoch: ChainEpoch) { @@ -386,9 +391,9 @@ impl<'bs> VM for TestVM<'bs> { return Some(act.clone()); } // go to persisted map - let actors = Hamt::<&'bs MemoryBlockstore, ActorState, BytesKey, Sha256>::load_with_config( + let actors = Hamt::, ActorState, BytesKey, Sha256>::load_with_config( &self.state_root.borrow(), - self.store, + Rc::clone(&self.store), DEFAULT_HAMT_CONFIG, ) .unwrap(); diff --git a/test_vm/src/messaging.rs b/test_vm/src/messaging.rs index b62611543..da261b95d 100644 --- a/test_vm/src/messaging.rs +++ b/test_vm/src/messaging.rs @@ -62,6 +62,7 @@ use vm_api::{new_actor, ActorState, VM}; use fil_actors_runtime::test_blockstores::MemoryBlockstore; use std::ops::Add; +use std::rc::Rc; use crate::{TestVM, TEST_VM_INVALID_POST, TEST_VM_RAND_ARRAY}; @@ -82,7 +83,7 @@ pub struct InternalMessage { pub params: Option, } -impl MessageInfo for InvocationCtx<'_, '_> { +impl MessageInfo for InvocationCtx<'_> { fn nonce(&self) -> u64 { self.top.originator_call_seq } @@ -103,8 +104,8 @@ impl MessageInfo for InvocationCtx<'_, '_> { } } -pub struct InvocationCtx<'invocation, 'bs> { - pub v: &'invocation TestVM<'bs>, +pub struct InvocationCtx<'invocation> { + pub v: &'invocation TestVM, pub top: TopCtx, pub msg: InternalMessage, pub allow_side_effects: RefCell, @@ -114,7 +115,7 @@ pub struct InvocationCtx<'invocation, 'bs> { pub subinvocations: RefCell>, } -impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> { +impl<'invocation> InvocationCtx<'invocation> { fn resolve_target( &'invocation self, target: &Address, @@ -152,7 +153,7 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> { } let mut st: InitState = get_state(self.v, &INIT_ACTOR_ADDR).unwrap(); - let (target_id, existing) = st.map_addresses_to_id(self.v.store, target, None).unwrap(); + let (target_id, existing) = st.map_addresses_to_id(&self.v.store, target, None).unwrap(); assert!(!existing, "should never have existing actor when no f4 address is specified"); let target_id_addr = Address::new_id(target_id); let mut init_actor = self.v.actor(&INIT_ACTOR_ADDR).unwrap(); @@ -298,8 +299,8 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> { } } -impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> { - type Blockstore = &'bs MemoryBlockstore; +impl<'invocation> Runtime for InvocationCtx<'invocation> { + type Blockstore = Rc; fn create_actor( &self, @@ -341,7 +342,7 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> { Ok(()) } - fn store(&self) -> &&'bs MemoryBlockstore { + fn store(&self) -> &Rc { &self.v.store } @@ -645,7 +646,7 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> { } } -impl Primitives for InvocationCtx<'_, '_> { +impl Primitives for InvocationCtx<'_> { fn verify_signature( &self, signature: &Signature, @@ -684,7 +685,7 @@ impl Primitives for InvocationCtx<'_, '_> { } } -impl Verifier for InvocationCtx<'_, '_> { +impl Verifier for InvocationCtx<'_> { fn verify_post(&self, verify_info: &WindowPoStVerifyInfo) -> Result<(), anyhow::Error> { for proof in &verify_info.proofs { if proof.proof_bytes.eq(&TEST_VM_INVALID_POST.as_bytes().to_vec()) { @@ -720,7 +721,7 @@ impl Verifier for InvocationCtx<'_, '_> { } } -impl RuntimePolicy for InvocationCtx<'_, '_> { +impl RuntimePolicy for InvocationCtx<'_> { fn policy(&self) -> &Policy { self.policy } diff --git a/test_vm/tests/suite/authenticate_message_test.rs b/test_vm/tests/suite/authenticate_message_test.rs index f04594cd4..1d64dd043 100644 --- a/test_vm/tests/suite/authenticate_message_test.rs +++ b/test_vm/tests/suite/authenticate_message_test.rs @@ -5,6 +5,6 @@ use test_vm::TestVM; #[test] fn account_authenticate_message() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); account_authenticate_message_test(&v); } diff --git a/test_vm/tests/suite/batch_onboarding.rs b/test_vm/tests/suite/batch_onboarding.rs index 902687c3a..c374c3846 100644 --- a/test_vm/tests/suite/batch_onboarding.rs +++ b/test_vm/tests/suite/batch_onboarding.rs @@ -8,7 +8,7 @@ use test_vm::TestVM; #[test_case(true; "v2")] fn batch_onboarding(v2: bool) { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); batch_onboarding_test(&v, v2); } diff --git a/test_vm/tests/suite/batch_onboarding_deals_test.rs b/test_vm/tests/suite/batch_onboarding_deals_test.rs index 06b547ca7..dc6cdd5b0 100644 --- a/test_vm/tests/suite/batch_onboarding_deals_test.rs +++ b/test_vm/tests/suite/batch_onboarding_deals_test.rs @@ -5,6 +5,6 @@ use test_vm::TestVM; #[test] fn batch_onboarding_deals() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); batch_onboarding_deals_test(&v); } diff --git a/test_vm/tests/suite/change_beneficiary_test.rs b/test_vm/tests/suite/change_beneficiary_test.rs index c353540c9..5fa650e80 100644 --- a/test_vm/tests/suite/change_beneficiary_test.rs +++ b/test_vm/tests/suite/change_beneficiary_test.rs @@ -8,20 +8,20 @@ use test_vm::TestVM; #[test] fn change_beneficiary_success() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); change_beneficiary_success_test(&v); } #[test] fn change_beneficiary_back_owner_success() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); change_beneficiary_back_owner_success_test(&v); } #[test] fn change_beneficiary_fail() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); change_beneficiary_fail_test(&v); } diff --git a/test_vm/tests/suite/change_owner_test.rs b/test_vm/tests/suite/change_owner_test.rs index 4bac875a3..7a6269bde 100644 --- a/test_vm/tests/suite/change_owner_test.rs +++ b/test_vm/tests/suite/change_owner_test.rs @@ -7,20 +7,20 @@ use test_vm::TestVM; #[test] fn change_owner_success() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); change_owner_success_test(&v); } #[test] fn keep_beneficiary_when_owner_changed() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); keep_beneficiary_when_owner_changed_test(&v); } #[test] fn change_owner_fail() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); change_owner_fail_test(&v); } diff --git a/test_vm/tests/suite/commit_post_test.rs b/test_vm/tests/suite/commit_post_test.rs index b1178be37..7a513bc5f 100644 --- a/test_vm/tests/suite/commit_post_test.rs +++ b/test_vm/tests/suite/commit_post_test.rs @@ -6,59 +6,58 @@ use fil_actors_integration_tests::tests::{ }; use fil_actors_runtime::test_blockstores::MemoryBlockstore; use test_vm::TestVM; - #[test] fn submit_post_succeeds() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); submit_post_succeeds_test(&v); } #[test] fn skip_sector() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); skip_sector_test(&v); } #[test] fn missed_first_post_deadline() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); missed_first_post_deadline_test(&v); } #[test] fn overdue_precommit() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); overdue_precommit_test(&v); } #[test] fn aggregate_bad_sector_number() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); aggregate_bad_sector_number_test(&v); } #[test] fn aggregate_size_limits() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); aggregate_size_limits_test(&v); } #[test] fn aggregate_bad_sender() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); aggregate_bad_sender_test(&v); } #[test] fn aggregate_one_precommit_expires() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); aggregate_one_precommit_expires_test(&v); } diff --git a/test_vm/tests/suite/datacap_tests.rs b/test_vm/tests/suite/datacap_tests.rs index 53084a831..22a196c5b 100644 --- a/test_vm/tests/suite/datacap_tests.rs +++ b/test_vm/tests/suite/datacap_tests.rs @@ -6,7 +6,7 @@ use test_vm::TestVM; #[test] fn datacap_transfer() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); datacap_transfer_test(&v); } @@ -14,6 +14,6 @@ fn datacap_transfer() { #[test] fn call_name_symbol() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); call_name_symbol_test(&v); } diff --git a/test_vm/tests/suite/evm_test.rs b/test_vm/tests/suite/evm_test.rs index 7b9ab73d6..b1094fcd2 100644 --- a/test_vm/tests/suite/evm_test.rs +++ b/test_vm/tests/suite/evm_test.rs @@ -9,54 +9,54 @@ use test_vm::TestVM; #[test] fn evm_call() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_call_test(&v); } #[test] fn evm_create() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_create_test(&v); } #[test] fn evm_eth_create_external() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_eth_create_external_test(&v); } #[test] fn evm_empty_initcode() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_empty_initcode_test(&v); } #[test] fn evm_staticcall() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_staticcall_test(&v); } #[test] fn evm_delegatecall() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_delegatecall_test(&v); } #[test] fn evm_staticcall_delegatecall() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_staticcall_delegatecall_test(&v); } #[test] fn evm_init_revert_data() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); evm_init_revert_data_test(&v); } diff --git a/test_vm/tests/suite/extend_sectors_test.rs b/test_vm/tests/suite/extend_sectors_test.rs index 6b9a9b788..f0ba429f1 100644 --- a/test_vm/tests/suite/extend_sectors_test.rs +++ b/test_vm/tests/suite/extend_sectors_test.rs @@ -8,34 +8,34 @@ use test_vm::TestVM; #[test] fn extend_legacy_sector_with_deals() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); extend_legacy_sector_with_deals_test(&v, false); } #[test] fn extend2_legacy_sector_with_deals() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); extend_legacy_sector_with_deals_test(&v, true); } #[test] fn extend_updated_sector_with_claim() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); extend_updated_sector_with_claims_test(&v); } #[test] fn extend_sector_up_to_max_relative_extension() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); extend_sector_up_to_max_relative_extension_test(&v); } #[test] fn commit_sector_with_max_duration_deal() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); commit_sector_with_max_duration_deal_test(&v); } diff --git a/test_vm/tests/suite/init_test.rs b/test_vm/tests/suite/init_test.rs index 8b81c5f2b..b8acf6276 100644 --- a/test_vm/tests/suite/init_test.rs +++ b/test_vm/tests/suite/init_test.rs @@ -5,7 +5,7 @@ use test_vm::TestVM; #[test] fn placeholder_deploy() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); placeholder_deploy_test(&v); } diff --git a/test_vm/tests/suite/market_miner_withdrawal_test.rs b/test_vm/tests/suite/market_miner_withdrawal_test.rs index 9e0725748..f097e22b7 100644 --- a/test_vm/tests/suite/market_miner_withdrawal_test.rs +++ b/test_vm/tests/suite/market_miner_withdrawal_test.rs @@ -7,14 +7,14 @@ mod market_tests { #[test] fn withdraw_all_funds() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_all_funds_test(&v); } #[test] fn withdraw_as_much_as_possible() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_as_much_as_possible_test(&v); } @@ -22,7 +22,7 @@ mod market_tests { #[test] fn withdraw_0() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_0_test(&v); } } @@ -36,7 +36,7 @@ mod miner_tests { #[test] fn withdraw_all_funds() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_all_funds_test(&v); } @@ -44,21 +44,21 @@ mod miner_tests { #[test] fn withdraw_as_much_as_possible() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_as_much_as_possible_test(&v); } #[test] fn withdraw_0() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_0_test(&v); } #[test] fn withdraw_from_non_owner_address_fails() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_from_non_owner_address_fails_test(&v) } } diff --git a/test_vm/tests/suite/move_partitions_test.rs b/test_vm/tests/suite/move_partitions_test.rs index 3d9fa185d..23c5d0d8b 100644 --- a/test_vm/tests/suite/move_partitions_test.rs +++ b/test_vm/tests/suite/move_partitions_test.rs @@ -5,6 +5,6 @@ use test_vm::TestVM; #[test] fn move_partitions() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); move_partitions_test(&v); } diff --git a/test_vm/tests/suite/multisig_test.rs b/test_vm/tests/suite/multisig_test.rs index 6187394c3..bac2a249e 100644 --- a/test_vm/tests/suite/multisig_test.rs +++ b/test_vm/tests/suite/multisig_test.rs @@ -7,7 +7,7 @@ use test_vm::TestVM; #[test] fn proposal_hash() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); proposal_hash_test(&v); } @@ -15,7 +15,7 @@ fn proposal_hash() { fn test_delete_self() { let test = |threshold: usize, signers: u64, remove_idx: usize| { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); test_delete_self_inner_test(&v, signers, threshold, remove_idx); }; test(2, 3, 0); // 2 of 3 removed is proposer @@ -27,13 +27,13 @@ fn test_delete_self() { #[test] fn swap_self_1_of_2() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); swap_self_1_of_2_test(&v); } #[test] fn swap_self_2_of_3() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); swap_self_2_of_3_test(&v); } diff --git a/test_vm/tests/suite/power_scenario_tests.rs b/test_vm/tests/suite/power_scenario_tests.rs index d73e0b706..fafad17e1 100644 --- a/test_vm/tests/suite/power_scenario_tests.rs +++ b/test_vm/tests/suite/power_scenario_tests.rs @@ -5,7 +5,7 @@ use test_vm::TestVM; #[test] fn power_create_miner() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); power_create_miner_test(&v); } @@ -13,7 +13,7 @@ fn power_create_miner() { #[test] fn cron_tick() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); cron_tick_test(&v); } diff --git a/test_vm/tests/suite/publish_deals_test.rs b/test_vm/tests/suite/publish_deals_test.rs index b547b3f0d..23bdc73ff 100644 --- a/test_vm/tests/suite/publish_deals_test.rs +++ b/test_vm/tests/suite/publish_deals_test.rs @@ -13,111 +13,111 @@ use test_vm::TestVM; #[test] fn psd_mismatched_provider() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_mismatched_provider_test(&v); } #[test] fn psd_bad_piece_size() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_bad_piece_size_test(&v); } #[test] fn psd_start_time_in_past() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_start_time_in_past_test(&v); } #[test] fn psd_client_address_cannot_be_resolved() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_client_address_cannot_be_resolved_test(&v); } #[test] fn psd_no_client_lockup() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_no_client_lockup_test(&v); } #[test] fn psd_not_enough_client_lockup_for_batch() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_not_enough_client_lockup_for_batch_test(&v); } #[test] fn psd_not_enough_provider_lockup_for_batch() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_not_enough_provider_lockup_for_batch_test(&v); } #[test] fn psd_duplicate_deal_in_batch() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_duplicate_deal_in_batch_test(&v); } #[test] fn psd_duplicate_deal_in_state() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_duplicate_deal_in_state_test(&v); } #[test] fn psd_verified_deal_fails_getting_datacap() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_verified_deal_fails_getting_datacap_test(&v); } #[test] fn psd_random_assortment_of_failures() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_random_assortment_of_failures_test(&v); } #[test] fn psd_all_deals_are_bad() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_all_deals_are_bad_test(&v); } #[test] fn psd_bad_sig() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_bad_sig_test(&v); } #[test] fn psd_all_deals_are_good() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); all_deals_are_good_test(&v); } #[test] fn psd_valid_deals_with_ones_longer_than_540() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_valid_deals_with_ones_longer_than_540_test(&v); } #[test] fn psd_deal_duration_too_long() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); psd_deal_duration_too_long_test(&v); } diff --git a/test_vm/tests/suite/replica_update_test.rs b/test_vm/tests/suite/replica_update_test.rs index f4bc0b47e..b5859c17d 100644 --- a/test_vm/tests/suite/replica_update_test.rs +++ b/test_vm/tests/suite/replica_update_test.rs @@ -1,6 +1,7 @@ use fil_actors_integration_tests::tests::create_miner_and_upgrade_sector; use fil_actors_runtime::runtime::Policy; use fil_actors_runtime::test_blockstores::MemoryBlockstore; +use std::rc::Rc; use test_case::test_case; use test_vm::TestVM; @@ -21,7 +22,7 @@ use fil_actors_integration_tests::util::assert_invariants; #[test_case(false; "v1")] #[test_case(true; "v2")] fn replica_update_simple_path_success(v2: bool) { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); create_miner_and_upgrade_sector(&v, v2); assert_invariants(&v, &Policy::default()); @@ -31,7 +32,7 @@ fn replica_update_simple_path_success(v2: bool) { #[test_case(false; "v1")] #[test_case(true; "v2")] fn replica_update_full_path_success(v2: bool) { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); replica_update_full_path_success_test(&v, v2); } @@ -39,14 +40,14 @@ fn replica_update_full_path_success(v2: bool) { #[test_case(false; "v1")] #[test_case(true; "v2")] fn upgrade_and_miss_post(v2: bool) { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); upgrade_and_miss_post_test(&v, v2); } #[test] fn prove_replica_update_multi_dline() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); prove_replica_update_multi_dline_test(&v); } @@ -55,70 +56,70 @@ fn prove_replica_update_multi_dline() { #[test] fn immutable_deadline_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); immutable_deadline_failure_test(&v); } #[test] fn unhealthy_sector_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); unhealthy_sector_failure_test(&v); } #[test] fn terminated_sector_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); terminated_sector_failure_test(&v); } #[test] fn bad_batch_size_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); bad_batch_size_failure_test(&v); } #[test] fn no_dispute_after_upgrade() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); nodispute_after_upgrade_test(&v); } #[test] fn upgrade_bad_post_dispute() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); upgrade_bad_post_dispute_test(&v); } #[test] fn bad_post_upgrade_dispute() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); bad_post_upgrade_dispute_test(&v); } #[test] fn terminate_after_upgrade() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); terminate_after_upgrade_test(&v); } #[test] fn extend_after_upgrade() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); extend_after_upgrade_test(&v); } #[test] fn wrong_deadline_index_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); wrong_deadline_index_failure_test(&v); @@ -126,7 +127,7 @@ fn wrong_deadline_index_failure() { #[test] fn wrong_partition_index_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); wrong_partition_index_failure_test(&v); @@ -134,14 +135,14 @@ fn wrong_partition_index_failure() { #[test] fn deal_included_in_multiple_sectors_failure() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); deal_included_in_multiple_sectors_failure_test(&v); } #[test] fn replica_update_verified_deal() { - let store = &MemoryBlockstore::new(); + let store = MemoryBlockstore::new(); let v = TestVM::new_with_singletons(store); replica_update_verified_deal_test(&v); @@ -149,7 +150,7 @@ fn replica_update_verified_deal() { #[test] fn replica_update_verified_deal_max_term_violated() { - let store = &MemoryBlockstore::new(); + let store = Rc::new(MemoryBlockstore::new()); let v = TestVM::new_with_singletons(store); replica_update_verified_deal_max_term_violated_test(&v); } diff --git a/test_vm/tests/suite/terminate_test.rs b/test_vm/tests/suite/terminate_test.rs index 43ece8817..cfb6ecd9b 100644 --- a/test_vm/tests/suite/terminate_test.rs +++ b/test_vm/tests/suite/terminate_test.rs @@ -5,6 +5,6 @@ use test_vm::TestVM; #[test] fn terminate_sectors() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); terminate_sectors_test(&v); } diff --git a/test_vm/tests/suite/test_vm_test.rs b/test_vm/tests/suite/test_vm_test.rs index 8c3832cfb..a9e442c54 100644 --- a/test_vm/tests/suite/test_vm_test.rs +++ b/test_vm/tests/suite/test_vm_test.rs @@ -17,7 +17,7 @@ use vm_api::{new_actor, VM}; #[test] fn state_control() { let store = MemoryBlockstore::new(); - let v = TestVM::new(&store); + let v = TestVM::new(store); let addr1 = Address::new_id(1000); let addr2 = Address::new_id(2222); @@ -73,7 +73,7 @@ fn assert_account_actor( #[test] fn test_sent() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); // send to uninitialized account actor let addr1 = Address::new_bls(&[1; fvm_shared::address::BLS_PUB_LEN]).unwrap(); diff --git a/test_vm/tests/suite/verified_claim_test.rs b/test_vm/tests/suite/verified_claim_test.rs index 8da135f72..5e435e8a4 100644 --- a/test_vm/tests/suite/verified_claim_test.rs +++ b/test_vm/tests/suite/verified_claim_test.rs @@ -10,20 +10,20 @@ use test_vm::TestVM; #[test] fn verified_claim_scenario() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); verified_claim_scenario_test(&v); } #[test] fn expired_allocations() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); expired_allocations_test(&v); } #[test] fn deal_passes_claim_fails() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); deal_passes_claim_fails_test(&v); } diff --git a/test_vm/tests/suite/verifreg_remove_datacap_test.rs b/test_vm/tests/suite/verifreg_remove_datacap_test.rs index 0a9cac26c..c1c26a6b8 100644 --- a/test_vm/tests/suite/verifreg_remove_datacap_test.rs +++ b/test_vm/tests/suite/verifreg_remove_datacap_test.rs @@ -7,13 +7,13 @@ use test_vm::TestVM; #[test] fn remove_datacap_simple_successful_path() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); remove_datacap_simple_successful_path_test(&v); } #[test] fn remove_datacap_fails_on_verifreg() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); remove_datacap_fails_on_verifreg_test(&v); } diff --git a/test_vm/tests/suite/withdraw_balance_test.rs b/test_vm/tests/suite/withdraw_balance_test.rs index cc5f688cb..2f906509d 100644 --- a/test_vm/tests/suite/withdraw_balance_test.rs +++ b/test_vm/tests/suite/withdraw_balance_test.rs @@ -3,17 +3,16 @@ use fil_actors_integration_tests::tests::{ }; use fil_actors_runtime::test_blockstores::MemoryBlockstore; use test_vm::TestVM; - #[test] fn withdraw_balance_success() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_balance_success_test(&v); } #[test] fn withdraw_balance_fail() { let store = MemoryBlockstore::new(); - let v = TestVM::new_with_singletons(&store); + let v = TestVM::new_with_singletons(store); withdraw_balance_fail_test(&v); }