1
- const testUtil = require ( './util' )
2
- const { promisify } = require ( 'util' )
3
1
const ethUtil = require ( 'ethereumjs-util' )
4
- const Account = require ( 'ethereumjs-account' ) . default
5
- const Trie = require ( 'merkle-patricia-tree/secure' )
6
2
const BN = ethUtil . BN
7
- const { getRequiredForkConfigAlias } = require ( './util' )
8
- const StateManager = require ( '../dist/state/stateManager' ) . default
9
-
10
- const VM = require ( '../dist/index.js' ) . default
11
- const PStateManager = require ( '../dist/state/promisified' ) . default
3
+ const { getRequiredForkConfigAlias, setupPreConditions, makeTx, makeBlockFromEnv } = require ( './util' )
4
+ const Account = require ( '@ethereumjs/account' ) . default
5
+ const Trie = require ( 'merkle-patricia-tree' ) . SecureTrie
6
+ const { default : Common } = require ( '@ethereumjs/common' )
7
+ const { default : VM } = require ( '../dist/index.js' )
8
+ const { default : DefaultStateManager } = require ( '../dist/state/stateManager' )
12
9
13
10
async function runTestCase ( options , testData , t ) {
14
11
let expectedPostStateRoot = testData . postStateRoot
@@ -17,8 +14,8 @@ async function runTestCase (options, testData, t) {
17
14
}
18
15
19
16
// Prepare tx and block
20
- let tx = testUtil . makeTx ( testData . transaction )
21
- let block = testUtil . makeBlockFromEnv ( testData . env )
17
+ let tx = makeTx ( testData . transaction )
18
+ let block = makeBlockFromEnv ( testData . env )
22
19
tx . _homestead = true
23
20
tx . enableHomestead = true
24
21
block . isHomestead = function ( ) {
@@ -28,14 +25,15 @@ async function runTestCase (options, testData, t) {
28
25
return
29
26
}
30
27
31
- let stateManager = new StateManager ( )
32
- await promisify ( testUtil . setupPreConditions ) ( stateManager . _trie , testData )
28
+ const common = new Common ( 'mainnet' , options . forkConfigVM . toLowerCase ( ) )
29
+ const stateManager = new DefaultStateManager ( { common : common } )
30
+ await setupPreConditions ( stateManager . _trie , testData )
33
31
const preStateRoot = stateManager . _trie . root
34
32
35
33
// Set up VM
36
34
let vm = new VM ( {
37
35
stateManager : stateManager ,
38
- hardfork : options . forkConfig . toLowerCase ( )
36
+ common : common
39
37
} )
40
38
if ( options . jsontrace ) {
41
39
hookVM ( vm , t )
@@ -94,7 +92,7 @@ async function runTestCase (options, testData, t) {
94
92
try {
95
93
await vm . runTx ( { tx : tx , block : block } )
96
94
} catch ( err ) {
97
- await deleteCoinbase ( new PStateManager ( stateManager ) , block . header . coinbase )
95
+ await deleteCoinbase ( stateManager , block . header . coinbase )
98
96
}
99
97
t . equal ( stateManager . _trie . root . toString ( 'hex' ) , expectedPostStateRoot , 'the state roots should match' )
100
98
}
@@ -104,12 +102,12 @@ async function runTestCase (options, testData, t) {
104
102
* expects the coinbase account to be deleted from state.
105
103
* Without this ecmul_0-3_5616_28000_96 would fail.
106
104
*/
107
- async function deleteCoinbase ( pstate , coinbaseAddr ) {
108
- const account = await pstate . getAccount ( coinbaseAddr )
105
+ async function deleteCoinbase ( stateManager , coinbaseAddr ) {
106
+ const account = await stateManager . getAccount ( coinbaseAddr )
109
107
if ( new BN ( account . balance ) . isZero ( ) ) {
110
- await pstate . putAccount ( coinbaseAddr , new Account ( ) )
111
- await pstate . cleanupTouchedAccounts ( )
112
- await promisify ( pstate . _wrapped . _cache . flush . bind ( pstate . _wrapped . _cache ) ) ( )
108
+ await stateManager . putAccount ( coinbaseAddr , new Account ( ) )
109
+ await stateManager . cleanupTouchedAccounts ( )
110
+ await stateManager . _wrapped . _cache . flush ( )
113
111
}
114
112
}
115
113
@@ -178,7 +176,7 @@ function parseTestCases (forkConfig, testData, data, gasLimit, value) {
178
176
}
179
177
180
178
module . exports = async function runStateTest ( options , testData , t ) {
181
- const forkConfig = getRequiredForkConfigAlias ( options . forkConfig )
179
+ const forkConfig = getRequiredForkConfigAlias ( options . forkConfigTestSuite )
182
180
try {
183
181
const testCases = parseTestCases ( forkConfig , testData , options . data , options . gasLimit , options . value )
184
182
if ( testCases . length > 0 ) {
0 commit comments