chainntnfs: add netParams arg to backend funcs

This commit is contained in:
Oliver Gugger 2024-03-15 12:54:30 +01:00
parent b4449ab55f
commit 11ba14ab02
No known key found for this signature in database
GPG key ID: 8E4256593F177720
4 changed files with 24 additions and 20 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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,

View file

@ -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)