From 11ba14ab02005be5dd16bef23debf6115e6a85c2 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 15 Mar 2024 12:54:30 +0100 Subject: [PATCH] chainntnfs: add netParams arg to backend funcs --- chainntnfs/bitcoindnotify/bitcoind_test.go | 8 ++++---- chainntnfs/btcdnotify/btcd_test.go | 4 ++-- chainntnfs/test/test_interface.go | 10 ++++++---- chainntnfs/test_utils.go | 22 ++++++++++++---------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/chainntnfs/bitcoindnotify/bitcoind_test.go b/chainntnfs/bitcoindnotify/bitcoind_test.go index 3eefe8e32..03572ad0f 100644 --- a/chainntnfs/bitcoindnotify/bitcoind_test.go +++ b/chainntnfs/bitcoindnotify/bitcoind_test.go @@ -120,11 +120,11 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) { func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) { miner := chainntnfs.NewMiner( - t, []string{"--txindex"}, true, 25, + t, chainntnfs.NetParams, []string{"--txindex"}, true, 25, ) bitcoindConn := chainntnfs.NewBitcoindBackend( - t, miner.P2PAddress(), true, rpcPolling, + t, chainntnfs.NetParams, miner.P2PAddress(), true, rpcPolling, ) hintCache := initHintCache(t) @@ -217,10 +217,10 @@ func TestHistoricalConfDetailsNoTxIndex(t *testing.T) { } func testHistoricalConfDetailsNoTxIndex(t *testing.T, rpcpolling bool) { - miner := chainntnfs.NewMiner(t, nil, true, 25) + miner := chainntnfs.NewMiner(t, chainntnfs.NetParams, nil, true, 25) bitcoindConn := chainntnfs.NewBitcoindBackend( - t, miner.P2PAddress(), false, rpcpolling, + t, chainntnfs.NetParams, miner.P2PAddress(), false, rpcpolling, ) hintCache := initHintCache(t) diff --git a/chainntnfs/btcdnotify/btcd_test.go b/chainntnfs/btcdnotify/btcd_test.go index 517710be5..240c5a24c 100644 --- a/chainntnfs/btcdnotify/btcd_test.go +++ b/chainntnfs/btcdnotify/btcd_test.go @@ -74,7 +74,7 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) { t.Parallel() harness := chainntnfs.NewMiner( - t, []string{"--txindex"}, true, 25, + t, chainntnfs.NetParams, []string{"--txindex"}, true, 25, ) notifier := setUpNotifier(t, harness) @@ -145,7 +145,7 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) { func TestHistoricalConfDetailsNoTxIndex(t *testing.T) { t.Parallel() - harness := chainntnfs.NewMiner(t, nil, true, 25) + harness := chainntnfs.NewMiner(t, chainntnfs.NetParams, nil, true, 25) notifier := setUpNotifier(t, harness) diff --git a/chainntnfs/test/test_interface.go b/chainntnfs/test/test_interface.go index de01cc149..a091c286e 100644 --- a/chainntnfs/test/test_interface.go +++ b/chainntnfs/test/test_interface.go @@ -1905,7 +1905,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) { // dedicated miner to generate blocks, cause re-orgs, etc. We'll set up // this node with a chain length of 125, so we have plenty of BTC to // play around with. - miner := chainntnfs.NewMiner(t, nil, true, 25) + miner := chainntnfs.NewMiner(t, chainntnfs.NetParams, nil, true, 25) rpcConfig := miner.RPCConfig() p2pAddr := miner.P2PAddress() @@ -1945,7 +1945,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) { case "bitcoind": var bitcoindConn *chain.BitcoindConn bitcoindConn = chainntnfs.NewBitcoindBackend( - t, p2pAddr, true, false, + t, chainntnfs.NetParams, p2pAddr, true, false, ) newNotifier = func() (chainntnfs.TestChainNotifier, error) { return bitcoindnotify.New( @@ -1957,7 +1957,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) { case "bitcoind-rpc-polling": var bitcoindConn *chain.BitcoindConn bitcoindConn = chainntnfs.NewBitcoindBackend( - t, p2pAddr, true, true, + t, chainntnfs.NetParams, p2pAddr, true, true, ) newNotifier = func() (chainntnfs.TestChainNotifier, error) { return bitcoindnotify.New( @@ -1976,7 +1976,9 @@ func TestInterfaces(t *testing.T, targetBackEnd string) { case "neutrino": var spvNode *neutrino.ChainService - spvNode = chainntnfs.NewNeutrinoBackend(t, p2pAddr) + spvNode = chainntnfs.NewNeutrinoBackend( + t, chainntnfs.NetParams, p2pAddr, + ) newNotifier = func() (chainntnfs.TestChainNotifier, error) { return neutrinonotify.New( spvNode, hintCache, hintCache, diff --git a/chainntnfs/test_utils.go b/chainntnfs/test_utils.go index 8bd994f07..73bd2cf69 100644 --- a/chainntnfs/test_utils.go +++ b/chainntnfs/test_utils.go @@ -6,8 +6,8 @@ package chainntnfs import ( "errors" "fmt" - "io/ioutil" "math/rand" + "os" "os/exec" "path/filepath" "testing" @@ -166,8 +166,8 @@ func CreateSpendTx(t *testing.T, prevOutPoint *wire.OutPoint, // NewMiner spawns testing harness backed by a btcd node that can serve as a // miner. -func NewMiner(t *testing.T, extraArgs []string, createChain bool, - spendableOutputs uint32) *rpctest.Harness { +func NewMiner(t *testing.T, netParams *chaincfg.Params, extraArgs []string, + createChain bool, spendableOutputs uint32) *rpctest.Harness { t.Helper() @@ -175,7 +175,7 @@ func NewMiner(t *testing.T, extraArgs []string, createChain bool, trickle := fmt.Sprintf("--trickleinterval=%v", TrickleInterval) extraArgs = append(extraArgs, trickle) - node, err := rpctest.New(NetParams, nil, extraArgs, "") + node, err := rpctest.New(netParams, nil, extraArgs, "") require.NoError(t, err, "unable to create backend node") t.Cleanup(func() { require.NoError(t, node.TearDown()) @@ -194,15 +194,15 @@ func NewMiner(t *testing.T, extraArgs []string, createChain bool, // can be set to determine whether bitcoind's RPC polling interface should be // used for block and tx notifications or if its ZMQ interface should be used. // A connection to the newly spawned bitcoind node is returned. -func NewBitcoindBackend(t *testing.T, minerAddr string, txindex, - rpcpolling bool) *chain.BitcoindConn { +func NewBitcoindBackend(t *testing.T, netParams *chaincfg.Params, + minerAddr string, txindex, rpcpolling bool) *chain.BitcoindConn { t.Helper() // We use ioutil.TempDir here instead of t.TempDir because some versions // of bitcoind complain about the zmq connection string formats when the // t.TempDir directory string is used. - tempBitcoindDir, err := ioutil.TempDir("", "bitcoind") + tempBitcoindDir, err := os.MkdirTemp("", "bitcoind") require.NoError(t, err, "unable to create temp dir") rpcPort := rand.Intn(65536-1024) + 1024 @@ -236,7 +236,7 @@ func NewBitcoindBackend(t *testing.T, minerAddr string, txindex, // Wait for the bitcoind instance to start up. host := fmt.Sprintf("127.0.0.1:%d", rpcPort) cfg := &chain.BitcoindConfig{ - ChainParams: NetParams, + ChainParams: netParams, Host: host, User: "weks", Pass: "weks", @@ -279,7 +279,9 @@ func NewBitcoindBackend(t *testing.T, minerAddr string, txindex, // NewNeutrinoBackend spawns a new neutrino node that connects to a miner at // the specified address. -func NewNeutrinoBackend(t *testing.T, minerAddr string) *neutrino.ChainService { +func NewNeutrinoBackend(t *testing.T, netParams *chaincfg.Params, + minerAddr string) *neutrino.ChainService { + t.Helper() spvDir := t.TempDir() @@ -300,7 +302,7 @@ func NewNeutrinoBackend(t *testing.T, minerAddr string) *neutrino.ChainService { spvConfig := neutrino.Config{ DataDir: spvDir, Database: spvDatabase, - ChainParams: *NetParams, + ChainParams: *netParams, ConnectPeers: []string{minerAddr}, } spvNode, err := neutrino.NewChainService(spvConfig)