-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
Add blocktests as go tests #750
Closed
Gustav-Simonsson
wants to merge
8
commits into
ethereum:develop
from
Gustav-Simonsson:add_blocktests_as_go_tests
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d508303
eth: use NewDB hook also for extra DB
fjl 21c4c15
eth: honour config.Shh
fjl 898ba87
cmd/geth, tests: enable running multiple tests from a single file
fjl 2e5a0f3
core, eth: add missing shutdown synchronization to ChainManager
fjl e7608c0
blockpool: add missing shutdown synchronization
fjl 035a30a
tests: hopefully improve test conversion helpers
fjl 7c3319f
Merge remote-tracking branch 'felix/blocktest-parsing-fix' into HEAD
89f7566
Add block tests wrapper and fixes for tx tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package tests | ||
|
||
// TODO: figure out how to move this file to tests package and get imports working there | ||
import ( | ||
// "os" | ||
"path" | ||
|
||
// TODO: refactor to avoid depending on CLI stuff | ||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/eth" | ||
"github.com/ethereum/go-ethereum/ethdb" | ||
"testing" | ||
) | ||
|
||
// TODO: refactor test setup & execution to better align with vm and tx tests | ||
// TODO: refactor to avoid duplication with cmd/geth/blocktest.go | ||
func TestBcValidBlockTests(t *testing.T) { | ||
//dir, _ := os.Getwd() | ||
//t.Logf("CWD: ", dir) | ||
runBlockTestsInFile("files/BlockTests/bcValidBlockTest.json", t) | ||
} | ||
|
||
func runBlockTestsInFile(filepath string, t *testing.T) { | ||
bt, err := LoadBlockTests(filepath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, test := range bt { | ||
runBlockTest(test, t) | ||
} | ||
} | ||
|
||
func runBlockTest(test *BlockTest, t *testing.T) { | ||
cfg := testEthConfig() | ||
ethereum, err := eth.New(cfg) | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
err = ethereum.Start() | ||
if err != nil { | ||
t.Fatalf("%v", err) | ||
} | ||
|
||
// import the genesis block | ||
ethereum.ResetWithGenesisBlock(test.Genesis) | ||
|
||
// import pre accounts | ||
statedb, err := test.InsertPreState(ethereum.StateDb()) | ||
if err != nil { | ||
t.Fatalf("InsertPreState: %v", err) | ||
} | ||
|
||
// insert the test blocks, which will execute all transactions | ||
if err := test.InsertBlocks(ethereum.ChainManager()); err != nil { | ||
t.Fatalf("Block Test load error: %v %T", err, err) | ||
} | ||
t.Log("chain loaded") | ||
|
||
if err := test.ValidatePostState(statedb); err != nil { | ||
t.Fatal("post state validation failed: %v", err) | ||
} | ||
t.Log("Block Test post state validated.") | ||
} | ||
|
||
func testEthConfig() *eth.Config { | ||
ks := crypto.NewKeyStorePassphrase(path.Join(common.DefaultDataDir(), "keys")) | ||
|
||
return ð.Config{ | ||
DataDir: common.DefaultDataDir(), | ||
LogLevel: 5, | ||
Etherbase: "primary", | ||
AccountManager: accounts.NewManager(ks), | ||
NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() }, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, these sort of changes need to be well documented. Second I suggest you find some other way to solve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these changes while working out a crash in the tests together with Gustav. The blockpool was crashing because it didn't expect to be started and stopped in short succession.
While looking at the source of the events, I found that
ChainManager
now has a background goroutine which is never stopped. The changes ensure that it is stopped, and also that stopping blocks until the loop is down.sync.WaitGroup
is the canonical way to wait for one or more goroutines to end. But it could also be done with a channel, if you prefer that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, the issue doesn't really exist anymore because the blockpool is no longer used. It would still be preferable to fix
ChainManager
so it exits properly.@Gustav-Simonsson maybe you could strip those commits (changes to blockpool and chain manager) from the PR. I'll submit a separate PR with the change to core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix is fine with a little context :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, will cherry pick the other commits from @fjl branch then to leave this out for a separate PR.