@@ -38,6 +38,7 @@ use fvm_shared::{MethodNum, METHOD_SEND};
3838use serde:: ser;
3939use std:: cell:: { RefCell , RefMut } ;
4040use std:: collections:: { BTreeMap , HashMap } ;
41+ use std:: rc:: Rc ;
4142use vm_api:: trace:: InvocationTrace ;
4243use vm_api:: { new_actor, ActorState , MessageResult , VMError , VM } ;
4344
@@ -50,9 +51,9 @@ mod messaging;
5051pub use messaging:: * ;
5152
5253/// An in-memory rust-execution VM for testing builtin-actors that yields sensible stack traces and debug info
53- pub struct TestVM < ' bs > {
54+ pub struct TestVM {
5455 pub primitives : FakePrimitives ,
55- pub store : & ' bs MemoryBlockstore ,
56+ pub store : Rc < MemoryBlockstore > ,
5657 pub state_root : RefCell < Cid > ,
5758 circulating_supply : RefCell < TokenAmount > ,
5859 actors_dirty : RefCell < bool > ,
@@ -62,13 +63,15 @@ pub struct TestVM<'bs> {
6263 invocations : RefCell < Vec < InvocationTrace > > ,
6364}
6465
65- impl < ' bs > TestVM < ' bs > {
66- pub fn new ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs > {
66+ impl TestVM {
67+ pub fn new ( store : impl Into < Rc < MemoryBlockstore > > ) -> TestVM {
68+ let store = store. into ( ) ;
6769 let mut actors =
68- Hamt :: < & ' bs MemoryBlockstore , ActorState , BytesKey , Sha256 > :: new_with_config (
69- store,
70+ Hamt :: < Rc < MemoryBlockstore > , ActorState , BytesKey , Sha256 > :: new_with_config (
71+ Rc :: clone ( & store) ,
7072 DEFAULT_HAMT_CONFIG ,
7173 ) ;
74+
7275 TestVM {
7376 primitives : FakePrimitives { } ,
7477 store,
@@ -82,15 +85,17 @@ impl<'bs> TestVM<'bs> {
8285 }
8386 }
8487
85- pub fn new_with_singletons ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs > {
88+ pub fn new_with_singletons ( store : impl Into < Rc < MemoryBlockstore > > ) -> TestVM {
8689 let reward_total = TokenAmount :: from_whole ( 1_100_000_000i64 ) ;
8790 let faucet_total = TokenAmount :: from_whole ( 1_000_000_000i64 ) ;
8891
89- let v = TestVM :: < ' _ > :: new ( store) ;
92+ let store = store. into ( ) ;
93+
94+ let v = TestVM :: new ( Rc :: clone ( & store) ) ;
9095 v. set_circulating_supply ( & reward_total + & faucet_total) ;
9196
9297 // system
93- let sys_st = SystemState :: new ( store) . unwrap ( ) ;
98+ let sys_st = SystemState :: new ( & store) . unwrap ( ) ;
9499 let sys_head = v. put_store ( & sys_st) ;
95100 let sys_value = faucet_total. clone ( ) ; // delegate faucet funds to system so we can construct faucet by sending to bls addr
96101 v. set_actor (
@@ -99,7 +104,7 @@ impl<'bs> TestVM<'bs> {
99104 ) ;
100105
101106 // init
102- let init_st = InitState :: new ( store, "integration-test" . to_string ( ) ) . unwrap ( ) ;
107+ let init_st = InitState :: new ( & store, "integration-test" . to_string ( ) ) . unwrap ( ) ;
103108 let init_head = v. put_store ( & init_st) ;
104109 v. set_actor (
105110 & INIT_ACTOR_ADDR ,
@@ -239,9 +244,9 @@ impl<'bs> TestVM<'bs> {
239244 pub fn checkpoint ( & self ) -> Cid {
240245 // persist cache on top of latest checkpoint and clear
241246 let mut actors =
242- Hamt :: < & ' bs MemoryBlockstore , ActorState , BytesKey , Sha256 > :: load_with_config (
247+ Hamt :: < Rc < MemoryBlockstore > , ActorState , BytesKey , Sha256 > :: load_with_config (
243248 & self . state_root . borrow ( ) ,
244- self . store ,
249+ Rc :: clone ( & self . store ) ,
245250 DEFAULT_HAMT_CONFIG ,
246251 )
247252 . unwrap ( ) ;
@@ -275,9 +280,9 @@ impl<'bs> TestVM<'bs> {
275280 }
276281}
277282
278- impl < ' bs > VM for TestVM < ' bs > {
283+ impl VM for TestVM {
279284 fn blockstore ( & self ) -> & dyn Blockstore {
280- self . store
285+ self . store . as_ref ( )
281286 }
282287
283288 fn epoch ( & self ) -> ChainEpoch {
@@ -364,7 +369,7 @@ impl<'bs> VM for TestVM<'bs> {
364369 }
365370 fn resolve_id_address ( & self , address : & Address ) -> Option < Address > {
366371 let st: InitState = get_state ( self , & INIT_ACTOR_ADDR ) . unwrap ( ) ;
367- st. resolve_address ( self . store , address) . unwrap ( )
372+ st. resolve_address ( & self . store , address) . unwrap ( )
368373 }
369374
370375 fn set_epoch ( & self , epoch : ChainEpoch ) {
@@ -386,9 +391,9 @@ impl<'bs> VM for TestVM<'bs> {
386391 return Some ( act. clone ( ) ) ;
387392 }
388393 // go to persisted map
389- let actors = Hamt :: < & ' bs MemoryBlockstore , ActorState , BytesKey , Sha256 > :: load_with_config (
394+ let actors = Hamt :: < Rc < MemoryBlockstore > , ActorState , BytesKey , Sha256 > :: load_with_config (
390395 & self . state_root . borrow ( ) ,
391- self . store ,
396+ Rc :: clone ( & self . store ) ,
392397 DEFAULT_HAMT_CONFIG ,
393398 )
394399 . unwrap ( ) ;
0 commit comments