mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-19 01:40:55 +01:00
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:
parent
54646d4516
commit
0843d7ecb5
@ -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
|
@ -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 =
|
||||
|
@ -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)))
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user