2023 12 19 compiler opts (#5330)

* Enable more compiler options

* enable -Xlint:valpattern, fix bug with out Test / scalacOptions were set with incorrect source code compiler flags

* Enable -Xlint:eta-sam

* Fix cryptoTestJVM

* Fix cryptoTestJS/test

* Fix asyncUtilTest

* Fix asyncUtilTest
This commit is contained in:
Chris Stewart 2023-12-20 05:42:01 -06:00 committed by GitHub
parent 54f303efb0
commit 16fb5d2dad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 192 additions and 118 deletions

View File

@ -64,7 +64,7 @@ class OracleRoutesSpec
"get public key" in {
val key = ECPublicKey.freshPublicKey.schnorrPublicKey
(mockOracleApi.publicKey: () => SchnorrPublicKey)
(() => mockOracleApi.publicKey())
.expects()
.returning(key)
@ -95,7 +95,7 @@ class OracleRoutesSpec
}
"list announcements" in {
(mockOracleApi.listEvents: () => Future[Vector[OracleEvent]])
(() => mockOracleApi.listEvents())
.expects()
.returning(Future.successful(Vector(dummyOracleEvent)))
@ -399,7 +399,7 @@ class OracleRoutesSpec
}
"get oracle name" in {
(mockOracleApi.oracleName: () => Future[Option[String]])
(() => mockOracleApi.oracleName())
.expects()
.returning(Future.successful(Some("oracle name")))

View File

@ -170,7 +170,7 @@ class DLCRoutesSpec
}
"contacts-list list contacts" in {
(mockWallet.listDLCContacts: () => Future[Vector[DLCContactDb]])
(() => mockWallet.listDLCContacts())
.expects()
.returning(Future.successful(Vector(expected)))

View File

@ -183,7 +183,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the block count" in {
(mockChainApi.getBlockCount: () => Future[Int])
(() => mockChainApi.getBlockCount())
.expects()
.returning(Future.successful(1234567890))
@ -197,7 +197,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the filter count" in {
(mockChainApi.getFilterCount: () => Future[Int])
(() => mockChainApi.getFilterCount())
.expects()
.returning(Future.successful(1234567890))
@ -211,7 +211,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the filter header count" in {
(mockChainApi.getFilterHeaderCount: () => Future[Int])
(() => mockChainApi.getFilterHeaderCount())
.expects()
.returning(Future.successful(1234567890))
@ -225,7 +225,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the best block hash" in {
(mockChainApi.getBestBlockHash: () => Future[DoubleSha256DigestBE])
(() => mockChainApi.getBestBlockHash())
.expects()
.returning(Future.successful(DoubleSha256DigestBE.empty))
@ -261,7 +261,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
.expects(blockHeader.hashBE)
.returning(Future.successful(Some(blockHeaderDb)))
(mockChainApi.getBestBlockHeader: () => Future[BlockHeaderDb])
(() => mockChainApi.getBestBlockHeader())
.expects()
.returning(Future.successful(blockHeaderDb))
@ -282,7 +282,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the median time past" in {
(mockChainApi.getMedianTimePast: () => Future[Long])
(() => mockChainApi.getMedianTimePast())
.expects()
.returning(Future.successful(1234567890L))
@ -327,7 +327,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the wallet's confirmed balance" in {
(mockWalletApi.getConfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getConfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
@ -342,7 +342,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the wallet's confirmed balance in sats" in {
(mockWalletApi.getConfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getConfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
@ -357,7 +357,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the wallet's unconfirmed balance" in {
(mockWalletApi.getUnconfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getUnconfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
@ -374,11 +374,11 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
val spendingInfoDb = TransactionTestUtil.spendingInfoDb
"return the wallet's balances in bitcoin" in {
(mockWalletApi.getConfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getConfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
(mockWalletApi.getUnconfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getUnconfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
@ -399,11 +399,11 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the wallet's balances in sats" in {
(mockWalletApi.getConfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getConfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
(mockWalletApi.getUnconfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getUnconfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
@ -424,7 +424,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return the wallet's unconfirmed balance in sats" in {
(mockWalletApi.getUnconfirmedBalance: () => Future[CurrencyUnit])
(() => mockWalletApi.getUnconfirmedBalance())
.expects()
.returning(Future.successful(Bitcoins(50)))
@ -439,7 +439,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"check if the wallet is empty" in {
(mockWalletApi.isEmpty: () => Future[Boolean])
(() => mockWalletApi.isEmpty())
.expects()
.returning(Future.successful(true))
@ -454,7 +454,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
"return the wallet utxos" in {
(mockWalletApi.listUtxos: () => Future[Vector[SpendingInfoDb]])
(() => mockWalletApi.listUtxos())
.expects()
.returning(Future.successful(Vector(spendingInfoDb)))
@ -494,7 +494,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
testAddress.scriptPubKey
)
(mockWalletApi.listAddresses: () => Future[Vector[AddressDb]])
(() => mockWalletApi.listAddresses())
.expects()
.returning(Future.successful(Vector(addressDb)))
@ -517,7 +517,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
testAddress.scriptPubKey
)
(mockWalletApi.listSpentAddresses: () => Future[Vector[AddressDb]])
(() => mockWalletApi.listSpentAddresses())
.expects()
.returning(Future.successful(Vector(addressDb)))
@ -540,9 +540,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
testAddress.scriptPubKey
)
(mockWalletApi.listFundedAddresses: () => Future[Vector[(
AddressDb,
CurrencyUnit)]])
(() => mockWalletApi.listFundedAddresses())
.expects()
.returning(Future.successful(Vector((addressDb, Satoshis.zero))))
@ -565,7 +563,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
testAddress.scriptPubKey
)
(mockWalletApi.listUnusedAddresses: () => Future[Vector[AddressDb]])
(() => mockWalletApi.listUnusedAddresses())
.expects()
.returning(Future.successful(Vector(addressDb)))
@ -589,7 +587,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
hdAccount =
HDAccount(HDCoin(HDPurposes.Legacy, HDCoinType.Testnet), 0))
(mockWalletApi.listAccounts: () => Future[Vector[AccountDb]])
(() => mockWalletApi.listAccounts())
.expects()
.returning(Future.successful(Vector(accountDb)))
@ -604,7 +602,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"return a new address" in {
(mockWalletApi.getNewAddress: () => Future[BitcoinAddress])
(() => mockWalletApi.getNewAddress())
.expects()
.returning(Future.successful(testAddress))
@ -657,7 +655,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"lock unspent" in {
(mockWalletApi.listUtxos: () => Future[Vector[SpendingInfoDb]])
(() => mockWalletApi.listUtxos())
.expects()
.returning(Future.successful(Vector(spendingInfoDb)))
.anyNumberOfTimes()
@ -777,7 +775,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
}
"get address labels" in {
(mockWalletApi.getAddressTags: () => Future[Vector[AddressTagDb]])
(() => mockWalletApi.getAddressTags())
.expects()
.returning(
Future.successful(Vector(AddressTagDb(testAddress, testLabel))))
@ -1703,7 +1701,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
"run wallet rescan" in {
// positive cases
(mockWalletApi.discoveryBatchSize: () => Int)
(() => mockWalletApi.discoveryBatchSize())
.expects()
.returning(100)
.atLeastOnce()
@ -1893,7 +1891,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
myPayout = Satoshis(2),
theirPayout = Satoshis.zero)
(mockWalletApi.getWalletAccounting: () => Future[DLCWalletAccounting])
(() => mockWalletApi.getWalletAccounting())
.expects()
.returning(Future.successful(accounting))

View File

@ -7,7 +7,7 @@ import org.bitcoins.core.protocol.BitcoinAddress
import org.bitcoins.core.protocol.dlc.models.DLCMessage.{DLCAccept, DLCOffer}
import org.bitcoins.core.protocol.dlc.models.DLCStatus
import org.bitcoins.core.protocol.tlv.{DLCOfferTLV, LnMessage, LnMessageFactory}
import org.bitcoins.core.wallet.fee.{FeeUnit, SatoshisPerVirtualByte}
import org.bitcoins.core.wallet.fee.{SatoshisPerVirtualByte}
import org.bitcoins.crypto.Sha256Digest
import org.bitcoins.feeprovider.ConstantFeeRateProvider
import org.bitcoins.node.Node
@ -50,7 +50,7 @@ class WalletRoutesSpec
"WalletRoutes" should {
"estimatefee" in {
(mockWalletApi.getFeeRate: () => Future[FeeUnit])
(() => mockWalletApi.getFeeRate())
.expects()
.returning(Future.successful(SatoshisPerVirtualByte.one))
val route =

View File

@ -136,7 +136,7 @@ class AsyncUtilTest extends BitcoinSJvmTest {
}
val _ =
AsyncUtil.awaitCondition(blockingTask)
AsyncUtil.awaitCondition(() => blockingTask())
//schedule a non blocking task second
val counter1 = new AtomicInteger(0)

View File

@ -443,14 +443,18 @@ class ChainHandler(
Map[DoubleSha256DigestBE, CompactFilterMessage]] = {
for {
newFilters <- newFiltersF
} yield {
newFilters.groupBy(_.blockHash.flip).map { case (blockHash, messages) =>
if (messages.size > 1) {
return Future.failed(DuplicateFilters(
s"Attempt to process ${messages.length} duplicate filters for blockHashBE=$blockHash"))
}
(blockHash, messages.head)
result = newFilters.groupBy(_.blockHash.flip).map {
case (blockHash, messages) =>
if (messages.size > 1) {
Future.failed(DuplicateFilters(
s"Attempt to process ${messages.length} duplicate filters for blockHashBE=$blockHash"))
} else {
Future.successful((blockHash, messages.head))
}
}
iter <- Future.sequence(result)
} yield {
iter.toMap
}
}

View File

@ -362,7 +362,7 @@ object DLCTxBuilder {
acceptSerialId: UInt64,
timeouts: DLCTimeouts,
fundingOutputRef: OutputReference): WitnessTransaction = {
val Vector(AdaptorPointCETPair(_, cet)) = buildCETs(
val cets = buildCETs(
Vector(adaptorPoint),
contractInfo,
offerFundingKey,
@ -374,8 +374,9 @@ object DLCTxBuilder {
timeouts,
fundingOutputRef
)
cet
require(cets.length == 1,
s"Cannot have more than 1 CET for buildCET, got=${cets.length}")
cets.head.wtx
}
def buildCETs(

View File

@ -41,8 +41,13 @@ class AesCryptTest extends BitcoinSCryptoTest {
AesCrypt.encryptWithIV(plainText, cipherText.iv, key)
assert(encrypted == cipherText)
val Right(decrypted) = AesCrypt.decrypt(cipherText, key)
assert(decrypted == plainText)
val decryptedE = AesCrypt.decrypt(cipherText, key)
decryptedE match {
case Left(_) => fail(s"Unsucessful decryption")
case Right(decrypted) =>
assert(decrypted == plainText)
}
}
val first =
@ -87,7 +92,11 @@ class AesCryptTest extends BitcoinSCryptoTest {
it must "pass an openssl hard coded vector" in {
val key = getKey(hex"5CE91F97ED28FD5D1172E23EB17B1BAA")
val plainText = "foobar"
val Right(plainbytes) = ByteVector.encodeUtf8(plainText)
val plainBytesE = ByteVector.encodeUtf8(plainText)
val plainbytes = plainBytesE match {
case Left(_) => fail(s"Unsuccessful encoding")
case Right(b) => b
}
val iv = getIV(hex"455014871CD34F8DCFD7C1E387987BFF")
//val expectedCipher = ByteVector.fromValidBase64("oE8HErg1lg==")
@ -98,11 +107,20 @@ class AesCryptTest extends BitcoinSCryptoTest {
// assert(encrypted.cipherText == expectedCipher)
assert(encrypted.iv == iv)
val Right(decrypted) = AesCrypt.decrypt(encrypted, key)
val decryptedE = AesCrypt.decrypt(encrypted, key)
val decrypted = decryptedE match {
case Left(_) => fail(s"Failed to decrypt")
case Right(b) => b
}
assert(decrypted == plainbytes)
val Right(decryptedText) = decrypted.decodeUtf8
assert(decryptedText == plainText)
val decodedTextE = decrypted.decodeUtf8
decodedTextE match {
case Left(_) => fail(s"Failed to decode text")
case Right(decryptedText) =>
assert(decryptedText == plainText)
}
}
/** REPL.it: https://repl.it/@torkelrogstad/aes-test
@ -131,7 +149,11 @@ class AesCryptTest extends BitcoinSCryptoTest {
)
val plaintext = "The quick brown fox jumps over the lazy dog. 👻 👻"
val Right(plainbytes) = ByteVector.encodeUtf8(plaintext)
val plainBytesE = ByteVector.encodeUtf8(plaintext)
val plainbytes = plainBytesE match {
case Left(_) => fail(s"Unsuccessful encoding")
case Right(b) => b
}
// decrypt our own encrypted data
{
@ -140,11 +162,19 @@ class AesCryptTest extends BitcoinSCryptoTest {
assert(encrypted.iv == iv)
assert(encrypted.cipherText == expectedCipher)
val Right(decrypted) = AesCrypt.decrypt(encrypted, key)
val decryptedE = AesCrypt.decrypt(encrypted, key)
val decrypted = decryptedE match {
case Left(_) => fail(s"Failed to decrypt")
case Right(b) => b
}
assert(decrypted == plainbytes)
val Right(decryptedText) = decrypted.decodeUtf8
assert(decryptedText == plaintext)
val decodedTextE = decrypted.decodeUtf8
decodedTextE match {
case Left(_) => fail(s"Failed to decode text")
case Right(decryptedText) =>
assert(decryptedText == plaintext)
}
}
// decrypt the expected cipher text
@ -152,11 +182,19 @@ class AesCryptTest extends BitcoinSCryptoTest {
val encrypted =
AesEncryptedData(cipherText = expectedCipher, iv = iv)
val Right(decrypted) = AesCrypt.decrypt(encrypted, key)
val decryptedE = AesCrypt.decrypt(encrypted, key)
val decrypted = decryptedE match {
case Left(_) => fail(s"Failed to decrypt")
case Right(b) => b
}
assert(decrypted == plainbytes)
val Right(decryptedText) = decrypted.decodeUtf8
assert(decryptedText == plaintext)
val decodedTextE = decrypted.decodeUtf8
decodedTextE match {
case Left(_) => fail(s"Failed to decode text")
case Right(decryptedText) =>
assert(decryptedText == plaintext)
}
}
}
@ -243,7 +281,11 @@ class AesCryptTest extends BitcoinSCryptoTest {
val key = getKey(hex"e67a00b510bcff7f4a0101ff5f7fb690")
val iv = getIV(hex"f43b7f80624e7f01123ac272beb1ff7f")
val plainText = "The quick brown fox jumps over the lazy dog."
val Right(plainbytes) = ByteVector.encodeUtf8(plainText)
val plainBytesE = ByteVector.encodeUtf8(plainText)
val plainbytes = plainBytesE match {
case Left(_) => fail(s"Unsuccessful encoding")
case Right(b) => b
}
val expectedCipher =
hex"09697c53d3a1e5ec5a465231e536c70428f53cb7d4030a707e42daa338ce147ec2d55c865e85dfb5072a1bf31a977cf4"
@ -254,18 +296,30 @@ class AesCryptTest extends BitcoinSCryptoTest {
// assert(encrypted.cipherText == expectedCipher)
assert(encrypted.iv == iv)
val Right(decrypted) = AesCrypt.decrypt(encrypted, key)
val decryptedE = AesCrypt.decrypt(encrypted, key)
val decrypted = decryptedE match {
case Left(_) => fail(s"Failed to decrypt")
case Right(b) => b
}
assert(decrypted == plainbytes)
val Right(decryptedText) = decrypted.decodeUtf8
assert(decryptedText == plainText)
val decodedTextE = decrypted.decodeUtf8
decodedTextE match {
case Left(_) => fail(s"Failed to decode text")
case Right(decryptedText) =>
assert(decryptedText == plainText)
}
}
// test decrypting ciphertext from pycrypto
{
val encrypted = AesEncryptedData(expectedCipher, iv)
val Right(decrypted) = AesCrypt.decrypt(encrypted, key)
val decryptedE = AesCrypt.decrypt(encrypted, key)
val decrypted = decryptedE match {
case Left(_) => fail(s"Failed to decrypt")
case Right(b) => b
}
/** The AES implementation in pycrypto refuses to work with
* data that's not padded to the block size (although this
@ -276,9 +330,12 @@ class AesCryptTest extends BitcoinSCryptoTest {
*/
assertPaddedEqual(decrypted, plainbytes)
val Right(decryptedText) = decrypted.decodeUtf8
assert(decryptedText.trim == plainText.trim)
val decodedTextE = decrypted.decodeUtf8
decodedTextE match {
case Left(_) => fail(s"Failed to decode text")
case Right(decryptedText) =>
assert(decryptedText.trim == plainText.trim)
}
}
}

View File

@ -19,7 +19,7 @@ import scala.concurrent.ExecutionContext
class DbManagementTest extends BitcoinSAsyncTest with EmbeddedPg {
def dbConfig(project: ProjectType): Config = {
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(project), pgUrl)
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(project), () => pgUrl())
}
def createChainDbManagement(

View File

@ -18,12 +18,16 @@ sealed trait DecryptedSeedState extends SeedState {
protected def strToEncrypt: String
def encrypt(password: AesPassword): EncryptedSeed = {
val Right(clearText) = ByteVector.encodeUtf8(strToEncrypt)
val (key, salt) = password.toKey
val clearTextE = ByteVector.encodeUtf8(strToEncrypt)
clearTextE match {
case Left(err) => throw err
case Right(clearText) =>
val (key, salt) = password.toKey
val encrypted = AesCrypt.encrypt(clearText, key)
val encrypted = AesCrypt.encrypt(clearText, key)
EncryptedSeed(encrypted, salt, creationTime, backupTimeOpt, imported)
EncryptedSeed(encrypted, salt, creationTime, backupTimeOpt, imported)
}
}
}

View File

@ -20,7 +20,7 @@ class BroadcastTransactionTest extends NodeTestWithCachedBitcoindNewest {
/** Wallet config with data directory set to user temp directory */
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl,
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(() => pgUrl(),
Vector.empty)
override type FixtureParam = NeutrinoNodeConnectedWithBitcoind

View File

@ -10,7 +10,7 @@ import org.scalatest.FutureOutcome
class DisconnectedPeerTest extends NodeUnitTest {
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl,
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(() => pgUrl(),
Vector.empty)
override type FixtureParam = NeutrinoNode

View File

@ -22,7 +22,7 @@ class NeutrinoNodeTest extends NodeTestWithCachedBitcoindPair {
/** Wallet config with data directory set to user temp directory */
override protected def getFreshConfig: BitcoinSAppConfig = {
BitcoinSTestAppConfig.getMultiPeerNeutrinoWithEmbeddedDbTestConfig(
pgUrl,
() => pgUrl(),
Vector.empty)
}

View File

@ -37,7 +37,7 @@ class NeutrinoNodeWithUncachedBitcoindTest extends NodeUnitTest with CachedTor {
override protected def getFreshConfig: BitcoinSAppConfig = {
BitcoinSTestAppConfig.getMultiPeerNeutrinoWithEmbeddedDbTestConfig(
pgUrl,
() => pgUrl(),
Vector.empty)
}

View File

@ -26,7 +26,7 @@ class NeutrinoNodeWithWalletTest extends NodeTestWithCachedBitcoindNewest {
/** Wallet config with data directory set to user temp directory */
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl,
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(() => pgUrl(),
Vector.empty)
override type FixtureParam = NeutrinoNodeFundedWalletBitcoind
@ -211,7 +211,7 @@ class NeutrinoNodeWithWalletTest extends NodeTestWithCachedBitcoindNewest {
_ = assert(!rescan)
rescanState <- wallet.fullRescanNeutrinoWallet(addressBatchSize = 7)
_ <- AsyncUtil.awaitConditionF(condition,
_ <- AsyncUtil.awaitConditionF(() => condition(),
maxTries = 200,
interval = 200.millis)
_ <- rescanState.asInstanceOf[RescanStarted].stop()

View File

@ -18,7 +18,7 @@ class PeerManagerTest extends NodeTestWithCachedBitcoindNewest {
/** Wallet config with data directory set to user temp directory */
override protected def getFreshConfig: BitcoinSAppConfig = {
BitcoinSTestAppConfig.getMultiPeerNeutrinoWithEmbeddedDbTestConfig(
pgUrl,
() => pgUrl(),
Vector.empty)
}

View File

@ -18,7 +18,7 @@ import scala.concurrent.duration.{DurationInt, FiniteDuration}
class ReConnectionTest extends NodeTestWithCachedBitcoindNewest {
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl,
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(() => pgUrl(),
Vector.empty)
override type FixtureParam = NeutrinoNodeConnectedWithBitcoind

View File

@ -26,7 +26,7 @@ class DataMessageHandlerTest extends NodeTestWithCachedBitcoindNewest {
/** Wallet config with data directory set to user temp directory */
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl,
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(() => pgUrl(),
Vector.empty)
override type FixtureParam = NeutrinoNodeConnectedWithBitcoind

View File

@ -54,6 +54,7 @@ object CommonSettings {
Compile / scalacOptions ++= compilerOpts(scalaVersion = scalaVersion.value),
Test / scalacOptions ++= testCompilerOpts(scalaVersion =
scalaVersion.value),
Test / scalacOptions --= scala2_13SourceCompilerOpts,
//remove annoying import unused things in the scala console
//https://stackoverflow.com/questions/26940253/in-sbt-how-do-you-override-scalacoptions-for-console-in-all-configurations
Compile / console / scalacOptions ~= (_ filterNot (s =>
@ -69,7 +70,6 @@ object CommonSettings {
//see: https://github.com/bitcoin-s/bitcoin-s/issues/3232
Compile / doc / scalacOptions ++= Vector(s"-Wconf:any:ws"),
Test / console / scalacOptions ++= (Compile / console / scalacOptions).value,
Test / scalacOptions ++= testCompilerOpts(scalaVersion.value),
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
assembly / test := {},
Compile / doc := {
@ -147,19 +147,33 @@ object CommonSettings {
/** Linting options for scalac */
private val scala2_13CompilerLinting = {
Seq(
"-Xfatal-warnings",
"-Xlint:unused",
"-Xlint:adapted-args",
"-Xlint:nullary-unit",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:missing-interpolator",
"-Xlint:eta-sam"
"-Xlint:eta-zero",
"-Xlint:eta-sam",
"-Xlint:doc-detached",
"-Xlint:private-shadow",
//"-Xlint:type-parameter-shadow" need to fix BinaryTree.scala
"-Xlint:poly-implicit-overload",
"-Xlint:option-implicit",
"-Xlint:delayedinit-select",
"-Xlint:package-object-classes",
"-Xlint:stars-align",
"-Xlint:constant",
"-Xlint:nonlocal-return",
"-Xlint:implicit-not-found",
"-Xlint:serial"
)
}
/** Compiler options for source code */
private val scala2_13SourceCompilerOpts = {
Seq("-Xfatal-warnings") ++ scala2_13CompilerLinting
Seq("-Xlint:valpattern")
}
private val nonScala2_13CompilerOpts = Seq(
@ -185,17 +199,14 @@ object CommonSettings {
"off"
) ++ commonCompilerOpts ++ {
if (scalaVersion.startsWith("2.13")) {
scala2_13SourceCompilerOpts
scala2_13SourceCompilerOpts ++ scala2_13CompilerLinting
} else nonScala2_13CompilerOpts
}
}
def testCompilerOpts(scalaVersion: String): Seq[String] = {
(commonCompilerOpts ++
//initialization checks: https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html
Vector("-Xcheckinit") ++
compilerOpts(scalaVersion))
.filterNot(_ == "-Xfatal-warnings")
//initialization checks: https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html
Vector("-Xcheckinit")
}
lazy val testSettings: Seq[Setting[_]] = Seq(

View File

@ -9,7 +9,8 @@ trait ChainDbUnitTest extends ChainUnitTest with EmbeddedPg {
implicit override lazy val cachedChainConf: ChainAppConfig = {
val memoryDb =
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(ProjectType.Chain), pgUrl)
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(ProjectType.Chain),
() => pgUrl())
val chainConfig: ChainAppConfig =
BitcoinSTestAppConfig.getNeutrinoTestConfig().chainConf
chainConfig.withOverrides(memoryDb)
@ -17,7 +18,8 @@ trait ChainDbUnitTest extends ChainUnitTest with EmbeddedPg {
override lazy val mainnetAppConfig: ChainAppConfig = {
val memoryDb =
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(ProjectType.Chain), pgUrl)
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(ProjectType.Chain),
() => pgUrl())
val mainnetConf = ConfigFactory.parseString("bitcoin-s.network = mainnet")
val chainConfig: ChainAppConfig =
BitcoinSTestAppConfig.getNeutrinoTestConfig(mainnetConf).chainConf

View File

@ -21,13 +21,13 @@ trait TestAppConfigFixture
}
def withTestAppConfig(test: OneArgAsyncTest): FutureOutcome = {
makeDependentFixture(getFreshTestConfig, destroyTestConfig)(test)
makeDependentFixture(() => getFreshTestConfig(), destroyTestConfig)(test)
}
def getFreshTestConfig(): Future[TestAppConfig] = {
val configOverride = BitcoinSTestAppConfig.configWithEmbeddedDb(
Some(ProjectType.Test),
pgUrl = pgUrl)
pgUrl = () => pgUrl())
val config =
TestAppConfig(BitcoinSTestAppConfig.tmpDir(), Vector(configOverride))

View File

@ -20,7 +20,8 @@ sealed trait TestDAOFixture
implicit private val testConfig: TestAppConfig = {
val configOverrides =
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(ProjectType.Test), pgUrl)
BitcoinSTestAppConfig.configWithEmbeddedDb(Some(ProjectType.Test),
() => pgUrl())
TestAppConfig(BitcoinSTestAppConfig.tmpDir(), Vector(configOverrides))
}

View File

@ -19,7 +19,8 @@ trait BitcoinSDLCNodeTest extends BitcoinSWalletTest with CachedTor {
s"""bitcoin-s.dlcnode.listen = "127.0.0.1:${RpcUtil.randomPort}" """)
.withFallback(BaseWalletTest.segwitWalletConf)
BaseWalletTest.getFreshConfig(pgUrl, Vector(dlcListenWithSegwitWallet))
BaseWalletTest.getFreshConfig(() => pgUrl(),
Vector(dlcListenWithSegwitWallet))
}
/** Creates two DLC nodes with wallets that are funded with some bitcoin,

View File

@ -59,11 +59,11 @@ trait BitcoinSAppConfigBitcoinFixtureStarted
for {
_ <- cachedBitcoindWithFundsF
bitcoinSAppConfig1 = BitcoinSTestAppConfig
.getNeutrinoWithEmbeddedDbTestConfig(pgUrl = pgUrl,
.getNeutrinoWithEmbeddedDbTestConfig(pgUrl = () => pgUrl(),
config = Vector.empty,
forceNamedWallet = true)
bitcoinSAppConfig2 = BitcoinSTestAppConfig
.getNeutrinoWithEmbeddedDbTestConfig(pgUrl = pgUrl,
.getNeutrinoWithEmbeddedDbTestConfig(pgUrl = () => pgUrl(),
config = Vector.empty,
forceNamedWallet = true)
_ <- bitcoinSAppConfig1.start()

View File

@ -14,7 +14,8 @@ trait DLCOracleAppConfigFixture extends BitcoinSFixture with EmbeddedPg {
def withFixture(test: OneArgAsyncTest): FutureOutcome = {
val builder: () => Future[DLCOracleAppConfig] = () => {
val conf: DLCOracleAppConfig =
BitcoinSTestAppConfig.getDLCOracleWithEmbeddedDbTestConfig(pgUrl)
BitcoinSTestAppConfig.getDLCOracleWithEmbeddedDbTestConfig(() =>
pgUrl())
val _ = conf.migrate()
Future.successful(conf)
}

View File

@ -16,7 +16,7 @@ case class DLCOracleDAOs(
trait DLCOracleDAOFixture extends BitcoinSFixture with EmbeddedPg {
implicit protected val config: DLCOracleAppConfig =
BitcoinSTestAppConfig.getDLCOracleWithEmbeddedDbTestConfig(pgUrl)
BitcoinSTestAppConfig.getDLCOracleWithEmbeddedDbTestConfig(() => pgUrl())
override type FixtureParam = DLCOracleDAOs

View File

@ -15,7 +15,8 @@ trait DLCOracleFixture extends BitcoinSFixture with EmbeddedPg {
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
val builder: () => Future[DLCOracle] = () => {
val conf: DLCOracleAppConfig =
BitcoinSTestAppConfig.getDLCOracleWithEmbeddedDbTestConfig(pgUrl)
BitcoinSTestAppConfig.getDLCOracleWithEmbeddedDbTestConfig(() =>
pgUrl())
val _ = conf.migrate()
val oracleConfF: Future[Unit] = conf.start()

View File

@ -17,7 +17,7 @@ trait NodeDAOFixture extends NodeUnitTest with CachedBitcoinSAppConfig {
/** Wallet config with data directory set to user temp directory */
override protected def getFreshConfig: BitcoinSAppConfig =
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(pgUrl,
BitcoinSTestAppConfig.getNeutrinoWithEmbeddedDbTestConfig(() => pgUrl(),
Vector.empty)
private lazy val daos = {

View File

@ -29,7 +29,7 @@ trait BaseWalletTest extends EmbeddedPg { _: Suite with BitcoinSAkkaAsyncTest =>
val bipPasswordOpt = KeyManagerTestUtil.bip39PasswordOpt
val bip39Config =
BitcoinSWalletTest.buildBip39PasswordConfig(bipPasswordOpt)
BaseWalletTest.getFreshConfig(pgUrl, Vector(bip39Config))
BaseWalletTest.getFreshConfig(() => pgUrl(), Vector(bip39Config))
}
protected def getFreshWalletAppConfig: WalletAppConfig = {

View File

@ -33,7 +33,7 @@ trait BitcoinSDualWalletTest extends BitcoinSWalletTest {
val walletNameConfig =
ConfigFactory.parseString(s"bitcoin-s.wallet.walletName=$randomHex")
val extraConfig = segwitConfig.withFallback(walletNameConfig)
BaseWalletTest.getFreshConfig(pgUrl, Vector(extraConfig))
BaseWalletTest.getFreshConfig(() => pgUrl(), Vector(extraConfig))
}
/** Enables external payout addresses which is needed for some unit tests */

View File

@ -188,7 +188,7 @@ trait BitcoinSWalletTest
def withWalletConfig(test: OneArgAsyncTest): FutureOutcome = {
val builder: () => Future[WalletAppConfig] = () => {
createWalletAppConfig(pgUrl, Vector.empty)
createWalletAppConfig(() => pgUrl(), Vector.empty)
}
val destroy: WalletAppConfig => Future[Unit] = walletAppConfig => {
@ -199,7 +199,7 @@ trait BitcoinSWalletTest
def withWalletConfigNotStarted(test: OneArgAsyncTest): FutureOutcome = {
val builder: () => Future[WalletAppConfig] = () => {
createWalletAppConfigNotStarted(pgUrl, Vector.empty)
createWalletAppConfigNotStarted(() => pgUrl(), Vector.empty)
}
val destroy: WalletAppConfig => Future[Unit] = _ => {

View File

@ -30,7 +30,7 @@ trait DualWalletTestCachedBitcoind
val walletNameConfig =
ConfigFactory.parseString(s"bitcoin-s.wallet.walletName=$randomHex")
val extraConfig = config.withFallback(walletNameConfig)
BaseWalletTest.getFreshConfig(pgUrl, Vector(extraConfig))
BaseWalletTest.getFreshConfig(() => pgUrl(), Vector(extraConfig))
}
implicit protected def wallet2AppConfig: WalletAppConfig = {

View File

@ -49,7 +49,7 @@ trait WalletAppConfigWithBitcoindNewestFixtures
makeDependentFixture[WalletAppConfigWithBitcoindRpc](
() => {
val walletConfig =
BaseWalletTest.getFreshWalletAppConfig(pgUrl, Vector.empty)
BaseWalletTest.getFreshWalletAppConfig(() => pgUrl(), Vector.empty)
for {
_ <- walletConfig.start()
model = WalletAppConfigWithBitcoindRpc(walletConfig, bitcoind)

View File

@ -269,18 +269,11 @@ object TorAppConfig extends AppConfigFactory[TorAppConfig] {
private lazy val ports = {
val proxyPort = NetworkUtil.randomPort()
def findControlPort: Int = {
1.to(1024).foreach { _ =>
val controlPort = NetworkUtil.randomPort()
if (proxyPort != controlPort) {
return controlPort
}
}
throw new RuntimeException("Cannot find a non-bound port")
var controlPort = proxyPort
while (proxyPort == controlPort) {
controlPort = NetworkUtil.randomPort()
}
TorPorts(proxyPort, findControlPort)
TorPorts(proxyPort, controlPort)
}
}