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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM/tests: ensure verifyPostConditions works #1900

Merged
merged 3 commits into from May 26, 2022
Merged

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented May 23, 2022

If a blockchain test fails and we have the --debug flag on, we expect that we do verifyPostConditions:

await verifyPostConditions(state, testData.postState, t)

However, this actually does not work. If the block is invalid and produces a different stateRoot than whatever we expect, then runBlockchain actually throws and the verifyPostConditions is never ran.

This PR also updates the formatter such that it is easier to read what goes wrong. On a VM which I intentially made producing wrong output:

Screenshot from 2022-05-23 23-21-05

(Was done by adding this to runBlock.ts:)

Screenshot from 2022-05-23 23-25-17

If the tests contain the postConditions we can now very quickly figure out what goes wrong if a test files 馃槃

@jochem-brouwer jochem-brouwer added PR state: WIP type: tests package: vm type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR. labels May 23, 2022
@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #1900 (f3a28d2) into master (a133e27) will decrease coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

Flag Coverage 螖
block 85.57% <酶> (酶)
blockchain 83.82% <酶> (酶)
client 76.88% <酶> (-0.08%) 猬囷笍
common 94.19% <酶> (酶)
devp2p 82.49% <酶> (-0.14%) 猬囷笍
ethash 90.76% <酶> (酶)
trie 80.02% <酶> (酶)
tx 88.22% <酶> (酶)
util 92.62% <酶> (酶)
vm 81.00% <酶> (酶)

Flags with carried forward coverage won't be shown. Click here to find out more.

@jochem-brouwer
Copy link
Member Author

jochem-brouwer commented May 25, 2022

Updated this one, sample messages:

# Account: 0x8888f1f195afa192cfee860698584c030f4c9db1
# Expected balance of 30312500000000021000, but got 30312500000000020999
# Expected nonce of 0, but got 1
# Account: 0x0000000000000000000000000000000000000011
# Account: 0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b
# Account: 0xb94f5374fce5ed0000000097c15331677e6ebf0b
# Account: 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b
# Expected storage key 0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563 to have value 0x, but got 0x01}

There are some gotcha's in the diffs, will comment.

@@ -144,14 +144,14 @@ export async function verifyPostConditions(state: any, testData: any, t: tape.Te
const promise = verifyAccountPostConditions(state, address, account, testData, t)
queue.push(promise)
} else {
t.fail('invalid account in the trie: ' + <string>key)
t.comment('invalid account in the trie: ' + <string>key)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted all tape commands to comment. The reason is that if you have failing tests, then this adds to the number of tests counter. Let's say we accidentally do not run some tests, then --verify-amount-alltests flag could still pass while this is actually not the case.

Also note that if any of these comments get triggered, then the state root of the block is wrong, so the test fails anyways.

})
if (val !== hashedStorage[key]) {
t.comment(
`Expected storage key 0x${data.key.toString('hex')} at address ${address} to have value ${
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to add address here since it is not clear when these promises are fulfilled.

@@ -188,38 +195,40 @@ export function verifyAccountPostConditions(
] = acctData.storage[key]
}

if (storageKeys.length > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this if statement: if there is no storage in the postState but we somehow still store something, then we should detect that anyways.

@jochem-brouwer jochem-brouwer marked this pull request as ready for review May 25, 2022 20:39
Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, lgtm!

@holgerd77
Copy link
Member

Updated this via rebase (via Web UI).

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holgerd77 holgerd77 merged commit 2b993aa into master May 26, 2022
@holgerd77 holgerd77 deleted the blockchain-tester-update branch May 26, 2022 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: vm PR state: needs review type: test all hardforks This special label enables VM state and blockchain tests for all hardforks on the respective PR. type: tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants