@@ -18,6 +18,36 @@ tape('StateManager', (t) => {
18
18
st . end ( )
19
19
} )
20
20
21
+ t . test ( 'should clear the cache when the state root is set' , async ( st ) => {
22
+ const stateManager = new StateManager ( )
23
+ const addressBuffer = Buffer . from ( 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' , "hex" )
24
+ const account = createAccount ( )
25
+
26
+ const getStateRoot = promisify ( ( ...args ) => stateManager . getStateRoot ( ...args ) )
27
+ const checkpoint = promisify ( ( ...args ) => stateManager . checkpoint ( ...args ) )
28
+ const putAccount = promisify ( ( ...args ) => stateManager . putAccount ( ...args ) )
29
+ const getAccount = promisify ( ( ...args ) => stateManager . getAccount ( ...args ) )
30
+ const commit = promisify ( ( ...args ) => stateManager . commit ( ...args ) )
31
+ const setStateRoot = promisify ( ( ...args ) => stateManager . setStateRoot ( ...args ) )
32
+
33
+ const initialStateRoot = await getStateRoot ( )
34
+ await checkpoint ( )
35
+ await putAccount ( addressBuffer , account )
36
+
37
+ const account0 = await getAccount ( addressBuffer )
38
+ st . equal ( account0 . balance . toString ( "hex" ) , account . balance . toString ( "hex" ) , 'account value is set in the cache' )
39
+
40
+ await commit ( )
41
+ const account1 = await getAccount ( addressBuffer )
42
+ st . equal ( account1 . balance . toString ( "hex" ) , account . balance . toString ( "hex" ) , 'account value is set in the state trie' )
43
+
44
+ await setStateRoot ( initialStateRoot )
45
+ const account2 = await getAccount ( addressBuffer )
46
+ st . equal ( account2 . balance . toString ( "hex" ) , "" , 'account value is set to 0 in original state root' )
47
+
48
+ st . end ( )
49
+ } )
50
+
21
51
t . test ( 'should put and get account, and add to the underlying cache if the account is not found' , async ( st ) => {
22
52
const stateManager = new StateManager ( )
23
53
const account = createAccount ( )
0 commit comments