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

Use the state tests embedded in the blockchain tests #1577

Merged
merged 7 commits into from
Dec 12, 2018

Conversation

lithp
Copy link
Contributor

@lithp lithp commented Dec 11, 2018

When state tests fail they tell you the root state hash has changed, but there's no easy way of telling which parts of the state have changed. However, a copy of the state tests is also available under the blockchain tests, and that copy includes the full expected state tree.

This PR changes which version of the state tests are run. In combination with #1573 this should make diagnosing test failures much easier.

  • test_state.py skipped some tests which take too long to run, those changes are now reproduced in test_blockchain.py
  • test_blockchain.py now also supports the --fork flag, to allow running just a subset of the tests
  • the tox commands have been updated to only run blockchain tests, not the state tests.
  • circleci has been updated in-step with tox
  • SLOWEST_TESTS has been regenerated. There are now more tests (each of the indexes appears as a separate blockchain test) so the list is a little longer now. The 60ish tests skipped here (out of 10851) account for 15 of the 21 minutes it takes to run the test suite on my machine.

Cute Animal Picture

kitten

@lithp lithp force-pushed the lithp/use-blockchain-state-tests branch 2 times, most recently from 7ee7041 to a8b1a74 Compare December 11, 2018 23:07
@lithp lithp force-pushed the lithp/use-blockchain-state-tests branch from b767a6e to 5c15617 Compare December 12, 2018 02:52
@@ -34,6 +36,84 @@
BASE_FIXTURE_PATH = os.path.join(ROOT_PROJECT_DIR, 'fixtures', 'BlockchainTests')


# These are the slowest tests from the full blockchain test run. This list
# should be regenerated occasionally using `--durations 100`.
SLOWEST_TESTS = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR but just as an idea: Isn't there something in Circle CI that we can differentiate between CI runs for PRs and CI runs on master? I think it would be nice if we could at least achieve that all these tests run from time to time. So that, even if we don't get immediate feedback that our PR broke one of these, we at least get notified about it some time after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible with Travis and I would be surprised if it wasn't also possible with Circle CI. It could be nice to have a nightly build which takes master and runs all the tests, and maybe even does benchmarking?

Copy link
Member

Choose a reason for hiding this comment

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

I dug around a bit and couldn't find anything in the CircleCI interface to do this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CircleCI exposes some useful environment variables such as CIRCLE_PULL_REQUEST and CIRCLE_BRANCH you could use to detect whether you're building a branch or not.

I've opened a PR which attempts to schedule a nightly build which runs all the tests, even the slowest ones.

Copy link
Contributor

@cburgdorf cburgdorf left a comment

Choose a reason for hiding this comment

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

This looks good to me. I would feel a bit better if I knew the reason why the GeneralStateTests exist twice 😅

@@ -1,10 +1,10 @@
[tox]
envlist=
py{35,36}-{core,database,transactions,vm,native-blockchain}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still a bit confused why the GeneralStateTests also exists outside of the BlockchainTest and if there is something we might be forgetting about dropping those. Do you know why they exist in the first place? Did you check if the number of tests that are run still matches after this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Upstream docs:

https://ethereum-tests.readthedocs.io/en/latest/test_types/state_tests.html
https://ethereum-tests.readthedocs.io/en/latest/test_types/blockchain_tests.html

So, you should be confused as to why GeneralStateTests exist inside BlockchainTests, not the other way around. ^_^

Anyway, according to the docs, all of the former should eventually make their way into the latter:

https://ethereum-tests.readthedocs.io/en/latest/generating-tests.html#advanced-converting-a-generalstatetest-case-into-a-blockchaintest-case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wish I had taken better notes, I saw somewhere that winsvega wanted to remove the state tests entirely, given that they've been duplicated to the blockchain tests. I neglected to save the link unfortunately.

And that last link is a little scary. It's possible that there's been an error in test generation and that some of the state tests are missing from BlockchainTests/GeneralStateTests, but the idea is definitely that they be perfect duplicates.

@carver
Copy link
Contributor

carver commented Dec 12, 2018

I just did a quick scan, and I'm missing something: what happened to the blockchain tests that are not in the state tests. Are they distributed in the different forks now?

@veox
Copy link
Contributor

veox commented Dec 12, 2018

@carver Good question. You mean like this one?..

pytest -k 'test_blockchain_fixtures[/home/veox/src/py-evm/fixtures/BlockchainTests/bcUncleTest/uncleWithSameBlockNumber.json:uncleWithSameBlockNumber_Homestead]'

They are in the same submodule that gets pulled in as fixtures.

(I haven't tested this particular PR yet, and whether it has inadvertently removed something.)

Copy link
Contributor

@carver carver left a comment

Choose a reason for hiding this comment

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

Just marking this 👎 so no one merges by accident while we confirm that none of the blockchain tests got dropped.

- py36-native-state-frontier
- py36-native-state-homestead
- py36-native-state-eip150
- py36-native-state-eip158
Copy link
Contributor

@carver carver Dec 12, 2018

Choose a reason for hiding this comment

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

These are still state tests, they just happen to be in a different folder. I think the job name could stay the same. But it's a minor opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're blockchain tests now! Blockchain tests which happen to also contain state tests. The command for this specific one is now:

native-blockchain-eip158: pytest {posargs:tests/json-fixtures/test_blockchain.py --fork EIP158}

Copy link
Member

Choose a reason for hiding this comment

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

Somewhat orthogonal but it would be good to rename the EIPXXX to their long form fork names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are their long form fork names? The EIP's page just calls it 158 and doesn't say when it was scheduled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

150 is apparently Tangerine Whistle and yeah, that name is 200% more exciting than EIP-150 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want me to do that in this PR?

Copy link
Member

Choose a reason for hiding this comment

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

I think "Spurious Dragon" is the other one. Look in eth.vm.forks and you can find them (and there should be things within each module to hint at which EIPXXX they correspond to.

@@ -35,14 +35,13 @@ commands=
rpc-state-quadratic: pytest {posargs:tests/trinity/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and stQuadraticComplexityTest'}
transactions: pytest {posargs:tests/json-fixtures/test_transactions.py}
vm: pytest {posargs:tests/json-fixtures/test_virtual_machine.py}
native-blockchain: pytest {posargs:tests/json-fixtures/test_blockchain.py}
Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. You mean like this one?..

pytest -k 'test_blockchain_fixtures[/home/veox/src/py-evm/fixtures/BlockchainTests/bcUncleTest/uncleWithSameBlockNumber.json:uncleWithSameBlockNumber_Homestead]'

They are in the same submodule that gets pulled in as fixtures.

(I haven't tested this particular PR yet, and whether it has inadvertently removed something.)

@veox right, the complete removal of this test (non-state blockchain tests) is what threw me off. Just wanted to make sure we had confirmation that nothing got dropped in the refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

A weak indicator is bcForkStressTest/ForkStressTest.json making it into the list of slowest tests:

https://github.com/ethereum/py-evm/pull/1577/files#diff-c5ffb862ee7554c09f7aea9d6f6a679aR75

(Got to run right now, so can't take a proper look.)

Copy link
Contributor Author

@lithp lithp Dec 12, 2018

Choose a reason for hiding this comment

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

SLOWEST_TESTS isn't a great indication because I generated those myself and didn't use tox/circleci. But here's proof that regular blockchain tests are being run:

(py-evm-ojdIf4Yr) brian@rhythm:~/ef/py-evm$ pytest tests/json-fixtures/test_blockchain.py --fork Byzantium --collect-only | grep -v GeneralStateTests | head
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-3.6.4, py-1.7.0, pluggy-0.7.1
rootdir: /home/brian/ef/py-evm, inifile: pytest.ini
plugins: xdist-1.18.1, profiling-1.3.0, cov-2.5.1, asyncio-0.9.0, asyncio-network-simulator-0.1.0a2, hypothesis-3.69.5
collected 4945 items
<Module 'tests/json-fixtures/test_blockchain.py'>
  <Function 'test_blockchain_fixtures[/home/brian/ef/py-evm/fixtures/BlockchainTests/bcBlockGasLimitTest/BlockGasLimit2p63m1.json:BlockGasLimit2p63m1_Byzantium:Byzantium]'>
  <Function 'test_blockchain_fixtures[/home/brian/ef/py-evm/fixtures/BlockchainTests/bcBlockGasLimitTest/GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst.json:GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst_Byzantium:Byzantium]'>
  <Function 'test_blockchain_fixtures[/home/brian/ef/py-evm/fixtures/BlockchainTests/bcBlockGasLimitTest/GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideLast.json:GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideLast_Byzantium:Byzantium]'>
  <Function 'test_blockchain_fixtures[/home/brian/ef/py-evm/fixtures/BlockchainTests/bcBlockGasLimitTest/SuicideTransaction.json:SuicideTransaction_Byzantium:Byzantium]'>

Each of these native-blockchain-* jobs is now running all the blockchain tests for a given fork, which (primarily) includes state tests, but also includes the blockchain tests which were previously being run by the native-blockchain job.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only way we would be missing some tests would be if this collection of forks doesn't cover the full set of blockchain tests: frontier, homestead, eip150, eip158, byzantium, constantinople, metropolis. Let me think of a way to test whether that's true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well shucks, looks like we're missing some tests:

(py-evm-ojdIf4Yr) brian@rhythm:~/ef/py-evm$ pytest tests/json-fixtures/test_blockchain.py --collect-only 2>/dev/null | grep -oP '\[\K.*(?=\])' | cut -d':' -f3 | sort | uniq
Byzantium
Constantinople
EIP150
EIP158
EIP158ToByzantiumAt5
Frontier
FrontierToHomesteadAt5
Homestead
HomesteadToDaoAt5
HomesteadToEIP150At5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, thanks for catching this Carver! I've pushed a commit which adds the missing tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, well I pretty much just pointed and grumbled. Thanks for hunting it down!

@lithp lithp force-pushed the lithp/use-blockchain-state-tests branch from 86fa931 to 9d28e83 Compare December 12, 2018 19:03
@carver carver merged commit 10d62b5 into ethereum:master Dec 12, 2018
@lithp lithp deleted the lithp/use-blockchain-state-tests branch December 12, 2018 22:43
veox added a commit to veox/trinity that referenced this pull request May 16, 2019
Mostly a copy-paste from `py-evm` codebase; relevant PRs that
introduced the functionality there:

ethereum/py-evm#1470
ethereum/py-evm#1577
veox added a commit to veox/trinity that referenced this pull request May 20, 2019
Mostly a copy-paste from `py-evm` codebase; relevant PRs that
introduced the functionality there:

ethereum/py-evm#1470
ethereum/py-evm#1577
veox added a commit to veox/trinity that referenced this pull request May 21, 2019
Mostly a copy-paste from `py-evm` codebase; relevant PRs that
introduced the functionality there:

ethereum/py-evm#1470
ethereum/py-evm#1577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants