mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 15:02:17 +01:00
Rework BitcoindRpcTestUtil.getBinary() to match major and minor versions of bitcoind binary when possible (#5569)
This commit is contained in:
parent
6dacfb071a
commit
cb3fbe523a
3 changed files with 43 additions and 23 deletions
|
@ -378,15 +378,15 @@ object BitcoindVersion
|
||||||
val known: Vector[BitcoindVersion] = standard
|
val known: Vector[BitcoindVersion] = standard
|
||||||
|
|
||||||
case object V25 extends BitcoindVersion {
|
case object V25 extends BitcoindVersion {
|
||||||
override def toString: String = "v25"
|
override def toString: String = "v25.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
case object V26 extends BitcoindVersion {
|
case object V26 extends BitcoindVersion {
|
||||||
override def toString: String = "v26"
|
override def toString: String = "v26.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
case object V27 extends BitcoindVersion {
|
case object V27 extends BitcoindVersion {
|
||||||
override def toString: String = "v27"
|
override def toString: String = "v27.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
case object Unknown extends BitcoindVersion {
|
case object Unknown extends BitcoindVersion {
|
||||||
|
@ -417,4 +417,17 @@ object BitcoindVersion
|
||||||
newest
|
newest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def findVersion(version: String): Option[BitcoindVersion] = {
|
||||||
|
// first try to match the version exactly
|
||||||
|
BitcoindVersion.known
|
||||||
|
.find(v => version == v.toString) match {
|
||||||
|
case Some(r) => Some(r)
|
||||||
|
case None =>
|
||||||
|
// try to match the major version if we can't match it exactly
|
||||||
|
BitcoindVersion.known.find { v =>
|
||||||
|
version.startsWith(v.toString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,17 +51,13 @@ sealed trait BitcoindInstanceLocal extends BitcoindInstance {
|
||||||
def getVersion: BitcoindVersion = {
|
def getVersion: BitcoindVersion = {
|
||||||
|
|
||||||
val binaryPath = binary.getAbsolutePath
|
val binaryPath = binary.getAbsolutePath
|
||||||
|
|
||||||
val versionT = Try {
|
val versionT = Try {
|
||||||
val foundVersion =
|
val foundVersion =
|
||||||
Seq(binaryPath, "--version").!!.split(Properties.lineSeparator).head
|
Seq(binaryPath, "--version").!!.split(Properties.lineSeparator).head
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.last
|
.last
|
||||||
BitcoindVersion.known
|
BitcoindVersion.findVersion(foundVersion).getOrElse {
|
||||||
.find(v => foundVersion.startsWith(v.toString))
|
// else just default to the newest version of bitcoind
|
||||||
.getOrElse {
|
|
||||||
println(
|
|
||||||
s"Unsupported Bitcoin Core version: $foundVersion. The latest supported version is ${BitcoindVersion.newest}")
|
|
||||||
logger.warn(
|
logger.warn(
|
||||||
s"Unsupported Bitcoin Core version: $foundVersion. The latest supported version is ${BitcoindVersion.newest}"
|
s"Unsupported Bitcoin Core version: $foundVersion. The latest supported version is ${BitcoindVersion.newest}"
|
||||||
)
|
)
|
||||||
|
|
|
@ -179,16 +179,25 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||||
// default to newest version
|
// default to newest version
|
||||||
case Unknown => getBinary(BitcoindVersion.newest, binaryDirectory)
|
case Unknown => getBinary(BitcoindVersion.newest, binaryDirectory)
|
||||||
case known @ (V25 | V26 | V27) =>
|
case known @ (V25 | V26 | V27) =>
|
||||||
val fileList = Files
|
val fileList: List[(Path, String)] = Files
|
||||||
.list(binaryDirectory)
|
.list(binaryDirectory)
|
||||||
.iterator()
|
.iterator()
|
||||||
.asScala
|
.asScala
|
||||||
.toList
|
.toList
|
||||||
.filter(f => Files.isDirectory(f))
|
.filter(f => Files.isDirectory(f))
|
||||||
|
.map(p => (p, p.toString.split("-").last))
|
||||||
// drop leading 'v'
|
// drop leading 'v'
|
||||||
val version = known.toString.drop(1)
|
val version = known.toString.drop(1)
|
||||||
val filtered = fileList.filter(f => f.toString.contains(version))
|
val exactMatchOpt = fileList.find { case (_, versionStr) =>
|
||||||
|
// try matching the version exactly
|
||||||
|
versionStr == version
|
||||||
|
}
|
||||||
|
|
||||||
|
val versionFolder: Path = exactMatchOpt match {
|
||||||
|
case Some((p, _)) =>
|
||||||
|
p
|
||||||
|
case None =>
|
||||||
|
val filtered = fileList.filter(f => f.toString.contains(version))
|
||||||
if (filtered.isEmpty)
|
if (filtered.isEmpty)
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
s"bitcoind ${known.toString} is not installed in $binaryDirectory. Run `sbt downloadBitcoind`"
|
s"bitcoind ${known.toString} is not installed in $binaryDirectory. Run `sbt downloadBitcoind`"
|
||||||
|
@ -197,6 +206,8 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||||
// might be multiple versions downloaded for
|
// might be multiple versions downloaded for
|
||||||
// each major version, i.e. 0.16.2 and 0.16.3
|
// each major version, i.e. 0.16.2 and 0.16.3
|
||||||
val versionFolder = filtered.max
|
val versionFolder = filtered.max
|
||||||
|
versionFolder._1
|
||||||
|
}
|
||||||
|
|
||||||
versionFolder
|
versionFolder
|
||||||
.resolve("bin")
|
.resolve("bin")
|
||||||
|
|
Loading…
Add table
Reference in a new issue