From 0843d7ecb5f5d89db77ba0b975b2483ee6108ade Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Thu, 10 Oct 2024 10:18:42 -0500 Subject: [PATCH] Remove `-port` and `-rpcport` settings for `bitcoind` on startup for tests (#5702) * Remove -port and -rpcport settings for bitcoind on startup for tests * Revert logback-test.xml --- .../src/test/resources/sample-bitcoin.conf | 10 --- .../bitcoins/rpc/BitcoindInstanceTest.scala | 69 +++++-------------- .../org/bitcoins/rpc/v18/PsbtRpcTest.scala | 1 - .../bitcoins/rpc/client/common/Client.scala | 4 +- 4 files changed, 17 insertions(+), 67 deletions(-) delete mode 100644 bitcoind-rpc-test/src/test/resources/sample-bitcoin.conf diff --git a/bitcoind-rpc-test/src/test/resources/sample-bitcoin.conf b/bitcoind-rpc-test/src/test/resources/sample-bitcoin.conf deleted file mode 100644 index 4cc687459d..0000000000 --- a/bitcoind-rpc-test/src/test/resources/sample-bitcoin.conf +++ /dev/null @@ -1,10 +0,0 @@ -testnet=0 -regtest=1 -rpcuser=user -rpcpassword=password -zmqpubrawblock=tcp://127.0.0.1:29005 -zmppubrawtx=tcp://127.0.0.1:29001 -rpcport=18500 -port=9000 -daemon=1 -blockfilterindex=1 \ No newline at end of file diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala index 06c913d34d..68725e92b7 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/BitcoindInstanceTest.scala @@ -1,7 +1,6 @@ package org.bitcoins.rpc import org.bitcoins.core.config.RegTest -import org.bitcoins.core.currency.Bitcoins import org.bitcoins.rpc.client.common.BitcoindRpcClient import org.bitcoins.rpc.config.{ BitcoindAuthCredentials, @@ -11,34 +10,14 @@ import org.bitcoins.rpc.config.{ } import org.bitcoins.rpc.util.RpcUtil import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil -import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil.newestBitcoindBinary - import org.bitcoins.testkit.util.{BitcoindRpcTest, FileUtil} import org.scalatest.compatible.Assertion -import java.io.{File, PrintWriter} import java.net.URI -import java.nio.file.{Files, Path} import scala.concurrent.Future -import scala.io.Source -import scala.util.control.NonFatal class BitcoindInstanceTest extends BitcoindRpcTest { - private val sampleConf: Seq[String] = { - val source = Source.fromURL(getClass.getResource("/sample-bitcoin.conf")) - source.getLines().toSeq - } - - private val datadir: Path = Files.createTempDirectory(null) - - override protected def beforeAll(): Unit = { - val confFile = new File(datadir.toString + "/bitcoin.conf") - val pw = new PrintWriter(confFile) - sampleConf.foreach(line => pw.write(line + "\n")) - pw.close() - } - /** Tests that the client can call the isStartedF method without throwing and * then start */ @@ -63,12 +42,15 @@ class BitcoindInstanceTest extends BitcoindRpcTest { val confStr = s""" |regtest=1 |daemon=1 + |[regtest] |port=${RpcUtil.randomPort} |rpcport=${RpcUtil.randomPort} """.stripMargin val conf = BitcoindConfig(confStr, FileUtil.tmpDir()) - val instance = BitcoindInstanceLocal.fromConfig(conf, newestBitcoindBinary) + val instance = + BitcoindInstanceLocal.fromConfig(conf, + BitcoindRpcTestUtil.newestBitcoindBinary) assert( instance.authCredentials .isInstanceOf[BitcoindAuthCredentials.CookieBased] @@ -84,12 +66,15 @@ class BitcoindInstanceTest extends BitcoindRpcTest { |regtest=1 |rpcuser=foobar |rpcpassword=barfoo + |[regtest] |port=${RpcUtil.randomPort} |rpcport=${RpcUtil.randomPort} """.stripMargin val conf = BitcoindConfig(confStr, FileUtil.tmpDir()) - val instance = BitcoindInstanceLocal.fromConfig(conf, newestBitcoindBinary) + val instance = + BitcoindInstanceLocal.fromConfig(conf, + BitcoindRpcTestUtil.newestBitcoindBinary) assert( instance.authCredentials .isInstanceOf[BitcoindAuthCredentials.PasswordBased] @@ -112,8 +97,9 @@ class BitcoindInstanceTest extends BitcoindRpcTest { |daemon=1 |rpcauth=bitcoin-s:6d7580be1deb4ae52bc4249871845b09$$82b282e7c6493f6982a5a7af9fbb1b671bab702e2f31bbb1c016bb0ea1cc27ca |regtest=1 - |port=${RpcUtil.randomPort} - |rpcport=${RpcUtil.randomPort} + |[regtest] + |port=${port} + |rpcport=${rpcPort} """.stripMargin val conf = BitcoindConfig(confStr, FileUtil.tmpDir()) @@ -129,36 +115,12 @@ class BitcoindInstanceTest extends BitcoindRpcTest { rpcUri = new URI(s"http://localhost:$rpcPort"), authCredentials = authCredentials, datadir = conf.datadir, - binary = newestBitcoindBinary + binary = BitcoindRpcTestUtil.newestBitcoindBinary ) testClientStart(BitcoindRpcClient(instance)) } - it should "parse a bitcoin.conf file, start bitcoind, mine some blocks and quit" in { - val instance = - BitcoindInstanceLocal.fromDatadir(datadir.toFile, newestBitcoindBinary) - val client = - BitcoindRpcClient(instance) - - for { - _ <- startClient(client) - _ <- client.generate(101) - balance <- client.getBalance - _ <- BitcoindRpcTestUtil.stopServers(Vector(client)) - _ <- - client.getBalance - .map { balance => - logger.error(s"Got unexpected balance: $balance") - fail("Was able to connect to bitcoind after shutting down") - } - .recover { case NonFatal(_) => - () - } - } yield assert(balance > Bitcoins(0)) - - } - it should "connect us to a remote bitcoind instance and ping it successfully" in { val port = RpcUtil.randomPort val rpcPort = RpcUtil.randomPort @@ -166,8 +128,9 @@ class BitcoindInstanceTest extends BitcoindRpcTest { |daemon=1 |rpcauth=bitcoin-s:6d7580be1deb4ae52bc4249871845b09$$82b282e7c6493f6982a5a7af9fbb1b671bab702e2f31bbb1c016bb0ea1cc27ca |regtest=1 - |port=${RpcUtil.randomPort} - |rpcport=${RpcUtil.randomPort} + |[regtest] + |port=${port} + |rpcport=${rpcPort} """.stripMargin val conf = BitcoindConfig(confStr, FileUtil.tmpDir()) @@ -183,7 +146,7 @@ class BitcoindInstanceTest extends BitcoindRpcTest { rpcUri = new URI(s"http://localhost:$rpcPort"), authCredentials = authCredentials, datadir = conf.datadir, - binary = newestBitcoindBinary + binary = BitcoindRpcTestUtil.newestBitcoindBinary ) val client = diff --git a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/PsbtRpcTest.scala b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/PsbtRpcTest.scala index 5b04e339ca..b1b9675523 100644 --- a/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/PsbtRpcTest.scala +++ b/bitcoind-rpc-test/src/test/scala/org/bitcoins/rpc/v18/PsbtRpcTest.scala @@ -107,7 +107,6 @@ class PsbtRpcTest extends BitcoindFixturesFundedCachedNewest { val joinedF = client.joinPsbts(seqofpsbts) joinedF.map { result => - logger.info(s"result=${result.base64}") val allInputs = seqofpsbts.flatMap(_.transaction.inputs).distinct val allOutputs = seqofpsbts.flatMap(_.transaction.outputs).distinct assert(allInputs.forall(i => result.transaction.inputs.contains(i))) diff --git a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala index 5d75cb6bf1..b2ceef52fe 100644 --- a/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala +++ b/bitcoind-rpc/src/main/scala/org/bitcoins/rpc/client/common/Client.scala @@ -142,9 +142,7 @@ trait Client val binaryPath = local.binary.getAbsolutePath val cmd = Vector( binaryPath, - "-datadir=" + local.datadir, - "-rpcport=" + instance.rpcUri.getPort, - "-port=" + instance.uri.getPort + "-datadir=" + local.datadir ) logger.debug( s"starting bitcoind with datadir ${local.datadir} and binary path $binaryPath"