@@ -168,6 +168,84 @@ tape('StateManager', (t) => {
168
168
st . end ( )
169
169
}
170
170
)
171
+
172
+ t . test ( 'should modify account fields correctly' , async ( st ) => {
173
+ const stateManager = new DefaultStateManager ( )
174
+ const account = createAccount ( )
175
+ const address = new Address ( Buffer . from ( 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' , 'hex' ) )
176
+ await stateManager . putAccount ( address , account )
177
+
178
+ await stateManager . modifyAccountFields ( address , { balance : new BN ( 1234 ) } )
179
+
180
+ const res1 = await stateManager . getAccount ( address )
181
+
182
+ st . equal ( res1 . balance . toString ( 'hex' ) , '4d2' )
183
+
184
+ await stateManager . modifyAccountFields ( address , { nonce : new BN ( 1 ) } )
185
+
186
+ const res2 = await stateManager . getAccount ( address )
187
+
188
+ st . equal ( res2 . nonce . toNumber ( ) , 1 )
189
+
190
+ await stateManager . modifyAccountFields ( address , {
191
+ codeHash : Buffer . from (
192
+ 'd748bf26ab37599c944babfdbeecf6690801bd61bf2670efb0a34adfc6dca10b' ,
193
+ 'hex'
194
+ ) ,
195
+ stateRoot : Buffer . from (
196
+ 'cafd881ab193703b83816c49ff6c2bf6ba6f464a1be560c42106128c8dbc35e7' ,
197
+ 'hex'
198
+ ) ,
199
+ } )
200
+
201
+ const res3 = await stateManager . getAccount ( address )
202
+
203
+ st . equal (
204
+ res3 . codeHash . toString ( 'hex' ) ,
205
+ 'd748bf26ab37599c944babfdbeecf6690801bd61bf2670efb0a34adfc6dca10b'
206
+ )
207
+ st . equal (
208
+ res3 . stateRoot . toString ( 'hex' ) ,
209
+ 'cafd881ab193703b83816c49ff6c2bf6ba6f464a1be560c42106128c8dbc35e7'
210
+ )
211
+
212
+ st . end ( )
213
+ } )
214
+
215
+ t . test (
216
+ 'should modify account fields correctly on previously non-existent account' ,
217
+ async ( st ) => {
218
+ const stateManager = new DefaultStateManager ( )
219
+ const address = new Address ( Buffer . from ( 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' , 'hex' ) )
220
+
221
+ await stateManager . modifyAccountFields ( address , { balance : new BN ( 1234 ) } )
222
+ const res1 = await stateManager . getAccount ( address )
223
+ st . equal ( res1 . balance . toString ( 'hex' ) , '4d2' )
224
+
225
+ await stateManager . modifyAccountFields ( address , { nonce : new BN ( 1 ) } )
226
+ const res2 = await stateManager . getAccount ( address )
227
+ st . equal ( res2 . nonce . toNumber ( ) , 1 )
228
+
229
+ const newCodeHash = Buffer . from (
230
+ 'd748bf26ab37599c944babfdbeecf6690801bd61bf2670efb0a34adfc6dca10b' ,
231
+ 'hex'
232
+ )
233
+ const newStateRoot = Buffer . from (
234
+ 'cafd881ab193703b83816c49ff6c2bf6ba6f464a1be560c42106128c8dbc35e7' ,
235
+ 'hex'
236
+ )
237
+ await stateManager . modifyAccountFields ( address , {
238
+ codeHash : newCodeHash ,
239
+ stateRoot : newStateRoot ,
240
+ } )
241
+
242
+ const res3 = await stateManager . getAccount ( address )
243
+ st . ok ( res3 . codeHash . equals ( newCodeHash ) )
244
+ st . ok ( res3 . stateRoot . equals ( newStateRoot ) )
245
+ st . end ( )
246
+ }
247
+ )
248
+
171
249
t . test (
172
250
'should generate the genesis state root correctly for mainnet from ethereum/tests data' ,
173
251
async ( st ) => {
0 commit comments