integration: allow setting custom btcd exe path

To allow using a custom btcd executable, we allow specifying a path to a
file. If the path is empty, the harness will fall back to compiling one
from scratch.
This commit is contained in:
Oliver Gugger 2020-11-11 14:16:03 +01:00
parent f070f7f2be
commit 9250064837
No known key found for this signature in database
GPG key ID: 8E4256593F177720
6 changed files with 31 additions and 18 deletions

View file

@ -129,7 +129,7 @@ func assertSoftForkStatus(r *rpctest.Harness, t *testing.T, forkKey string, stat
// specific soft fork deployment to test. // specific soft fork deployment to test.
func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) { func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
// Initialize the primary mining node with only the genesis block. // Initialize the primary mining node with only the genesis block.
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil) r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatalf("unable to create primary harness: %v", err) t.Fatalf("unable to create primary harness: %v", err)
} }
@ -320,7 +320,7 @@ func TestBIP0009Mining(t *testing.T) {
t.Parallel() t.Parallel()
// Initialize the primary mining node with only the genesis block. // Initialize the primary mining node with only the genesis block.
r, err := rpctest.New(&chaincfg.SimNetParams, nil, nil) r, err := rpctest.New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatalf("unable to create primary harness: %v", err) t.Fatalf("unable to create primary harness: %v", err)
} }

View file

@ -109,7 +109,7 @@ func TestBIP0113Activation(t *testing.T) {
t.Parallel() t.Parallel()
btcdCfg := []string{"--rejectnonstd"} btcdCfg := []string{"--rejectnonstd"}
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg) r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
if err != nil { if err != nil {
t.Fatal("unable to create primary harness: ", err) t.Fatal("unable to create primary harness: ", err)
} }
@ -405,7 +405,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
// relative lock times. // relative lock times.
btcdCfg := []string{"--rejectnonstd"} btcdCfg := []string{"--rejectnonstd"}
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg) r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
if err != nil { if err != nil {
t.Fatal("unable to create primary harness: ", err) t.Fatal("unable to create primary harness: ", err)
} }

View file

@ -109,7 +109,9 @@ func TestMain(m *testing.M) {
// ensure that non-standard transactions aren't accepted into the // ensure that non-standard transactions aren't accepted into the
// mempool or relayed. // mempool or relayed.
btcdCfg := []string{"--rejectnonstd"} btcdCfg := []string{"--rejectnonstd"}
primaryHarness, err = rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg) primaryHarness, err = rpctest.New(
&chaincfg.SimNetParams, nil, btcdCfg, "",
)
if err != nil { if err != nil {
fmt.Println("unable to create primary harness: ", err) fmt.Println("unable to create primary harness: ", err)
os.Exit(1) os.Exit(1)

View file

@ -41,11 +41,19 @@ type nodeConfig struct {
} }
// newConfig returns a newConfig with all default values. // newConfig returns a newConfig with all default values.
func newConfig(prefix, certFile, keyFile string, extra []string) (*nodeConfig, error) { func newConfig(prefix, certFile, keyFile string, extra []string,
btcdPath, err := btcdExecutablePath() customExePath string) (*nodeConfig, error) {
var btcdPath string
if customExePath != "" {
btcdPath = customExePath
} else {
var err error
btcdPath, err = btcdExecutablePath()
if err != nil { if err != nil {
btcdPath = "btcd" btcdPath = "btcd"
} }
}
a := &nodeConfig{ a := &nodeConfig{
listen: "127.0.0.1:18555", listen: "127.0.0.1:18555",

View file

@ -94,11 +94,12 @@ type Harness struct {
// New creates and initializes new instance of the rpc test harness. // New creates and initializes new instance of the rpc test harness.
// Optionally, websocket handlers and a specified configuration may be passed. // Optionally, websocket handlers and a specified configuration may be passed.
// In the case that a nil config is passed, a default configuration will be // In the case that a nil config is passed, a default configuration will be
// used. // used. If a custom btcd executable is specified, it will be used to start the
// harness node. Otherwise a new binary is built on demand.
// //
// NOTE: This function is safe for concurrent access. // NOTE: This function is safe for concurrent access.
func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers, func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers,
extraArgs []string) (*Harness, error) { extraArgs []string, customExePath string) (*Harness, error) {
harnessStateMtx.Lock() harnessStateMtx.Lock()
defer harnessStateMtx.Unlock() defer harnessStateMtx.Unlock()
@ -144,7 +145,9 @@ func New(activeNet *chaincfg.Params, handlers *rpcclient.NotificationHandlers,
miningAddr := fmt.Sprintf("--miningaddr=%s", wallet.coinbaseAddr) miningAddr := fmt.Sprintf("--miningaddr=%s", wallet.coinbaseAddr)
extraArgs = append(extraArgs, miningAddr) extraArgs = append(extraArgs, miningAddr)
config, err := newConfig("rpctest", certFile, keyFile, extraArgs) config, err := newConfig(
"rpctest", certFile, keyFile, extraArgs, customExePath,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -105,7 +105,7 @@ func assertConnectedTo(t *testing.T, nodeA *Harness, nodeB *Harness) {
func testConnectNode(r *Harness, t *testing.T) { func testConnectNode(r *Harness, t *testing.T) {
// Create a fresh test harness. // Create a fresh test harness.
harness, err := New(&chaincfg.SimNetParams, nil, nil) harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -153,7 +153,7 @@ func testActiveHarnesses(r *Harness, t *testing.T) {
numInitialHarnesses := len(ActiveHarnesses()) numInitialHarnesses := len(ActiveHarnesses())
// Create a single test harness. // Create a single test harness.
harness1, err := New(&chaincfg.SimNetParams, nil, nil) harness1, err := New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -181,7 +181,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
// Create a local test harness with only the genesis block. The nodes // Create a local test harness with only the genesis block. The nodes
// will be synced below so the same transaction can be sent to both // will be synced below so the same transaction can be sent to both
// nodes without it being an orphan. // nodes without it being an orphan.
harness, err := New(&chaincfg.SimNetParams, nil, nil) harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -281,7 +281,7 @@ func testJoinMempools(r *Harness, t *testing.T) {
func testJoinBlocks(r *Harness, t *testing.T) { func testJoinBlocks(r *Harness, t *testing.T) {
// Create a second harness with only the genesis block so it is behind // Create a second harness with only the genesis block so it is behind
// the main harness. // the main harness.
harness, err := New(&chaincfg.SimNetParams, nil, nil) harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -469,7 +469,7 @@ func testGenerateAndSubmitBlockWithCustomCoinbaseOutputs(r *Harness,
func testMemWalletReorg(r *Harness, t *testing.T) { func testMemWalletReorg(r *Harness, t *testing.T) {
// Create a fresh harness, we'll be using the main harness to force a // Create a fresh harness, we'll be using the main harness to force a
// re-org on this local harness. // re-org on this local harness.
harness, err := New(&chaincfg.SimNetParams, nil, nil) harness, err := New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -566,7 +566,7 @@ const (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
var err error var err error
mainHarness, err = New(&chaincfg.SimNetParams, nil, nil) mainHarness, err = New(&chaincfg.SimNetParams, nil, nil, "")
if err != nil { if err != nil {
fmt.Println("unable to create main harness: ", err) fmt.Println("unable to create main harness: ", err)
os.Exit(1) os.Exit(1)