1- const testUtil = require ( './util' )
2- const { promisify } = require ( 'util' )
31const ethUtil = require ( 'ethereumjs-util' )
4- const Account = require ( 'ethereumjs-account' ) . default
5- const Trie = require ( 'merkle-patricia-tree/secure' )
62const 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' )
129
1310async function runTestCase ( options , testData , t ) {
1411 let expectedPostStateRoot = testData . postStateRoot
@@ -17,8 +14,8 @@ async function runTestCase (options, testData, t) {
1714 }
1815
1916 // 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 )
2219 tx . _homestead = true
2320 tx . enableHomestead = true
2421 block . isHomestead = function ( ) {
@@ -28,14 +25,15 @@ async function runTestCase (options, testData, t) {
2825 return
2926 }
3027
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 )
3331 const preStateRoot = stateManager . _trie . root
3432
3533 // Set up VM
3634 let vm = new VM ( {
3735 stateManager : stateManager ,
38- hardfork : options . forkConfig . toLowerCase ( )
36+ common : common
3937 } )
4038 if ( options . jsontrace ) {
4139 hookVM ( vm , t )
@@ -94,7 +92,7 @@ async function runTestCase (options, testData, t) {
9492 try {
9593 await vm . runTx ( { tx : tx , block : block } )
9694 } catch ( err ) {
97- await deleteCoinbase ( new PStateManager ( stateManager ) , block . header . coinbase )
95+ await deleteCoinbase ( stateManager , block . header . coinbase )
9896 }
9997 t . equal ( stateManager . _trie . root . toString ( 'hex' ) , expectedPostStateRoot , 'the state roots should match' )
10098}
@@ -104,12 +102,12 @@ async function runTestCase (options, testData, t) {
104102 * expects the coinbase account to be deleted from state.
105103 * Without this ecmul_0-3_5616_28000_96 would fail.
106104 */
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 )
109107 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 ( )
113111 }
114112}
115113
@@ -178,7 +176,7 @@ function parseTestCases (forkConfig, testData, data, gasLimit, value) {
178176}
179177
180178module . exports = async function runStateTest ( options , testData , t ) {
181- const forkConfig = getRequiredForkConfigAlias ( options . forkConfig )
179+ const forkConfig = getRequiredForkConfigAlias ( options . forkConfigTestSuite )
182180 try {
183181 const testCases = parseTestCases ( forkConfig , testData , options . data , options . gasLimit , options . value )
184182 if ( testCases . length > 0 ) {
0 commit comments