Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm/tests: cleanup access to private variables + types #3149

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/vm/test/tester/runners/BlockchainTestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes
await setupPreConditions(vm.stateManager, testData)

t.deepEquals(
(vm.stateManager as any)._trie.root(),
await vm.stateManager.getStateRoot(),
genesisBlock.header.stateRoot,
'correct pre stateRoot'
)
Expand Down Expand Up @@ -193,7 +193,7 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes
// blockchain tests come with their own `pre` world state.
// TODO: Add option to `runBlockchain` not to generate genesis state.
//
//vm.common.genesis().stateRoot = vm.stateManager._trie.root()
//vm.common.genesis().stateRoot = await vm.stateManager.getStateRoot()
try {
await blockchain.iterator('vm', async (block: Block) => {
const parentBlock = await blockchain!.getBlock(block.header.parentHash)
Expand All @@ -217,7 +217,7 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes
if (options.debug !== true) {
// make sure the state is set before checking post conditions
const headBlock = await vm.blockchain.getIteratorHead()
;(vm.stateManager as any)._trie.root(headBlock.header.stateRoot)
await vm.stateManager.setStateRoot(headBlock.header.stateRoot)
} else {
await verifyPostConditions(state, testData.postState, t)
}
Expand Down
11 changes: 5 additions & 6 deletions packages/vm/test/tester/runners/GeneralStateTestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ async function runTestCase(options: any, testData: any, t: tape.Test) {

// Even if no txs are ran, coinbase should always be created
const coinbaseAddress = Address.fromString(testData.env.currentCoinbase)
const account = await (<VM>vm).stateManager.getAccount(coinbaseAddress)
await (<VM>vm).evm.journal.putAccount(coinbaseAddress, account ?? new Account())
const account = await vm.stateManager.getAccount(coinbaseAddress)
await vm.evm.journal.putAccount(coinbaseAddress, account ?? new Account())

const stepHandler = (e: InterpreterStep) => {
let hexStack = []
Expand All @@ -124,7 +124,7 @@ async function runTestCase(options: any, testData: any, t: tape.Test) {

const afterTxHandler = async () => {
const stateRoot = {
stateRoot: bytesToHex((vm.stateManager as any)._trie.root),
stateRoot: bytesToHex(await vm.stateManager.getStateRoot()),
}
t.comment(JSON.stringify(stateRoot))
}
Expand All @@ -149,10 +149,9 @@ async function runTestCase(options: any, testData: any, t: tape.Test) {
}

// Cleanup touched accounts (this wipes coinbase if it is empty on HFs >= TangerineWhistle)
await (<VM>vm).evm.journal.cleanup()
await (<VM>vm).stateManager.getStateRoot() // Ensure state root is updated (flush all changes to trie)
await vm.evm.journal.cleanup()

const stateManagerStateRoot = (vm.stateManager as any)._trie.root()
const stateManagerStateRoot = await vm.stateManager.getStateRoot() // Ensure state root is updated (flush all changes to trie)
const testDataPostStateRoot = toBytes(testData.postStateRoot)
const stateRootsAreEqual = equalsBytes(stateManagerStateRoot, testDataPostStateRoot)

Expand Down
Loading