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) { func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) {
miner := chainntnfs.NewMiner( miner := chainntnfs.NewMiner(
t, []string{"--txindex"}, true, 25, t, chainntnfs.NetParams, []string{"--txindex"}, true, 25,
) )
bitcoindConn := chainntnfs.NewBitcoindBackend( bitcoindConn := chainntnfs.NewBitcoindBackend(
t, miner.P2PAddress(), true, rpcPolling, t, chainntnfs.NetParams, miner.P2PAddress(), true, rpcPolling,
) )
hintCache := initHintCache(t) hintCache := initHintCache(t)
@ -217,10 +217,10 @@ func TestHistoricalConfDetailsNoTxIndex(t *testing.T) {
} }
func testHistoricalConfDetailsNoTxIndex(t *testing.T, rpcpolling bool) { 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( bitcoindConn := chainntnfs.NewBitcoindBackend(
t, miner.P2PAddress(), false, rpcpolling, t, chainntnfs.NetParams, miner.P2PAddress(), false, rpcpolling,
) )
hintCache := initHintCache(t) hintCache := initHintCache(t)

View File

@ -74,7 +74,7 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) {
t.Parallel() t.Parallel()
harness := chainntnfs.NewMiner( harness := chainntnfs.NewMiner(
t, []string{"--txindex"}, true, 25, t, chainntnfs.NetParams, []string{"--txindex"}, true, 25,
) )
notifier := setUpNotifier(t, harness) notifier := setUpNotifier(t, harness)
@ -145,7 +145,7 @@ func TestHistoricalConfDetailsTxIndex(t *testing.T) {
func TestHistoricalConfDetailsNoTxIndex(t *testing.T) { func TestHistoricalConfDetailsNoTxIndex(t *testing.T) {
t.Parallel() t.Parallel()
harness := chainntnfs.NewMiner(t, nil, true, 25) harness := chainntnfs.NewMiner(t, chainntnfs.NetParams, nil, true, 25)
notifier := setUpNotifier(t, harness) 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 // 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 // this node with a chain length of 125, so we have plenty of BTC to
// play around with. // play around with.
miner := chainntnfs.NewMiner(t, nil, true, 25) miner := chainntnfs.NewMiner(t, chainntnfs.NetParams, nil, true, 25)
rpcConfig := miner.RPCConfig() rpcConfig := miner.RPCConfig()
p2pAddr := miner.P2PAddress() p2pAddr := miner.P2PAddress()
@ -1945,7 +1945,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) {
case "bitcoind": case "bitcoind":
var bitcoindConn *chain.BitcoindConn var bitcoindConn *chain.BitcoindConn
bitcoindConn = chainntnfs.NewBitcoindBackend( bitcoindConn = chainntnfs.NewBitcoindBackend(
t, p2pAddr, true, false, t, chainntnfs.NetParams, p2pAddr, true, false,
) )
newNotifier = func() (chainntnfs.TestChainNotifier, error) { newNotifier = func() (chainntnfs.TestChainNotifier, error) {
return bitcoindnotify.New( return bitcoindnotify.New(
@ -1957,7 +1957,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) {
case "bitcoind-rpc-polling": case "bitcoind-rpc-polling":
var bitcoindConn *chain.BitcoindConn var bitcoindConn *chain.BitcoindConn
bitcoindConn = chainntnfs.NewBitcoindBackend( bitcoindConn = chainntnfs.NewBitcoindBackend(
t, p2pAddr, true, true, t, chainntnfs.NetParams, p2pAddr, true, true,
) )
newNotifier = func() (chainntnfs.TestChainNotifier, error) { newNotifier = func() (chainntnfs.TestChainNotifier, error) {
return bitcoindnotify.New( return bitcoindnotify.New(
@ -1976,7 +1976,9 @@ func TestInterfaces(t *testing.T, targetBackEnd string) {
case "neutrino": case "neutrino":
var spvNode *neutrino.ChainService var spvNode *neutrino.ChainService
spvNode = chainntnfs.NewNeutrinoBackend(t, p2pAddr) spvNode = chainntnfs.NewNeutrinoBackend(
t, chainntnfs.NetParams, p2pAddr,
)
newNotifier = func() (chainntnfs.TestChainNotifier, error) { newNotifier = func() (chainntnfs.TestChainNotifier, error) {
return neutrinonotify.New( return neutrinonotify.New(
spvNode, hintCache, hintCache, spvNode, hintCache, hintCache,

View File

@ -6,8 +6,8 @@ package chainntnfs
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"testing" "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 // NewMiner spawns testing harness backed by a btcd node that can serve as a
// miner. // miner.
func NewMiner(t *testing.T, extraArgs []string, createChain bool, func NewMiner(t *testing.T, netParams *chaincfg.Params, extraArgs []string,
spendableOutputs uint32) *rpctest.Harness { createChain bool, spendableOutputs uint32) *rpctest.Harness {
t.Helper() t.Helper()
@ -175,7 +175,7 @@ func NewMiner(t *testing.T, extraArgs []string, createChain bool,
trickle := fmt.Sprintf("--trickleinterval=%v", TrickleInterval) trickle := fmt.Sprintf("--trickleinterval=%v", TrickleInterval)
extraArgs = append(extraArgs, trickle) 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") require.NoError(t, err, "unable to create backend node")
t.Cleanup(func() { t.Cleanup(func() {
require.NoError(t, node.TearDown()) 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 // 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. // used for block and tx notifications or if its ZMQ interface should be used.
// A connection to the newly spawned bitcoind node is returned. // A connection to the newly spawned bitcoind node is returned.
func NewBitcoindBackend(t *testing.T, minerAddr string, txindex, func NewBitcoindBackend(t *testing.T, netParams *chaincfg.Params,
rpcpolling bool) *chain.BitcoindConn { minerAddr string, txindex, rpcpolling bool) *chain.BitcoindConn {
t.Helper() t.Helper()
// We use ioutil.TempDir here instead of t.TempDir because some versions // We use ioutil.TempDir here instead of t.TempDir because some versions
// of bitcoind complain about the zmq connection string formats when the // of bitcoind complain about the zmq connection string formats when the
// t.TempDir directory string is used. // 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") require.NoError(t, err, "unable to create temp dir")
rpcPort := rand.Intn(65536-1024) + 1024 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. // Wait for the bitcoind instance to start up.
host := fmt.Sprintf("127.0.0.1:%d", rpcPort) host := fmt.Sprintf("127.0.0.1:%d", rpcPort)
cfg := &chain.BitcoindConfig{ cfg := &chain.BitcoindConfig{
ChainParams: NetParams, ChainParams: netParams,
Host: host, Host: host,
User: "weks", User: "weks",
Pass: "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 // NewNeutrinoBackend spawns a new neutrino node that connects to a miner at
// the specified address. // 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() t.Helper()
spvDir := t.TempDir() spvDir := t.TempDir()
@ -300,7 +302,7 @@ func NewNeutrinoBackend(t *testing.T, minerAddr string) *neutrino.ChainService {
spvConfig := neutrino.Config{ spvConfig := neutrino.Config{
DataDir: spvDir, DataDir: spvDir,
Database: spvDatabase, Database: spvDatabase,
ChainParams: *NetParams, ChainParams: *netParams,
ConnectPeers: []string{minerAddr}, ConnectPeers: []string{minerAddr},
} }
spvNode, err := neutrino.NewChainService(spvConfig) spvNode, err := neutrino.NewChainService(spvConfig)