multi: change NewBitcoindBackend to take a miner as its param

Prepares for the following commit where we assert the chain backend is
synced to the miner.
This commit is contained in:
yyforyongyu 2025-02-25 21:33:16 +08:00
parent c725ba9f25
commit 99d49dec6a
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
5 changed files with 22 additions and 25 deletions

View file

@ -179,7 +179,7 @@ func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) {
)
bitcoindConn := unittest.NewBitcoindBackend(
t, unittest.NetParams, miner.P2PAddress(), true, rpcPolling,
t, unittest.NetParams, miner, true, rpcPolling,
)
hintCache := initHintCache(t)
@ -279,7 +279,7 @@ func testHistoricalConfDetailsNoTxIndex(t *testing.T, rpcpolling bool) {
miner := unittest.NewMiner(t, unittest.NetParams, nil, true, 25)
bitcoindConn := unittest.NewBitcoindBackend(
t, unittest.NetParams, miner.P2PAddress(), false, rpcpolling,
t, unittest.NetParams, miner, false, rpcpolling,
)
hintCache := initHintCache(t)

View file

@ -1932,7 +1932,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) {
case "bitcoind":
var bitcoindConn *chain.BitcoindConn
bitcoindConn = unittest.NewBitcoindBackend(
t, unittest.NetParams, p2pAddr, true, false,
t, unittest.NetParams, miner, true, false,
)
newNotifier = func() (chainntnfs.TestChainNotifier, error) {
return bitcoindnotify.New(
@ -1944,7 +1944,7 @@ func TestInterfaces(t *testing.T, targetBackEnd string) {
case "bitcoind-rpc-polling":
var bitcoindConn *chain.BitcoindConn
bitcoindConn = unittest.NewBitcoindBackend(
t, unittest.NetParams, p2pAddr, true, true,
t, unittest.NetParams, miner, true, true,
)
newNotifier = func() (chainntnfs.TestChainNotifier, error) {
return bitcoindnotify.New(

View file

@ -83,7 +83,7 @@ func NewMiner(t *testing.T, netParams *chaincfg.Params, extraArgs []string,
// 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, netParams *chaincfg.Params,
minerAddr string, txindex, rpcpolling bool) *chain.BitcoindConn {
miner *rpctest.Harness, txindex, rpcpolling bool) *chain.BitcoindConn {
t.Helper()
@ -204,7 +204,7 @@ func NewBitcoindBackend(t *testing.T, netParams *chaincfg.Params,
require.NoError(t, err, "failed to create RPC client")
// Connect to the miner node.
err = rpcClient.AddNode(minerAddr, rpcclient.ANAdd)
err = rpcClient.AddNode(miner.P2PAddress(), rpcclient.ANAdd)
require.NoError(t, err, "failed to connect to miner")
// Get the network info and assert the num of outbound connections is 1.

View file

@ -3352,8 +3352,7 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
case "bitcoind":
// Start a bitcoind instance.
chainConn := unittest.NewBitcoindBackend(
t, unittest.NetParams, miningNode.P2PAddress(),
true, false,
t, unittest.NetParams, miningNode, true, false,
)
// Create a btcwallet bitcoind client for both Alice and
@ -3364,8 +3363,7 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
case "bitcoind-rpc-polling":
// Start a bitcoind instance.
chainConn := unittest.NewBitcoindBackend(
t, unittest.NetParams, miningNode.P2PAddress(),
true, true,
t, unittest.NetParams, miningNode, true, true,
)
// Create a btcwallet bitcoind client for both Alice and

View file

@ -460,7 +460,7 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
// Init a chain view that has this node as its block source.
reorgView, err := chainViewInit(
t, reorgNode.RPCConfig(), reorgNode.P2PAddress(), bestHeight,
t, reorgNode.RPCConfig(), reorgNode, bestHeight,
)
require.NoError(t, err, "unable to create chain view")
@ -632,7 +632,7 @@ func testFilterBlockDisconnected(node *rpctest.Harness,
}
type chainViewInitFunc func(t *testing.T, rpcInfo rpcclient.ConnConfig,
p2pAddr string, bestHeight int32) (FilteredChainView, error)
miner *rpctest.Harness, bestHeight int32) (FilteredChainView, error)
type testCase struct {
name string
@ -666,12 +666,12 @@ var interfaceImpls = []struct {
{
name: "bitcoind_zmq",
chainViewInit: func(t *testing.T, _ rpcclient.ConnConfig,
p2pAddr string, bestHeight int32) (FilteredChainView,
error) {
miner *rpctest.Harness, bestHeight int32) (
FilteredChainView, error) {
// Start a bitcoind instance.
chainConn := unittest.NewBitcoindBackend(
t, unittest.NetParams, p2pAddr, true,
t, unittest.NetParams, miner, true,
false,
)
blockCache := blockcache.NewBlockCache(10000)
@ -686,12 +686,12 @@ var interfaceImpls = []struct {
{
name: "bitcoind_polling",
chainViewInit: func(t *testing.T, _ rpcclient.ConnConfig,
p2pAddr string, bestHeight int32) (FilteredChainView,
error) {
miner *rpctest.Harness, bestHeight int32) (
FilteredChainView, error) {
// Wait for the bitcoind instance to start up.
chainConn := unittest.NewBitcoindBackend(
t, unittest.NetParams, p2pAddr, true,
t, unittest.NetParams, miner, true,
true,
)
blockCache := blockcache.NewBlockCache(10000)
@ -706,8 +706,8 @@ var interfaceImpls = []struct {
{
name: "p2p_neutrino",
chainViewInit: func(t *testing.T, _ rpcclient.ConnConfig,
p2pAddr string, bestHeight int32) (FilteredChainView,
error) {
miner *rpctest.Harness, bestHeight int32) (
FilteredChainView, error) {
spvDir := t.TempDir()
@ -723,7 +723,7 @@ var interfaceImpls = []struct {
DataDir: spvDir,
Database: spvDatabase,
ChainParams: *netParams,
ConnectPeers: []string{p2pAddr},
ConnectPeers: []string{miner.P2PAddress()},
}
spvNode, err := neutrino.NewChainService(spvConfig)
@ -776,8 +776,8 @@ var interfaceImpls = []struct {
{
name: "btcd_websockets",
chainViewInit: func(_ *testing.T, config rpcclient.ConnConfig,
p2pAddr string, bestHeight int32) (FilteredChainView,
error) {
_ *rpctest.Harness, _ int32) (
FilteredChainView, error) {
blockCache := blockcache.NewBlockCache(10000)
chainView, err := NewBtcdFilteredChainView(
@ -802,7 +802,6 @@ func TestFilteredChainView(t *testing.T) {
)
rpcConfig := miner.RPCConfig()
p2pAddr := miner.P2PAddress()
for _, chainViewImpl := range interfaceImpls {
t.Logf("Testing '%v' implementation of FilteredChainView",
@ -814,7 +813,7 @@ func TestFilteredChainView(t *testing.T) {
}
chainView, err := chainViewImpl.chainViewInit(
t, rpcConfig, p2pAddr, bestHeight,
t, rpcConfig, miner, bestHeight,
)
if err != nil {
t.Fatalf("unable to make chain view: %v", err)