1- const testUtil = require ( './util' )
2- const { promisify } = require ( 'util' )
1+ const { getRequiredForkConfigAlias, setupPreConditions, makeTx, makeBlockFromEnv } = require ( './util' )
32const ethUtil = require ( 'ethereumjs-util' )
4- const Account = require ( 'ethereumjs- account' ) . default
5- const Trie = require ( 'merkle-patricia-tree/secure' )
3+ const Account = require ( '@ ethereumjs/ account' ) . default
4+ const Trie = require ( 'merkle-patricia-tree' ) . SecureTrie
65const BN = ethUtil . BN
7- const { getRequiredForkConfigAlias } = require ( './util' )
6+ const { } = require ( './util' )
7+ const { default : Common } = require ( '@ethereumjs/common' )
88const StateManager = require ( '../dist/state/stateManager' ) . default
99
1010const VM = require ( '../dist/index.js' ) . default
11- const PStateManager = require ( '../dist/state/promisified ' ) . default
11+ const DefaultStateManager = require ( '../dist/state/stateManager ' ) . default
1212
1313async function runTestCase ( options , testData , t ) {
1414 let expectedPostStateRoot = testData . postStateRoot
@@ -17,8 +17,8 @@ async function runTestCase (options, testData, t) {
1717 }
1818
1919 // Prepare tx and block
20- let tx = testUtil . makeTx ( testData . transaction )
21- let block = testUtil . makeBlockFromEnv ( testData . env )
20+ let tx = makeTx ( testData . transaction )
21+ let block = makeBlockFromEnv ( testData . env )
2222 tx . _homestead = true
2323 tx . enableHomestead = true
2424 block . isHomestead = function ( ) {
@@ -28,14 +28,15 @@ async function runTestCase (options, testData, t) {
2828 return
2929 }
3030
31- let stateManager = new StateManager ( )
32- await promisify ( testUtil . setupPreConditions ) ( stateManager . _trie , testData )
31+ const common = new Common ( 'mainnet' , options . forkConfigVM . toLowerCase ( ) )
32+ const stateManager = new DefaultStateManager ( { common : common } )
33+ await setupPreConditions ( stateManager . _trie , testData )
3334 const preStateRoot = stateManager . _trie . root
3435
3536 // Set up VM
3637 let vm = new VM ( {
3738 stateManager : stateManager ,
38- hardfork : options . forkConfig . toLowerCase ( )
39+ common : common
3940 } )
4041 if ( options . jsontrace ) {
4142 hookVM ( vm , t )
@@ -94,7 +95,7 @@ async function runTestCase (options, testData, t) {
9495 try {
9596 await vm . runTx ( { tx : tx , block : block } )
9697 } catch ( err ) {
97- await deleteCoinbase ( new PStateManager ( stateManager ) , block . header . coinbase )
98+ await deleteCoinbase ( stateManager , block . header . coinbase )
9899 }
99100 t . equal ( stateManager . _trie . root . toString ( 'hex' ) , expectedPostStateRoot , 'the state roots should match' )
100101}
@@ -104,12 +105,12 @@ async function runTestCase (options, testData, t) {
104105 * expects the coinbase account to be deleted from state.
105106 * Without this ecmul_0-3_5616_28000_96 would fail.
106107 */
107- async function deleteCoinbase ( pstate , coinbaseAddr ) {
108- const account = await pstate . getAccount ( coinbaseAddr )
108+ async function deleteCoinbase ( stateManager , coinbaseAddr ) {
109+ const account = await stateManager . getAccount ( coinbaseAddr )
109110 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 ) ) ( )
111+ await stateManager . putAccount ( coinbaseAddr , new Account ( ) )
112+ await stateManager . cleanupTouchedAccounts ( )
113+ await stateManager . _wrapped . _cache . flush ( )
113114 }
114115}
115116
@@ -178,7 +179,7 @@ function parseTestCases (forkConfig, testData, data, gasLimit, value) {
178179}
179180
180181module . exports = async function runStateTest ( options , testData , t ) {
181- const forkConfig = getRequiredForkConfigAlias ( options . forkConfig )
182+ const forkConfig = getRequiredForkConfigAlias ( options . forkConfigTestSuite )
182183 try {
183184 const testCases = parseTestCases ( forkConfig , testData , options . data , options . gasLimit , options . value )
184185 if ( testCases . length > 0 ) {
0 commit comments