Skip to content

Commit f6c8d3f

Browse files
committed
integration/rpctest: use options struct to initialize Harness
Initialize the Harness API with a options struct instead of several fields that may be set to the zero value of the type.
1 parent 6cfd717 commit f6c8d3f

13 files changed

Lines changed: 89 additions & 69 deletions

integration/bip0009_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ func assertSoftForkStatus(r *rpctest.Harness, t *testing.T, forkKey string, stat
130130
// specific soft fork deployment to test.
131131
func testBIP0009(t *testing.T, forkKey string, deploymentID uint32) {
132132
// Initialize the primary mining node with only the genesis block.
133-
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil, "")
133+
r, err := rpctest.New(rpctest.HarnessOpts{
134+
ActiveNet: &chaincfg.RegressionNetParams,
135+
})
134136
if err != nil {
135137
t.Fatalf("unable to create primary harness: %v", err)
136138
}
@@ -383,7 +385,7 @@ func TestBIP0009Mining(t *testing.T) {
383385
t.Parallel()
384386

385387
// Initialize the primary mining node with only the genesis block.
386-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, nil, "")
388+
r, err := rpctest.New()
387389
if err != nil {
388390
t.Fatalf("unable to create primary harness: %v", err)
389391
}

integration/chain_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/btcsuite/btcd/btcjson"
1010
"github.com/btcsuite/btcd/btcutil/v2"
11-
"github.com/btcsuite/btcd/chaincfg/v2"
1211
"github.com/btcsuite/btcd/integration/rpctest"
1312
"github.com/btcsuite/btcd/rpcclient"
1413
"github.com/btcsuite/btcd/txscript/v2"
@@ -27,7 +26,7 @@ func TestGetTxSpendingPrevOut(t *testing.T) {
2726

2827
// Boilerplate codetestDir to make a pruned node.
2928
btcdCfg := []string{"--rejectnonstd", "--debuglevel=debug"}
30-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
29+
r, err := rpctest.New(rpctest.HarnessOpts{ExtraArgs: btcdCfg})
3130
require.NoError(t, err)
3231

3332
// Setup the node.

integration/csv_fork_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/btcsuite/btcd/blockchain"
2020
"github.com/btcsuite/btcd/btcec/v2"
2121
"github.com/btcsuite/btcd/btcutil/v2"
22-
"github.com/btcsuite/btcd/chaincfg/v2"
2322
"github.com/btcsuite/btcd/chainhash/v2"
2423
"github.com/btcsuite/btcd/integration/rpctest"
2524
"github.com/btcsuite/btcd/txscript/v2"
@@ -112,7 +111,7 @@ func TestBIP0113Activation(t *testing.T) {
112111
t.Parallel()
113112

114113
btcdCfg := []string{"--rejectnonstd"}
115-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
114+
r, err := rpctest.New(rpctest.HarnessOpts{ExtraArgs: btcdCfg})
116115
if err != nil {
117116
t.Fatal("unable to create primary harness: ", err)
118117
}
@@ -409,7 +408,7 @@ func TestBIP0068AndBIP0112Activation(t *testing.T) {
409408
// relative lock times.
410409

411410
btcdCfg := []string{"--rejectnonstd"}
412-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
411+
r, err := rpctest.New(rpctest.HarnessOpts{ExtraArgs: btcdCfg})
413412
if err != nil {
414413
t.Fatal("unable to create primary harness: ", err)
415414
}

integration/getchaintips_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ func TestGetChainTips(t *testing.T) {
145145
"0000000000000000000000000000000000000000000000000000"
146146

147147
// Set up regtest chain.
148-
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil, "")
148+
r, err := rpctest.New(rpctest.HarnessOpts{
149+
ActiveNet: &chaincfg.RegressionNetParams,
150+
})
149151
if err != nil {
150152
t.Fatal("TestGetChainTips fail. Unable to create primary harness: ", err)
151153
}

integration/invalidate_reconsider_block_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99

1010
func TestInvalidateAndReconsiderBlock(t *testing.T) {
1111
// Set up regtest chain.
12-
r, err := rpctest.New(&chaincfg.RegressionNetParams, nil, nil, "")
12+
r, err := rpctest.New(rpctest.HarnessOpts{
13+
ActiveNet: &chaincfg.RegressionNetParams,
14+
})
1315
if err != nil {
1416
t.Fatalf("TestInvalidateAndReconsiderBlock fail."+
1517
"Unable to create primary harness: %v", err)

integration/p2a_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ func TestPayToAnchorSimple(t *testing.T) {
3030
// standardness checks running, so we start the node with
3131
// --rejectnonstd.
3232
btcdCfg := []string{"--rejectnonstd"}
33-
harness, err := rpctest.New(
34-
&chaincfg.SimNetParams, nil, btcdCfg, "",
35-
)
33+
harness, err := rpctest.New(rpctest.HarnessOpts{
34+
ActiveNet: &chaincfg.RegressionNetParams,
35+
ExtraArgs: btcdCfg,
36+
})
3637
if err != nil {
3738
t.Fatalf("unable to create test harness: %v", err)
3839
}
@@ -197,4 +198,3 @@ func TestPayToAnchorSimple(t *testing.T) {
197198
}
198199
})
199200
}
200-

integration/prune_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package integration
1111
import (
1212
"testing"
1313

14-
"github.com/btcsuite/btcd/chaincfg/v2"
1514
"github.com/btcsuite/btcd/integration/rpctest"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -21,7 +20,7 @@ func TestPrune(t *testing.T) {
2120

2221
// Boilerplate code to make a pruned node.
2322
btcdCfg := []string{"--prune=1536"}
24-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
23+
r, err := rpctest.New(rpctest.HarnessOpts{ExtraArgs: btcdCfg})
2524
require.NoError(t, err)
2625

2726
if err := r.SetUp(false, 0); err != nil {

integration/rawtx_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/btcsuite/btcd/btcjson"
1111
"github.com/btcsuite/btcd/btcutil/v2"
12-
"github.com/btcsuite/btcd/chaincfg/v2"
1312
"github.com/btcsuite/btcd/integration/rpctest"
1413
"github.com/btcsuite/btcd/rpcclient"
1514
"github.com/btcsuite/btcd/txscript/v2"
@@ -28,7 +27,7 @@ func TestTestMempoolAccept(t *testing.T) {
2827

2928
// Boilerplate codetestDir to make a pruned node.
3029
btcdCfg := []string{"--rejectnonstd", "--debuglevel=debug"}
31-
r, err := rpctest.New(&chaincfg.SimNetParams, nil, btcdCfg, "")
30+
r, err := rpctest.New(rpctest.HarnessOpts{ExtraArgs: btcdCfg})
3231
require.NoError(t, err)
3332

3433
// Setup the node.

integration/reorg_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/btcsuite/btcd/btcjson"
8-
"github.com/btcsuite/btcd/chaincfg/v2"
98
"github.com/btcsuite/btcd/integration/rpctest"
109
"github.com/btcsuite/btcd/rpcclient"
1110
"github.com/stretchr/testify/require"
@@ -33,12 +32,12 @@ func TestReorgFromForkPoint(t *testing.T) {
3332
forkBranchLen = int32(shorterBlocks)
3433
)
3534

36-
longer, err := rpctest.New(&chaincfg.SimNetParams, nil, []string{}, "")
35+
longer, err := rpctest.New()
3736
require.NoError(t, err)
3837
require.NoError(t, longer.SetUp(false, 0))
3938
t.Cleanup(func() { require.NoError(t, longer.TearDown()) })
4039

41-
shorter, err := rpctest.New(&chaincfg.SimNetParams, nil, []string{}, "")
40+
shorter, err := rpctest.New()
4241
require.NoError(t, err)
4342
require.NoError(t, shorter.SetUp(false, 0))
4443
t.Cleanup(func() { require.NoError(t, shorter.TearDown()) })

integration/rpcserver_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"time"
1818

1919
"github.com/btcsuite/btcd/blockchain"
20-
"github.com/btcsuite/btcd/chaincfg/v2"
2120
"github.com/btcsuite/btcd/chainhash/v2"
2221
"github.com/btcsuite/btcd/integration/rpctest"
2322
"github.com/btcsuite/btcd/rpcclient"
@@ -308,9 +307,9 @@ func TestMain(m *testing.M) {
308307
// ensure that non-standard transactions aren't accepted into the
309308
// mempool or relayed.
310309
btcdCfg := []string{"--rejectnonstd"}
311-
primaryHarness, err = rpctest.New(
312-
&chaincfg.SimNetParams, nil, btcdCfg, "",
313-
)
310+
primaryHarness, err = rpctest.New(rpctest.HarnessOpts{
311+
ExtraArgs: btcdCfg,
312+
})
314313
if err != nil {
315314
fmt.Println("unable to create primary harness: ", err)
316315
os.Exit(1)

0 commit comments

Comments
 (0)