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
This commit is contained in:
Chris Stewart 2024-10-10 10:18:42 -05:00 committed by GitHub
parent 54646d4516
commit 0843d7ecb5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 67 deletions

View File

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

View File

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

View File

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

View File

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