mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 19:37:30 +01:00
Get Scala 2.13.4 compiling (#2294)
* Get Scala 2.13.4 compiling * Fix broken test case, in general use if() else() statements for Vectors rather than pattern match as I am unsure of how to correctly pattern match on Vector0,Vector1,...,Vector6() * Bump CI to 2.13.4 * OVerride CurrencyUnit.equals() so that it works on Scala 2.13.4, not sure why there was a regression here between Scala versions 2.13.4/2.13.3 * Add explicit unit tests making sure bitcoin/satoshi currency units are equivalent
This commit is contained in:
parent
c5c7a423b2
commit
8836ed5e4f
10 changed files with 57 additions and 29 deletions
24
.travis.yml
24
.travis.yml
|
@ -9,7 +9,7 @@ jobs:
|
|||
name: Compile Website
|
||||
env:
|
||||
- TEST_COMMAND="docs/mdoc"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: trivial
|
||||
os: linux
|
||||
|
@ -30,14 +30,14 @@ jobs:
|
|||
name: Compile website
|
||||
env:
|
||||
- TEST_COMMAND="docs/mdoc"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: test
|
||||
name: Linux 2.13.3 bitcoind and eclair rpc tests
|
||||
name: Linux 2.13.4 bitcoind and eclair rpc tests
|
||||
os: linux
|
||||
env:
|
||||
- TEST_COMMAND="bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: test
|
||||
name: Linux 2.12.12 bitcoind and eclair rpc tests
|
||||
|
@ -47,11 +47,11 @@ jobs:
|
|||
scala: 2.12.12
|
||||
|
||||
- stage: test
|
||||
name: Linux 2.13.3 App, Chain, Node, and Core Tests
|
||||
name: Linux 2.13.4 App, Chain, Node, and Core Tests
|
||||
os: linux
|
||||
env:
|
||||
- TEST_COMMAND="chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls cryptoTest/test crypto/coverageReport crypto/coverageAggregate crypto/coveralls coreTest/test core/coverageReport core/coverageAggregate core/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: test
|
||||
name: Linux 2.12.12 App, Chain, Node, and Core Tests
|
||||
|
@ -60,11 +60,11 @@ jobs:
|
|||
- TEST_COMMAND="chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls cryptoTest/test crypto/coverageReport crypto/coverageAggregate crypto/coveralls coreTest/test core/coverageReport core/coverageAggregate core/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test"
|
||||
scala: 2.12.12
|
||||
- stage: test
|
||||
name: Linux 2.13.3 KeyManager Wallet, dlc tests
|
||||
name: Linux 2.13.4 KeyManager Wallet, dlc tests
|
||||
os: linux
|
||||
env:
|
||||
- TEST_COMMAND="keyManagerTest/test keyManager/coverageReport keyManager/coverageAggregate keyManager/coveralls walletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls dlcOracleTest/test dlcOracle/coverageReport dlcOracle/coverageAggregate dlcOracle/coveralls"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: test
|
||||
name: Linux 2.12.12 KeyManager, Wallet, dlc tests
|
||||
|
@ -79,7 +79,7 @@ jobs:
|
|||
env:
|
||||
- DISABLE_SECP256K1="true"
|
||||
- TEST_COMMAND="coreTest/test cryptoTest/test"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: test
|
||||
os: linux
|
||||
|
@ -87,14 +87,14 @@ jobs:
|
|||
env:
|
||||
- PG_ENABLED="1"
|
||||
- TEST_COMMAND="dbCommonsTest/test chainTest/test nodeTest/test walletTest/test"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
- stage: test
|
||||
os: osx
|
||||
name: "macOS bitcoind and eclair tests"
|
||||
env:
|
||||
- TEST_COMMAND="cryptoTest/test coreTest/test appCommonsTest/test bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
|
||||
# skip all test tagged as UsesExperimentalBitcoind
|
||||
# TODO remove this condition once we have a neutrino enabled bitcoind binary for OSX
|
||||
|
@ -103,7 +103,7 @@ jobs:
|
|||
name: "macOS wallet, node, dlc tests"
|
||||
env:
|
||||
- TEST_COMMAND="walletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcOracleTest/test dlcOracle/coverageReport dlcOracle/coveralls"
|
||||
scala: 2.13.3
|
||||
scala: 2.13.4
|
||||
# Release snapshots/versions of all libraries
|
||||
# run ci-release only if previous stages passed
|
||||
- stage: release
|
||||
|
|
|
@ -284,17 +284,18 @@ private[blockchain] trait BaseBlockChainCompObject
|
|||
val orderedHeaders =
|
||||
connectWalkBackwards(current = childHeader, ancestors = ancestors)
|
||||
|
||||
val initBlockchainOpt = orderedHeaders match {
|
||||
case Vector() | _ +: Vector() =>
|
||||
val initBlockchainOpt = {
|
||||
if (orderedHeaders.isEmpty || orderedHeaders.length == 1) {
|
||||
//for the case of _ +: Vector() this means only our
|
||||
//child header is in the chain, which means we
|
||||
//weren't able to form a blockchain
|
||||
None
|
||||
case h +: _ =>
|
||||
} else {
|
||||
//find our first header as we need it's Db representation
|
||||
//rather than just the raw header
|
||||
val dbOpt = ancestors.find(_.hashBE == h.hashBE)
|
||||
val dbOpt = ancestors.find(_.hashBE == orderedHeaders.head.hashBE)
|
||||
Some(Blockchain.fromHeaders(Vector(dbOpt.get)))
|
||||
}
|
||||
}
|
||||
|
||||
//now let's connect headers
|
||||
|
|
|
@ -63,23 +63,25 @@ class ChainHandler(
|
|||
val maxWork = groupedChains.keys.max
|
||||
val chainsByWork = groupedChains(maxWork)
|
||||
|
||||
val bestHeader: BlockHeaderDb = chainsByWork match {
|
||||
case Vector() =>
|
||||
val bestHeader: BlockHeaderDb = {
|
||||
if (chainsByWork.isEmpty) {
|
||||
// This should never happen
|
||||
val errMsg = s"Did not find blockchain with work $maxWork"
|
||||
logger.error(errMsg)
|
||||
throw new RuntimeException(errMsg)
|
||||
case chain +: Vector() =>
|
||||
chain.tip
|
||||
case chain +: rest =>
|
||||
} else if (chainsByWork.length == 1) {
|
||||
chainsByWork.head.tip
|
||||
} else {
|
||||
val tips = chainsByWork
|
||||
.map(_.tip.hashBE.hex)
|
||||
.mkString(", ")
|
||||
logger.warn(
|
||||
s"We have multiple competing blockchains with same work, selecting by time: ${(chain +: rest)
|
||||
.map(_.tip.hashBE.hex)
|
||||
.mkString(", ")}")
|
||||
s"We have multiple competing blockchains with same work, selecting by time: $tips")
|
||||
//since we have same chainwork, just take the oldest tip
|
||||
//as that's "more likely" to have been propagated first
|
||||
//and had more miners building on top of it
|
||||
chainsByWork.sortBy(_.tip.time).head.tip
|
||||
}
|
||||
}
|
||||
bestHeader
|
||||
}
|
||||
|
|
|
@ -11,6 +11,13 @@ class CurrencyUnitTest extends BitcoinSUnitTest {
|
|||
|
||||
behavior of "Satoshis"
|
||||
|
||||
it must "have 1BTC == 100,000,000 satoshis" in {
|
||||
assert(Bitcoins.one == Satoshis(100000000))
|
||||
assert(Satoshis(100000000) == Bitcoins.one)
|
||||
assert(Satoshis.zero == Bitcoins.zero)
|
||||
assert(Bitcoins.zero == Satoshis.zero)
|
||||
}
|
||||
|
||||
it must "have symmetry serialization" in {
|
||||
forAll(CurrencyUnitGenerator.satoshis) { satoshis =>
|
||||
assert(Satoshis(satoshis.hex) == satoshis)
|
||||
|
|
|
@ -38,6 +38,8 @@ object Base58ValidTestCaseProtocol extends DefaultJsonProtocol {
|
|||
Left(Sha256Hash160Digest(elements(1).convertTo[String]))
|
||||
case b if b.isRight =>
|
||||
Right(ECPrivateKey(elements(1).convertTo[String]))
|
||||
case _ =>
|
||||
sys.error(s"Should be left or right")
|
||||
}
|
||||
Base58ValidTestCaseImpl(addressOrPrivateKey(elements),
|
||||
isHashOrPrivKey(elements),
|
||||
|
|
|
@ -74,6 +74,19 @@ sealed abstract class CurrencyUnit
|
|||
def toBigDecimal: BigDecimal
|
||||
|
||||
protected def underlying: A
|
||||
|
||||
override def equals(obj: Any): Boolean = {
|
||||
//needed for cases like
|
||||
//1BTC == 100,000,000 satoshis should be true
|
||||
//weirdly enough, this worked in scala version < 2.13.4
|
||||
//but seems to be broken in 2.13.4 :/
|
||||
//try removing this and running code, you should see
|
||||
//failures in the 'walletTest' module
|
||||
obj match {
|
||||
case cu: CurrencyUnit => cu.satoshis == satoshis
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed abstract class Satoshis extends CurrencyUnit {
|
||||
|
|
|
@ -157,11 +157,11 @@ object LnTaggedFields {
|
|||
val newRemaining = t.slice(payload.size, t.size)
|
||||
|
||||
loop(newRemaining, fields :+ tag)
|
||||
case IndexedSeq() =>
|
||||
fields
|
||||
case _ +: _ | _ +: _ +: _ =>
|
||||
throw new IllegalArgumentException(
|
||||
"Failed to parse LnTaggedFields, needs 15bits of meta data to be able to parse")
|
||||
case _: Vector[_] =>
|
||||
fields
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,8 @@ sealed abstract class ScriptParser
|
|||
.decodeHex(
|
||||
BytesUtil.flipEndianness(
|
||||
h)) ++ bytesToPushOntoStack.bytes ++ accum)
|
||||
case Vector() => accum
|
||||
case _: Vector[_] =>
|
||||
accum
|
||||
}
|
||||
}
|
||||
if (tryParsingLong(str) && str.size > 1 && str.substring(0, 2) != "0x") {
|
||||
|
|
|
@ -3,7 +3,7 @@ import sbt.Keys.excludeLintKeys
|
|||
import scala.util.Properties
|
||||
|
||||
val scala2_12 = "2.12.12"
|
||||
val scala2_13 = "2.13.3"
|
||||
val scala2_13 = "2.13.4"
|
||||
|
||||
scalafmtOnCompile in ThisBuild := !Properties.envOrNone("CI").contains("true")
|
||||
|
||||
|
|
|
@ -99,7 +99,9 @@ object CommonSettings {
|
|||
"-Ywarn-unused",
|
||||
"-unchecked",
|
||||
"-deprecation",
|
||||
"-feature"
|
||||
"-feature",
|
||||
"-Ypatmat-exhaust-depth",
|
||||
"off"
|
||||
) ++ commonCompilerOpts ++ {
|
||||
if (scalaVersion.startsWith("2.13")) scala2_13CompilerOpts
|
||||
else nonScala2_13CompilerOpts
|
||||
|
|
Loading…
Add table
Reference in a new issue