1
- use alloy:: consensus :: { SignableTransaction as _ , TxEip1559 , TxEnvelope } ;
2
- use alloy :: network :: Ethereum ;
3
- use alloy :: primitives :: U256 ;
4
- use alloy :: signers :: local :: PrivateKeySigner ;
5
- use alloy :: signers :: SignerSync as _ ;
6
- use alloy :: transports :: http :: { Client , Http } ;
7
- use builder :: config :: WalletlessProvider ;
8
- use builder :: tasks :: simulator :: SimulatorFactory ;
9
- use trevm :: revm :: database :: { AlloyDB , CacheDB } ;
10
- use trevm :: revm :: primitives :: { address , TxKind } ;
1
+ use alloy:: {
2
+ consensus :: { SignableTransaction as _ , TxEip1559 , TxEnvelope } ,
3
+ eips :: BlockId ,
4
+ network :: Ethereum ,
5
+ primitives :: U256 ,
6
+ providers :: { Provider , ProviderBuilder } ,
7
+ signers :: SignerSync as _ ,
8
+ signers :: local :: PrivateKeySigner ,
9
+ } ;
10
+ use builder :: { config :: WalletlessProvider , tasks :: simulator :: SimulatorFactory } ;
11
11
use std:: sync:: Arc ;
12
- use tokio:: sync:: mpsc;
13
- use tokio:: time:: { Duration , Instant } ;
14
- use trevm:: revm:: primitives:: { Account , ExecutionResult , ResultAndState } ;
15
- use alloy:: eips:: BlockId ;
16
- use alloy:: providers:: { Provider , ProviderBuilder } ;
12
+ use tokio:: {
13
+ sync:: mpsc,
14
+ time:: { Duration , Instant } ,
15
+ } ;
16
+ use trevm:: {
17
+ db:: {
18
+ cow:: CacheOnWrite ,
19
+ sync:: { ConcurrentState , ConcurrentStateInfo } ,
20
+ } ,
21
+ revm:: {
22
+ context:: result:: { ExecutionResult , ResultAndState } ,
23
+ database:: { CacheDB , Database , DatabaseCommit , DatabaseRef , AlloyDB , WrapDatabaseAsync } ,
24
+ primitives:: { TxKind , address} ,
25
+ inspector:: NoOpInspector ,
26
+ state:: Account ,
27
+ } ,
28
+ } ;
29
+
30
+ // Define a type alias for the database used with SimulatorFactory.
31
+ type Db = WrapDatabaseAsync < AlloyDB < Ethereum , WalletlessProvider > > ;
17
32
18
33
#[ tokio:: test( flavor = "multi_thread" ) ]
19
34
async fn test_spawn ( ) {
@@ -24,7 +39,7 @@ async fn test_spawn() {
24
39
25
40
// Create a new anvil instance
26
41
let anvil =
27
- alloy:: node_bindings:: Anvil :: new ( ) . block_time ( 1 ) . chain_id ( 17003 ) . try_spawn ( ) . unwrap ( ) ;
42
+ alloy:: node_bindings:: Anvil :: new ( ) . block_time ( 1 ) . chain_id ( 14174 ) . try_spawn ( ) . unwrap ( ) ;
28
43
29
44
// Create a test wallet from the anvil keys
30
45
let keys = anvil. keys ( ) ;
@@ -35,20 +50,19 @@ async fn test_spawn() {
35
50
let latest = root_provider. get_block_number ( ) . await . unwrap ( ) ;
36
51
37
52
// Create an alloyDB from the provider at the latest height
38
- let alloy_db: AlloyDB < Http < Client > , Ethereum , Arc < WalletlessProvider > > =
39
- AlloyDB :: new ( Arc :: new ( root_provider. clone ( ) ) , BlockId :: Number ( latest. into ( ) ) ) . unwrap ( ) ;
40
- let db = CacheDB :: new ( Arc :: new ( alloy_db) ) ;
41
-
42
- // Define trevm extension, if any
43
- let ext = ( ) ;
53
+ let alloy_db: AlloyDB < Ethereum , WalletlessProvider > =
54
+ AlloyDB :: new ( root_provider. clone ( ) , BlockId :: from ( latest) ) ;
44
55
56
+ let wrapped_db = WrapDatabaseAsync :: new ( alloy_db) . unwrap ( ) ;
57
+ let concurrent_db = ConcurrentState :: new ( wrapped_db, ConcurrentStateInfo :: default ( ) ) ;
58
+
45
59
// Define the evaluator function
46
60
let evaluator = Arc :: new ( test_evaluator) ;
47
61
48
62
// Create a simulation factory with the provided DB
49
- let sim_factory = SimulatorFactory :: new ( db , ext ) ;
50
- let handle =
51
- sim_factory. spawn :: < TxEnvelope , _ > ( tx_receiver, evaluator, deadline) ;
63
+ let sim_factory = SimulatorFactory :: new ( concurrent_db , NoOpInspector ) ;
64
+
65
+ let handle = sim_factory. spawn ( tx_receiver, evaluator, deadline) ;
52
66
53
67
// Send some transactions
54
68
for count in 0 ..2 {
0 commit comments