cmd/ethereum: add blocktest command

This commit is contained in:
Felix Lange 2015-03-13 18:37:13 +01:00
parent e463479b6c
commit 67f8f83a1b
2 changed files with 67 additions and 0 deletions

66
cmd/ethereum/blocktest.go Normal file
View File

@ -0,0 +1,66 @@
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/tests"
)
var blocktestCmd = cli.Command{
Action: runblocktest,
Name: "blocktest",
Usage: `loads a block test file`,
Description: `
The first argument should be a block test file.
The second argument is the name of a block test from the file.
The block test will be loaded into an in-memory database.
If loading succeeds, the RPC server is started. Clients will
be able to interact with the chain defined by the test.
`,
}
func runblocktest(ctx *cli.Context) {
if len(ctx.Args()) != 2 {
utils.Fatalf("This command requires two arguments.")
}
file, testname := ctx.Args()[0], ctx.Args()[1]
bt, err := tests.LoadBlockTests(file)
if err != nil {
utils.Fatalf("%v", err)
}
test, ok := bt[testname]
if !ok {
utils.Fatalf("Test file does not contain test named %q", testname)
}
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
cfg.NewDB = func(path string) (ethutil.Database, error) { return ethdb.NewMemDatabase() }
ethereum, err := eth.New(cfg)
if err != nil {
utils.Fatalf("%v", err)
}
// import the genesis block
ethereum.ResetWithGenesisBlock(test.Genesis)
// import pre accounts
if err := test.InsertPreState(ethereum.StateDb()); err != nil {
utils.Fatalf("could not insert genesis accounts: %v", err)
}
// insert the test blocks, which will execute all transactions
chain := ethereum.ChainManager()
if err := chain.InsertChain(test.Blocks); err != nil {
utils.Fatalf("Block Test load error: %v", err)
} else {
fmt.Println("Block Test chain loaded, starting ethereum.")
}
startEth(ctx, ethereum)
}

View File

@ -53,6 +53,7 @@ func init() {
app.Action = run
app.HideVersion = true // we have a command to print the version
app.Commands = []cli.Command{
blocktestCmd,
{
Action: version,
Name: "version",