In blocktest cmd, disable network and add RPC flag

This commit is contained in:
Gustav Simonsson 2015-03-20 01:59:38 +01:00
parent 3f6e1b2fd3
commit 33c5186fd0
2 changed files with 12 additions and 5 deletions

View File

@ -26,10 +26,10 @@ be able to interact with the chain defined by the test.
} }
func runblocktest(ctx *cli.Context) { func runblocktest(ctx *cli.Context) {
if len(ctx.Args()) != 2 { if len(ctx.Args()) != 3 {
utils.Fatalf("This command requires two arguments.") utils.Fatalf("Usage: ethereum blocktest <path-to-test-file> <test-name> {rpc, norpc}")
} }
file, testname := ctx.Args()[0], ctx.Args()[1] file, testname, startrpc := ctx.Args()[0], ctx.Args()[1], ctx.Args()[2]
bt, err := tests.LoadBlockTests(file) bt, err := tests.LoadBlockTests(file)
if err != nil { if err != nil {
@ -42,6 +42,7 @@ func runblocktest(ctx *cli.Context) {
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
cfg.NewDB = func(path string) (common.Database, error) { return ethdb.NewMemDatabase() } cfg.NewDB = func(path string) (common.Database, error) { return ethdb.NewMemDatabase() }
cfg.MaxPeers = 0 // disable network
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
utils.Fatalf("%v", err) utils.Fatalf("%v", err)
@ -62,5 +63,11 @@ func runblocktest(ctx *cli.Context) {
} else { } else {
fmt.Println("Block Test chain loaded, starting ethereum.") fmt.Println("Block Test chain loaded, starting ethereum.")
} }
if startrpc == "rpc" {
startEth(ctx, ethereum)
utils.StartRPC(ethereum, ctx)
ethereum.WaitForShutdown()
} else {
startEth(ctx, ethereum) startEth(ctx, ethereum)
} }
}

View File

@ -256,7 +256,7 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) {
addr := ctx.GlobalString(RPCListenAddrFlag.Name) addr := ctx.GlobalString(RPCListenAddrFlag.Name)
port := ctx.GlobalInt(RPCPortFlag.Name) port := ctx.GlobalInt(RPCPortFlag.Name)
dataDir := ctx.GlobalString(DataDirFlag.Name) dataDir := ctx.GlobalString(DataDirFlag.Name)
fmt.Println("Starting RPC on port: ", port)
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port)) l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port))
if err != nil { if err != nil {
Fatalf("Can't listen on %s:%d: %v", addr, port, err) Fatalf("Can't listen on %s:%d: %v", addr, port, err)