From da04285e0d65bd85078908bfd8d1d4c81c11435e Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 19 Oct 2016 16:38:21 -0500 Subject: [PATCH] rpctest: Choose flags based on provided params. This modifies the rpctest framework to start btcd with the appropriate network flags depending on the provided parameters. Previously, it always started btcd with --simnet even if other parameters, such as those for the regression test network, were provided. --- rpctest/node.go | 5 ----- rpctest/rpc_harness.go | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/rpctest/node.go b/rpctest/node.go index c076a83a..6554824c 100644 --- a/rpctest/node.go +++ b/rpctest/node.go @@ -12,11 +12,8 @@ import ( "os/exec" "path/filepath" "runtime" - "strings" "time" - "github.com/btcsuite/btcd/wire" - rpc "github.com/btcsuite/btcrpcclient" "github.com/btcsuite/btcutil" ) @@ -90,8 +87,6 @@ func (n *nodeConfig) setDefaults() error { // process. func (n *nodeConfig) arguments() []string { args := []string{} - // --simnet - args = append(args, fmt.Sprintf("--%s", strings.ToLower(wire.SimNet.String()))) if n.rpcUser != "" { // --rpcuser args = append(args, fmt.Sprintf("--rpcuser=%s", n.rpcUser)) diff --git a/rpctest/rpc_harness.go b/rpctest/rpc_harness.go index 6fba7fc7..e930e60b 100644 --- a/rpctest/rpc_harness.go +++ b/rpctest/rpc_harness.go @@ -99,6 +99,22 @@ func New(activeNet *chaincfg.Params, handlers *btcrpcclient.NotificationHandlers harnessStateMtx.Lock() defer harnessStateMtx.Unlock() + // Add a flag for the appropriate network type based on the provided + // chain params. + switch activeNet.Net { + case wire.MainNet: + // No extra flags since mainnet is the default + case wire.TestNet3: + extraArgs = append(extraArgs, "--testnet") + case wire.TestNet: + extraArgs = append(extraArgs, "--regtest") + case wire.SimNet: + extraArgs = append(extraArgs, "--simnet") + default: + return nil, fmt.Errorf("rpctest.New must be called with one " + + "of the supported chain networks") + } + harnessID := strconv.Itoa(int(numTestInstances)) nodeTestData, err := ioutil.TempDir("", "rpctest-"+harnessID) if err != nil {