From 58d9d98dafc9013a4aa6f7f2c8c8e3d9ad76ce7c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 13 Mar 2015 18:30:45 +0100 Subject: cmd/utils: GetEthereum -> MakeEthConfig This allows changing the config before starting Ethereum with it. --- cmd/ethereum/main.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'cmd/ethereum') diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index 8b01457e6..d31053fb1 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -156,24 +156,26 @@ func main() { func run(ctx *cli.Context) { fmt.Printf("Welcome to the FRONTIER\n") utils.HandleInterrupt() - eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx) + cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) + ethereum, err := eth.New(cfg) if err != nil { utils.Fatalf("%v", err) } - startEth(ctx, eth) + startEth(ctx, ethereum) // this blocks the thread - eth.WaitForShutdown() + ethereum.WaitForShutdown() } func runjs(ctx *cli.Context) { - eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx) + cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) + ethereum, err := eth.New(cfg) if err != nil { utils.Fatalf("%v", err) } - startEth(ctx, eth) - repl := newJSRE(eth) + startEth(ctx, ethereum) + repl := newJSRE(ethereum) if len(ctx.Args()) == 0 { repl.interactive() } else { @@ -181,8 +183,8 @@ func runjs(ctx *cli.Context) { repl.exec(file) } } - eth.Stop() - eth.WaitForShutdown() + ethereum.Stop() + ethereum.WaitForShutdown() } func startEth(ctx *cli.Context, eth *eth.Ethereum) { -- cgit From 67f8f83a1ba2a4dbd0f6f2fd075bb440f5c420ad Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 13 Mar 2015 18:37:13 +0100 Subject: cmd/ethereum: add blocktest command --- cmd/ethereum/blocktest.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++ cmd/ethereum/main.go | 1 + 2 files changed, 67 insertions(+) create mode 100644 cmd/ethereum/blocktest.go (limited to 'cmd/ethereum') diff --git a/cmd/ethereum/blocktest.go b/cmd/ethereum/blocktest.go new file mode 100644 index 000000000..1bb3809cf --- /dev/null +++ b/cmd/ethereum/blocktest.go @@ -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) +} diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index d31053fb1..bc515b583 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -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", -- cgit