@@ -38,6 +38,7 @@ use fvm_shared::{MethodNum, METHOD_SEND};
38
38
use serde:: ser;
39
39
use std:: cell:: { RefCell , RefMut } ;
40
40
use std:: collections:: { BTreeMap , HashMap } ;
41
+ use std:: rc:: Rc ;
41
42
use vm_api:: trace:: InvocationTrace ;
42
43
use vm_api:: { new_actor, ActorState , MessageResult , VMError , VM } ;
43
44
@@ -50,9 +51,9 @@ mod messaging;
50
51
pub use messaging:: * ;
51
52
52
53
/// 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 {
54
55
pub primitives : FakePrimitives ,
55
- pub store : & ' bs MemoryBlockstore ,
56
+ pub store : Rc < MemoryBlockstore > ,
56
57
pub state_root : RefCell < Cid > ,
57
58
circulating_supply : RefCell < TokenAmount > ,
58
59
actors_dirty : RefCell < bool > ,
@@ -62,13 +63,15 @@ pub struct TestVM<'bs> {
62
63
invocations : RefCell < Vec < InvocationTrace > > ,
63
64
}
64
65
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 ( ) ;
67
69
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) ,
70
72
DEFAULT_HAMT_CONFIG ,
71
73
) ;
74
+
72
75
TestVM {
73
76
primitives : FakePrimitives { } ,
74
77
store,
@@ -82,15 +85,17 @@ impl<'bs> TestVM<'bs> {
82
85
}
83
86
}
84
87
85
- pub fn new_with_singletons ( store : & ' bs MemoryBlockstore ) -> TestVM < ' bs > {
88
+ pub fn new_with_singletons ( store : impl Into < Rc < MemoryBlockstore > > ) -> TestVM {
86
89
let reward_total = TokenAmount :: from_whole ( 1_100_000_000i64 ) ;
87
90
let faucet_total = TokenAmount :: from_whole ( 1_000_000_000i64 ) ;
88
91
89
- let v = TestVM :: < ' _ > :: new ( store) ;
92
+ let store = store. into ( ) ;
93
+
94
+ let v = TestVM :: new ( Rc :: clone ( & store) ) ;
90
95
v. set_circulating_supply ( & reward_total + & faucet_total) ;
91
96
92
97
// system
93
- let sys_st = SystemState :: new ( store) . unwrap ( ) ;
98
+ let sys_st = SystemState :: new ( & store) . unwrap ( ) ;
94
99
let sys_head = v. put_store ( & sys_st) ;
95
100
let sys_value = faucet_total. clone ( ) ; // delegate faucet funds to system so we can construct faucet by sending to bls addr
96
101
v. set_actor (
@@ -99,7 +104,7 @@ impl<'bs> TestVM<'bs> {
99
104
) ;
100
105
101
106
// 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 ( ) ;
103
108
let init_head = v. put_store ( & init_st) ;
104
109
v. set_actor (
105
110
& INIT_ACTOR_ADDR ,
@@ -239,9 +244,9 @@ impl<'bs> TestVM<'bs> {
239
244
pub fn checkpoint ( & self ) -> Cid {
240
245
// persist cache on top of latest checkpoint and clear
241
246
let mut actors =
242
- Hamt :: < & ' bs MemoryBlockstore , ActorState , BytesKey , Sha256 > :: load_with_config (
247
+ Hamt :: < Rc < MemoryBlockstore > , ActorState , BytesKey , Sha256 > :: load_with_config (
243
248
& self . state_root . borrow ( ) ,
244
- self . store ,
249
+ Rc :: clone ( & self . store ) ,
245
250
DEFAULT_HAMT_CONFIG ,
246
251
)
247
252
. unwrap ( ) ;
@@ -275,9 +280,9 @@ impl<'bs> TestVM<'bs> {
275
280
}
276
281
}
277
282
278
- impl < ' bs > VM for TestVM < ' bs > {
283
+ impl VM for TestVM {
279
284
fn blockstore ( & self ) -> & dyn Blockstore {
280
- self . store
285
+ self . store . as_ref ( )
281
286
}
282
287
283
288
fn epoch ( & self ) -> ChainEpoch {
@@ -364,7 +369,7 @@ impl<'bs> VM for TestVM<'bs> {
364
369
}
365
370
fn resolve_id_address ( & self , address : & Address ) -> Option < Address > {
366
371
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 ( )
368
373
}
369
374
370
375
fn set_epoch ( & self , epoch : ChainEpoch ) {
@@ -386,9 +391,9 @@ impl<'bs> VM for TestVM<'bs> {
386
391
return Some ( act. clone ( ) ) ;
387
392
}
388
393
// 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 (
390
395
& self . state_root . borrow ( ) ,
391
- self . store ,
396
+ Rc :: clone ( & self . store ) ,
392
397
DEFAULT_HAMT_CONFIG ,
393
398
)
394
399
. unwrap ( ) ;
0 commit comments