From 7bf4eee68537efc3d52b4499020e5ff9604f5812 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 6 Mar 2023 15:32:53 +0200 Subject: [PATCH] chainntnfs: fix temp dir creation and rpcpolling switch In the NewBitcoindBackend test util function, ensure that the `rpcpolling` param is switched on in the correct order. Also switch back to using `ioutil.TempDir` as it seems that the zmq conn strings created from `t.TempDir()` result in an invalid conn string. --- chainntnfs/test_utils.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/chainntnfs/test_utils.go b/chainntnfs/test_utils.go index 401e2f052..fa6b7cd56 100644 --- a/chainntnfs/test_utils.go +++ b/chainntnfs/test_utils.go @@ -6,6 +6,7 @@ package chainntnfs import ( "errors" "fmt" + "io/ioutil" "math/rand" "os/exec" "path/filepath" @@ -197,7 +198,11 @@ func NewBitcoindBackend(t *testing.T, minerAddr string, txindex, t.Helper() - tempBitcoindDir := t.TempDir() + // 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") + require.NoError(t, err, "unable to create temp dir") rpcPort := rand.Intn(65536-1024) + 1024 zmqBlockHost := "ipc:///" + tempBitcoindDir + "/blocks.socket" @@ -241,20 +246,20 @@ func NewBitcoindBackend(t *testing.T, minerAddr string, txindex, } if rpcpolling { + cfg.PollingConfig = &chain.PollingConfig{ + BlockPollingInterval: time.Millisecond * 20, + TxPollingInterval: time.Millisecond * 20, + } + } else { cfg.ZMQConfig = &chain.ZMQConfig{ ZMQBlockHost: zmqBlockHost, ZMQTxHost: zmqTxHost, ZMQReadDeadline: 5 * time.Second, } - } else { - cfg.PollingConfig = &chain.PollingConfig{ - BlockPollingInterval: time.Millisecond * 20, - TxPollingInterval: time.Millisecond * 20, - } } var conn *chain.BitcoindConn - err := wait.NoError(func() error { + err = wait.NoError(func() error { var err error conn, err = chain.NewBitcoindConn(cfg) if err != nil {