@@ -4,7 +4,7 @@ const util = require('ethereumjs-util')
4
4
const StateManager = require ( '../../lib/stateManager' )
5
5
const { createAccount } = require ( './utils' )
6
6
7
- tape ( 'StateManager' , ( t ) => {
7
+ tape . only ( 'StateManager' , ( t ) => {
8
8
t . test ( 'should instantiate' , ( st ) => {
9
9
const stateManager = new StateManager ( )
10
10
@@ -18,7 +18,7 @@ tape('StateManager', (t) => {
18
18
st . end ( )
19
19
} )
20
20
21
- t . test ( 'should put and get account' , async ( st ) => {
21
+ t . test ( 'should put and get account, and add to the underlying cache if the account is not found ' , async ( st ) => {
22
22
const stateManager = new StateManager ( )
23
23
const account = createAccount ( )
24
24
@@ -32,6 +32,79 @@ tape('StateManager', (t) => {
32
32
)
33
33
34
34
st . equal ( res . balance . toString ( 'hex' ) , 'fff384' )
35
+
36
+ stateManager . cache . clear ( )
37
+
38
+ res = await promisify ( stateManager . getAccount . bind ( stateManager ) ) (
39
+ 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b'
40
+ )
41
+
42
+ st . equal ( stateManager . cache . _cache . keys [ 0 ] , 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' )
43
+
44
+ st . end ( )
45
+ } )
46
+
47
+ t . test ( 'should retrieve a cached account, without adding to the underlying cache if the account is not found' , async ( st ) => {
48
+ const stateManager = new StateManager ( )
49
+ const account = createAccount ( )
50
+
51
+ await promisify ( stateManager . putAccount . bind ( stateManager ) ) (
52
+ 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' ,
53
+ account
54
+ )
55
+
56
+ let res = await promisify ( stateManager . getAccountPure . bind ( stateManager ) ) (
57
+ 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b'
58
+ )
59
+
60
+ st . equal ( res . balance . toString ( 'hex' ) , 'fff384' )
61
+
62
+ stateManager . cache . clear ( )
63
+
64
+ res = await promisify ( stateManager . getAccountPure . bind ( stateManager ) ) (
65
+ 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b'
66
+ )
67
+
68
+ st . notOk ( stateManager . cache . _cache . keys [ 0 ] )
69
+
70
+ st . end ( )
71
+ } )
72
+
73
+ t . test ( 'should call the callback with a boolean representing emptiness, and not cache the account if passed correct params' , async ( st ) => {
74
+ const stateManager = new StateManager ( )
75
+
76
+ const promisifiedAccountIsEmpty = promisify ( stateManager . accountIsEmpty . bind ( stateManager ) , function ( err , result ) {
77
+ return err || result
78
+ } )
79
+ let res = await promisifiedAccountIsEmpty ( 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' , true )
80
+
81
+ st . ok ( res )
82
+ st . notOk ( stateManager . cache . _cache . keys [ 0 ] )
83
+
84
+ let res2 = await promisifiedAccountIsEmpty ( '0x095e7baea6a6c7c4c2dfeb977efac326af552d87' )
85
+
86
+ st . ok ( res2 )
87
+ st . equal ( stateManager . cache . _cache . keys [ 0 ] , '0x095e7baea6a6c7c4c2dfeb977efac326af552d87' )
88
+
89
+ st . end ( )
90
+ } )
91
+
92
+ t . test ( 'should call the callback with a false boolean representing emptiness when the account is empty' , async ( st ) => {
93
+ const stateManager = new StateManager ( )
94
+ const account = createAccount ( '0x1' , '0x1' )
95
+
96
+ await promisify ( stateManager . putAccount . bind ( stateManager ) ) (
97
+ 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' ,
98
+ account
99
+ )
100
+
101
+ const promisifiedAccountIsEmpty = promisify ( stateManager . accountIsEmpty . bind ( stateManager ) , function ( err , result ) {
102
+ return err || result
103
+ } )
104
+ let res = await promisifiedAccountIsEmpty ( 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' , true )
105
+
106
+ st . notOk ( res )
107
+
35
108
st . end ( )
36
109
} )
37
110
} )
0 commit comments