mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 22:36:34 +01:00
testkit refactor (rename and repackage) (#355)
* Refactored testkit to have a package called testkit and renamed AsyncUtil and TestUtil, ran scalafmt * Updated internal file names list
This commit is contained in:
parent
0e9e021ad7
commit
a0c1ab91b4
84 changed files with 321 additions and 282 deletions
|
@ -7,6 +7,7 @@ import akka.testkit.TestKit
|
|||
import org.bitcoins.core.currency.Bitcoins
|
||||
import org.bitcoins.rpc.client.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.config.BitcoindInstance
|
||||
import org.bitcoins.testkit.rpc.{BitcoindRpcTestUtil, TestRpcUtil}
|
||||
import org.scalatest.{AsyncFlatSpec, BeforeAndAfterAll}
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
@ -43,7 +44,7 @@ class BitcoindInstanceTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
|||
val instance = BitcoindInstance.fromDatadir(datadir.toFile)
|
||||
val client = new BitcoindRpcClient(instance)
|
||||
BitcoindRpcTestUtil.startServers(Vector(client))
|
||||
RpcUtil.awaitServer(client)
|
||||
TestRpcUtil.awaitServer(client)
|
||||
|
||||
for {
|
||||
_ <- client.generate(101)
|
||||
|
@ -52,7 +53,7 @@ class BitcoindInstanceTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
|||
assert(balance > Bitcoins(0))
|
||||
client.stop()
|
||||
}
|
||||
_ <- Future.successful(RpcUtil.awaitServerShutdown(client))
|
||||
_ <- Future.successful(TestRpcUtil.awaitServerShutdown(client))
|
||||
} yield succeed
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.File
|
|||
import akka.actor.ActorSystem
|
||||
import akka.stream.ActorMaterializer
|
||||
import org.bitcoins.rpc.client.BitcoindRpcClient
|
||||
import org.bitcoins.testkit.rpc.{BitcoindRpcTestUtil, TestRpcUtil}
|
||||
import org.scalatest.exceptions.TestFailedException
|
||||
import org.scalatest.{AsyncFlatSpec, BeforeAndAfterAll}
|
||||
|
||||
|
@ -12,7 +13,7 @@ import scala.concurrent.duration.DurationInt
|
|||
import scala.concurrent.{Await, Future}
|
||||
import scala.util.Success
|
||||
|
||||
class RpcUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||
class TestRpcUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||
|
||||
implicit val system = ActorSystem("RpcUtilTest_ActorSystem")
|
||||
implicit val ec = system.dispatcher
|
||||
|
@ -33,10 +34,10 @@ class RpcUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
|||
boolLaterDoneAnd(true, trueLater)
|
||||
}
|
||||
|
||||
behavior of "RpcUtil"
|
||||
behavior of "TestRpcUtil"
|
||||
|
||||
it should "complete immediately if condition is true" in {
|
||||
RpcUtil
|
||||
TestRpcUtil
|
||||
.retryUntilSatisfiedF(conditionF = () => Future.successful(true),
|
||||
duration = 0.millis)
|
||||
.map { _ =>
|
||||
|
@ -46,14 +47,15 @@ class RpcUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
|||
|
||||
it should "fail if condition is false" in {
|
||||
recoverToSucceededIf[TestFailedException] {
|
||||
RpcUtil.retryUntilSatisfiedF(conditionF = () => Future.successful(false),
|
||||
duration = 0.millis)
|
||||
TestRpcUtil.retryUntilSatisfiedF(conditionF =
|
||||
() => Future.successful(false),
|
||||
duration = 0.millis)
|
||||
}
|
||||
}
|
||||
|
||||
it should "succeed after a delay" in {
|
||||
val boolLater = trueLater(delay = 250)
|
||||
RpcUtil.retryUntilSatisfiedF(boolLaterDoneAndTrue(boolLater)).map { _ =>
|
||||
TestRpcUtil.retryUntilSatisfiedF(boolLaterDoneAndTrue(boolLater)).map { _ =>
|
||||
succeed
|
||||
}
|
||||
}
|
||||
|
@ -61,26 +63,26 @@ class RpcUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
|||
it should "fail if there is a delay and duration is zero" in {
|
||||
val boolLater = trueLater(delay = 250)
|
||||
recoverToSucceededIf[TestFailedException] {
|
||||
RpcUtil.retryUntilSatisfiedF(boolLaterDoneAndTrue(boolLater),
|
||||
duration = 0.millis)
|
||||
TestRpcUtil.retryUntilSatisfiedF(boolLaterDoneAndTrue(boolLater),
|
||||
duration = 0.millis)
|
||||
}
|
||||
}
|
||||
|
||||
it should "succeed immediately if condition is true" in {
|
||||
RpcUtil.awaitCondition(condition = () => true, 0.millis)
|
||||
TestRpcUtil.awaitCondition(condition = () => true, 0.millis)
|
||||
succeed
|
||||
}
|
||||
|
||||
it should "timeout if condition is false" in {
|
||||
assertThrows[TestFailedException] {
|
||||
RpcUtil.awaitCondition(condition = () => false, duration = 0.millis)
|
||||
TestRpcUtil.awaitCondition(condition = () => false, duration = 0.millis)
|
||||
}
|
||||
}
|
||||
|
||||
it should "block for a delay and then succeed" in {
|
||||
val boolLater = trueLater(delay = 250)
|
||||
val before: Long = System.currentTimeMillis
|
||||
RpcUtil.awaitConditionF(boolLaterDoneAndTrue(boolLater))
|
||||
TestRpcUtil.awaitConditionF(boolLaterDoneAndTrue(boolLater))
|
||||
val after: Long = System.currentTimeMillis
|
||||
assert(after - before >= 250)
|
||||
}
|
||||
|
@ -88,8 +90,8 @@ class RpcUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
|||
it should "timeout if there is a delay and duration is zero" in {
|
||||
val boolLater = trueLater(delay = 250)
|
||||
assertThrows[TestFailedException] {
|
||||
RpcUtil.awaitConditionF(boolLaterDoneAndTrue(boolLater),
|
||||
duration = 0.millis)
|
||||
TestRpcUtil.awaitConditionF(boolLaterDoneAndTrue(boolLater),
|
||||
duration = 0.millis)
|
||||
}
|
||||
}
|
||||
|
|
@ -50,17 +50,22 @@ abstract class AsyncUtil extends BitcoinSLogger {
|
|||
message: String,
|
||||
caller: Array[StackTraceElement])
|
||||
extends Exception(message) {
|
||||
|
||||
/*
|
||||
Someone who calls a method in this class will be interested
|
||||
* in where the call was made (and the stack trace from there
|
||||
* backwards) and what happens between their call and the failure,
|
||||
* i.e. the internal calls of this class, are not of interest.
|
||||
*
|
||||
*
|
||||
* This trims the top of the stack trace to exclude these internal calls.
|
||||
*/
|
||||
private val relevantStackTrace = caller.tail
|
||||
.dropWhile(elem => elem.getFileName == "AsyncUtil.scala"
|
||||
|| elem.getFileName == "RpcUtil.scala")
|
||||
val internalFiles: Vector[String] = Vector("AsyncUtil.scala",
|
||||
"RpcUtil.scala",
|
||||
"TestAsyncUtil.scala",
|
||||
"TestRpcUtil.scala")
|
||||
|
||||
private val relevantStackTrace =
|
||||
caller.tail.dropWhile(elem => internalFiles.contains(elem.getFileName))
|
||||
|
||||
this.setStackTrace(relevantStackTrace)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.crypto
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.bitcoins.core.util.BitcoinSUnitTest
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.crypto
|
||||
|
||||
import org.bitcoinj.core.Sha256Hash
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.scalatest.prop.PropertyChecks
|
||||
import org.scalatest.{FlatSpec, MustMatchers}
|
||||
import scodec.bits.ByteVector
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.crypto
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Gen, Prop, Properties}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.crypto
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.bitcoins.core.util.BitcoinSUnitTest
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.crypto
|
||||
|
||||
import org.bitcoins.core.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.core.gen.TransactionGenerators
|
||||
import org.bitcoins.core.script.PreExecutionScriptProgram
|
||||
import org.bitcoins.core.script.interpreter.ScriptInterpreter
|
||||
import org.bitcoins.core.script.result._
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package org.bitcoins.core.number
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.util.BitcoinSUnitTest
|
||||
import org.scalatest.prop.PropertyChecks
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
import scala.util.Try
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
import scala.util.Try
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Gen, Prop, Properties}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.scalatest.prop.PropertyChecks
|
||||
import org.scalatest.{FlatSpec, MustMatchers}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
import scala.util.Try
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.number
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Gen, Prop, Properties}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol
|
||||
|
||||
import org.bitcoins.core.gen.{
|
||||
import org.bitcoins.testkit.core.gen.{
|
||||
AddressGenerator,
|
||||
ChainParamsGenerator,
|
||||
ScriptGenerators
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.bitcoins.core.protocol
|
|||
|
||||
import org.bitcoins.core.config.{MainNet, TestNet3}
|
||||
import org.bitcoins.core.crypto.ECPublicKey
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.number.{UInt5, UInt8}
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.bitcoins.core.util.{Bech32, BitcoinSUnitTest}
|
||||
|
@ -135,7 +135,6 @@ class Bech32Test extends BitcoinSUnitTest {
|
|||
Seq(31, 31, 31, 31, 31, 31, 31, 31, 31, 28).map(i => UInt5(i.toByte)))
|
||||
}
|
||||
|
||||
|
||||
it must "encode from 8 bit to 5 bit and back" in {
|
||||
forAll(NumberGenerator.uInt8s) { u8s =>
|
||||
val u5s = Bech32.from8bitTo5bit(u8s.toVector)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.protocol
|
||||
|
||||
import org.bitcoins.core.config.TestNet3
|
||||
import org.bitcoins.core.gen.{
|
||||
import org.bitcoins.testkit.core.gen.{
|
||||
AddressGenerator,
|
||||
CryptoGenerators,
|
||||
ScriptGenerators
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.blockchain
|
||||
|
||||
import org.bitcoins.core.gen.BlockchainElementsGenerator
|
||||
import org.bitcoins.testkit.core.gen.BlockchainElementsGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.protocol.blockchain
|
||||
|
||||
import org.bitcoins.core.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.core.gen.MerkleGenerator
|
||||
import org.bitcoins.testkit.core.gen.MerkleGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.protocol.blockchain
|
||||
|
||||
import org.bitcoins.core.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.core.gen.MerkleGenerator
|
||||
import org.bitcoins.testkit.core.gen.MerkleGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
package org.bitcoins.core.protocol.ln
|
||||
|
||||
import org.bitcoins.core.crypto.ECPrivateKey
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.core.gen.ln.LnInvoiceGen
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.ln.LnInvoiceGen
|
||||
import org.bitcoins.core.util.BitcoinSUnitTest
|
||||
|
||||
class LnInvoiceSignatureTest extends BitcoinSUnitTest {
|
||||
|
||||
override implicit val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode
|
||||
override implicit val generatorDrivenConfig: PropertyCheckConfiguration =
|
||||
generatorDrivenConfigNewCode
|
||||
|
||||
behavior of "LnInvoiceSignature"
|
||||
|
||||
|
||||
it must "have serialization symmetry for raw r,s,recovId" in {
|
||||
forAll(CryptoGenerators.digitalSignature, LnInvoiceGen.signatureVersion) {
|
||||
case (ecSig, recovId) =>
|
||||
|
||||
val lnSig = LnInvoiceSignature.fromRS(
|
||||
r = ecSig.r.bigInteger,
|
||||
s = ecSig.s.bigInteger,
|
||||
recovId = recovId)
|
||||
val lnSig = LnInvoiceSignature.fromRS(r = ecSig.r.bigInteger,
|
||||
s = ecSig.s.bigInteger,
|
||||
recovId = recovId)
|
||||
|
||||
val serialized = lnSig.hex
|
||||
|
||||
|
@ -33,29 +31,31 @@ class LnInvoiceSignatureTest extends BitcoinSUnitTest {
|
|||
}
|
||||
|
||||
it must "have serialization symmetry" in {
|
||||
forAll(LnInvoiceGen.lnInvoiceSignature) { case sig =>
|
||||
assert(LnInvoiceSignature.fromHex(sig.hex) == sig)
|
||||
forAll(LnInvoiceGen.lnInvoiceSignature) {
|
||||
case sig =>
|
||||
assert(LnInvoiceSignature.fromHex(sig.hex) == sig)
|
||||
}
|
||||
}
|
||||
|
||||
it must "be able to generate signatures, and then verify those signatures" in {
|
||||
it must "be able to generate signatures, and then verify those signatures" in {
|
||||
val gen = LnInvoiceGen
|
||||
forAll(gen.lnHrp, gen.taggedFields(None), gen.invoiceTimestamp) { case (hrp,tags,timestamp) =>
|
||||
val key = ECPrivateKey.freshPrivateKey
|
||||
val signature = LnInvoice.buildLnInvoiceSignature(
|
||||
forAll(gen.lnHrp, gen.taggedFields(None), gen.invoiceTimestamp) {
|
||||
case (hrp, tags, timestamp) =>
|
||||
val key = ECPrivateKey.freshPrivateKey
|
||||
val signature = LnInvoice.buildLnInvoiceSignature(
|
||||
hrp = hrp,
|
||||
timestamp = timestamp,
|
||||
lnTags = tags,
|
||||
privateKey = key
|
||||
)
|
||||
)
|
||||
|
||||
val hash = LnInvoice.buildSigHashData(
|
||||
hrp = hrp,
|
||||
timestamp = timestamp,
|
||||
lnTags = tags
|
||||
)
|
||||
val hash = LnInvoice.buildSigHashData(
|
||||
hrp = hrp,
|
||||
timestamp = timestamp,
|
||||
lnTags = tags
|
||||
)
|
||||
|
||||
assert(key.publicKey.verify(hash,signature.signature))
|
||||
assert(key.publicKey.verify(hash, signature.signature))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
package org.bitcoins.core.protocol.ln
|
||||
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.gen.ln.LnInvoiceGen
|
||||
import org.bitcoins.testkit.core.gen.ln.LnInvoiceGen
|
||||
import org.bitcoins.core.number.{UInt32, UInt64, UInt8}
|
||||
import org.bitcoins.core.protocol.ln.LnParams.{LnBitcoinMainNet, LnBitcoinTestNet}
|
||||
import org.bitcoins.core.protocol.ln.currency.{MicroBitcoins, MilliBitcoins, MilliSatoshis}
|
||||
import org.bitcoins.core.protocol.ln.fee.{FeeBaseMSat, FeeProportionalMillionths}
|
||||
import org.bitcoins.core.protocol.ln.LnParams.{
|
||||
LnBitcoinMainNet,
|
||||
LnBitcoinTestNet
|
||||
}
|
||||
import org.bitcoins.core.protocol.ln.currency.{
|
||||
MicroBitcoins,
|
||||
MilliBitcoins,
|
||||
MilliSatoshis
|
||||
}
|
||||
import org.bitcoins.core.protocol.ln.fee.{
|
||||
FeeBaseMSat,
|
||||
FeeProportionalMillionths
|
||||
}
|
||||
import org.bitcoins.core.protocol.ln.routing.LnRoute
|
||||
import org.bitcoins.core.protocol.{Bech32Address, P2PKHAddress, P2SHAddress}
|
||||
import org.bitcoins.core.util.{BitcoinSUnitTest, CryptoUtil}
|
||||
|
@ -14,7 +24,8 @@ import scodec.bits.ByteVector
|
|||
class LnInvoiceUnitTest extends BitcoinSUnitTest {
|
||||
behavior of "LnInvoice"
|
||||
|
||||
override implicit val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode
|
||||
override implicit val generatorDrivenConfig: PropertyCheckConfiguration =
|
||||
generatorDrivenConfigNewCode
|
||||
|
||||
val hrpEmpty = LnHumanReadablePart(LnBitcoinMainNet)
|
||||
|
||||
|
@ -368,7 +379,6 @@ class LnInvoiceUnitTest extends BitcoinSUnitTest {
|
|||
it must "have serialization symmetry for the invoices" in {
|
||||
|
||||
forAll(LnInvoiceGen.lnInvoice) { invoice =>
|
||||
|
||||
LnInvoice.fromString(invoice.toString).get == invoice
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package org.bitcoins.core.protocol.ln
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.number.{UInt5, UInt64}
|
||||
import org.bitcoins.core.protocol.ln.util.LnUtil
|
||||
import org.bitcoins.core.util.BitcoinSUnitTest
|
||||
|
||||
class LnUtilTest extends BitcoinSUnitTest {
|
||||
override implicit val generatorDrivenConfig: PropertyCheckConfiguration = generatorDrivenConfigNewCode
|
||||
override implicit val generatorDrivenConfig: PropertyCheckConfiguration =
|
||||
generatorDrivenConfigNewCode
|
||||
|
||||
behavior of "LnUtil"
|
||||
|
||||
it must "encode / decode a number correctly to bech32" in {
|
||||
|
||||
forAll(NumberGenerator.uInt64) { case u64: UInt64 =>
|
||||
|
||||
forAll(NumberGenerator.uInt64) {
|
||||
case u64: UInt64 =>
|
||||
val encoded = LnUtil.encodeNumber(u64.toBigInt)
|
||||
val decoded = LnUtil.decodeNumber(encoded)
|
||||
|
||||
|
@ -21,16 +22,15 @@ class LnUtilTest extends BitcoinSUnitTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
it must "encode the data length correctly for empty payload" in {
|
||||
val empty = LnUtil.createDataLength(List.empty)
|
||||
|
||||
empty must be (List(UInt5.zero, UInt5.zero))
|
||||
empty must be(List(UInt5.zero, UInt5.zero))
|
||||
}
|
||||
|
||||
|
||||
it must "encode the property data length for an arbitrary payload" in {
|
||||
forAll(NumberGenerator.uInt5s) { case u5s =>
|
||||
forAll(NumberGenerator.uInt5s) {
|
||||
case u5s =>
|
||||
val dataLen = LnUtil.createDataLength(u5s.toList)
|
||||
|
||||
val decodedDataLen = LnUtil.decodeDataLength(dataLen)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.protocol.ln.currency
|
||||
|
||||
import org.bitcoins.core.gen.{CurrencyUnitGenerator, NumberGenerator}
|
||||
import org.bitcoins.core.gen.ln.LnCurrencyUnitGen
|
||||
import org.bitcoins.testkit.core.gen.{CurrencyUnitGenerator, NumberGenerator}
|
||||
import org.bitcoins.testkit.core.gen.ln.LnCurrencyUnitGen
|
||||
import org.bitcoins.core.util.BitcoinSUnitTest
|
||||
import org.scalatest.prop.PropertyChecks
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.{CryptoGenerators, ScriptGenerators}
|
||||
import org.bitcoins.testkit.core.gen.{CryptoGenerators, ScriptGenerators}
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.scalatest.{FlatSpec, MustMatchers}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.bitcoins.core.script.bitwise.OP_EQUALVERIFY
|
||||
import org.bitcoins.core.script.constant._
|
||||
import org.bitcoins.core.script.crypto.{OP_CHECKSIG, OP_HASH160}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
class ScriptSpec extends Properties("ScriptSpec") {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.{ScriptGenerators, WitnessGenerators}
|
||||
import org.bitcoins.testkit.core.gen.{ScriptGenerators, WitnessGenerators}
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.script
|
||||
|
||||
import org.bitcoins.core.gen.ScriptGenerators
|
||||
import org.bitcoins.testkit.core.gen.ScriptGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.transaction
|
||||
|
||||
import org.bitcoins.core.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.core.gen.TransactionGenerators
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.transaction
|
||||
|
||||
import org.bitcoins.core.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.core.gen.TransactionGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.protocol.transaction
|
||||
|
||||
import org.bitcoins.core.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.core.gen.TransactionGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.protocol.transaction
|
||||
|
||||
import org.bitcoins.core.crypto.{ECPrivateKey, EmptyDigitalSignature}
|
||||
import org.bitcoins.core.gen.WitnessGenerators
|
||||
import org.bitcoins.testkit.core.gen.WitnessGenerators
|
||||
import org.bitcoins.core.protocol.script._
|
||||
import org.scalacheck.Prop
|
||||
import org.scalatest.{FlatSpec, MustMatchers}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.script.constant
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.script.crypto
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.serializers
|
||||
|
||||
import org.bitcoins.core.currency.Satoshis
|
||||
import org.bitcoins.core.gen.CurrencyUnitGenerator
|
||||
import org.bitcoins.testkit.core.gen.CurrencyUnitGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.serializers
|
||||
|
||||
import org.bitcoins.core.gen.TransactionGenerators
|
||||
import org.bitcoins.testkit.core.gen.TransactionGenerators
|
||||
import org.bitcoins.core.protocol.transaction.TransactionOutput
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
import scodec.bits.ByteVector
|
||||
|
|
|
@ -4,7 +4,11 @@ import org.bitcoins.core.script.arithmetic.OP_1ADD
|
|||
import org.bitcoins.core.script.bitwise.{OP_EQUAL, OP_EQUALVERIFY}
|
||||
import org.bitcoins.core.script.constant._
|
||||
import org.bitcoins.core.script.control.{OP_ELSE, OP_ENDIF, OP_IF, OP_NOTIF}
|
||||
import org.bitcoins.core.script.crypto.{OP_CHECKMULTISIG, OP_CHECKSIG, OP_HASH160}
|
||||
import org.bitcoins.core.script.crypto.{
|
||||
OP_CHECKMULTISIG,
|
||||
OP_CHECKSIG,
|
||||
OP_HASH160
|
||||
}
|
||||
import org.bitcoins.core.script.locktime.OP_CHECKLOCKTIMEVERIFY
|
||||
import org.bitcoins.core.script.reserved.OP_NOP
|
||||
import org.bitcoins.core.script.splice.OP_SIZE
|
||||
|
@ -267,7 +271,8 @@ class ScriptParserTest extends FlatSpec with MustMatchers {
|
|||
|
||||
it must "parse a offered htlc" in {
|
||||
//https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#offered-htlc-outputs
|
||||
val witScriptHex = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868"
|
||||
val witScriptHex =
|
||||
"76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c820120876475527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae67a914b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d188ac6868"
|
||||
val asm = ScriptParser.fromHex(witScriptHex)
|
||||
|
||||
/**
|
||||
|
@ -287,41 +292,45 @@ class ScriptParserTest extends FlatSpec with MustMatchers {
|
|||
* OP_ENDIF
|
||||
* OP_ENDIF
|
||||
*/
|
||||
val expectedAsm = List(
|
||||
OP_DUP,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(
|
||||
ByteVector.fromValidHex("14011f7254d96b819c76986c277d115efce6f7b5")),
|
||||
OP_EQUAL,
|
||||
OP_IF,
|
||||
OP_CHECKSIG,
|
||||
OP_ELSE,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex(
|
||||
"0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b")),
|
||||
OP_SWAP,
|
||||
OP_SIZE,
|
||||
BytesToPushOntoStack(1),
|
||||
ScriptConstant.fromHex("20"),
|
||||
OP_EQUAL,
|
||||
OP_NOTIF,
|
||||
OP_DROP,
|
||||
OP_2,
|
||||
OP_SWAP,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex(
|
||||
"030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7")),
|
||||
OP_2,
|
||||
OP_CHECKMULTISIG,
|
||||
OP_ELSE,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(
|
||||
ByteVector.fromValidHex("b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d1")),
|
||||
OP_EQUALVERIFY,
|
||||
OP_CHECKSIG,
|
||||
OP_ENDIF,
|
||||
OP_ENDIF
|
||||
)
|
||||
|
||||
val expectedAsm = List(OP_DUP,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(ByteVector.fromValidHex("14011f7254d96b819c76986c277d115efce6f7b5")),
|
||||
OP_EQUAL,
|
||||
OP_IF,
|
||||
OP_CHECKSIG,
|
||||
OP_ELSE,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex("0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b")),
|
||||
OP_SWAP,
|
||||
OP_SIZE,
|
||||
BytesToPushOntoStack(1),
|
||||
ScriptConstant.fromHex("20"),
|
||||
OP_EQUAL,
|
||||
OP_NOTIF,
|
||||
OP_DROP,
|
||||
OP_2,
|
||||
OP_SWAP,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex("030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7")),
|
||||
OP_2,
|
||||
OP_CHECKMULTISIG,
|
||||
OP_ELSE,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(ByteVector.fromValidHex("b43e1b38138a41b37f7cd9a1d274bc63e3a9b5d1")),
|
||||
OP_EQUALVERIFY,
|
||||
OP_CHECKSIG,
|
||||
OP_ENDIF,
|
||||
OP_ENDIF)
|
||||
|
||||
asm must be (expectedAsm)
|
||||
|
||||
asm must be(expectedAsm)
|
||||
|
||||
}
|
||||
|
||||
|
@ -345,53 +354,56 @@ class ScriptParserTest extends FlatSpec with MustMatchers {
|
|||
* OP_ENDIF
|
||||
* OP_ENDIF
|
||||
*/
|
||||
val witScriptHex = "76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac6868"
|
||||
|
||||
val witScriptHex =
|
||||
"76a91414011f7254d96b819c76986c277d115efce6f7b58763ac67210394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b7c8201208763a914b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc688527c21030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e752ae677502f401b175ac6868"
|
||||
|
||||
val asm = ScriptParser.fromHex(witScriptHex)
|
||||
|
||||
val expectedAsm = {
|
||||
List(
|
||||
OP_DUP,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(ByteVector.fromValidHex("14011f7254d96b819c76986c277d115efce6f7b5")),
|
||||
OP_EQUAL,
|
||||
OP_IF,
|
||||
OP_CHECKSIG,
|
||||
OP_ELSE,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex("0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b")),
|
||||
OP_SWAP,
|
||||
OP_SIZE,
|
||||
BytesToPushOntoStack(1),
|
||||
ScriptConstant(ByteVector.fromValidHex("20")),
|
||||
OP_EQUAL,
|
||||
OP_IF,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(ByteVector.fromValidHex("b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc6")),
|
||||
OP_EQUALVERIFY,
|
||||
OP_2,
|
||||
OP_SWAP,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex("030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7")),
|
||||
OP_2,
|
||||
OP_CHECKMULTISIG,
|
||||
OP_ELSE,
|
||||
OP_DROP,
|
||||
BytesToPushOntoStack(2),
|
||||
ScriptConstant(ByteVector.fromValidHex("f401")),
|
||||
OP_CHECKLOCKTIMEVERIFY,
|
||||
OP_DROP,
|
||||
OP_CHECKSIG,
|
||||
OP_ENDIF,
|
||||
OP_ENDIF
|
||||
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(
|
||||
ByteVector.fromValidHex("14011f7254d96b819c76986c277d115efce6f7b5")),
|
||||
OP_EQUAL,
|
||||
OP_IF,
|
||||
OP_CHECKSIG,
|
||||
OP_ELSE,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex(
|
||||
"0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b")),
|
||||
OP_SWAP,
|
||||
OP_SIZE,
|
||||
BytesToPushOntoStack(1),
|
||||
ScriptConstant(ByteVector.fromValidHex("20")),
|
||||
OP_EQUAL,
|
||||
OP_IF,
|
||||
OP_HASH160,
|
||||
BytesToPushOntoStack(20),
|
||||
ScriptConstant(
|
||||
ByteVector.fromValidHex("b8bcb07f6344b42ab04250c86a6e8b75d3fdbbc6")),
|
||||
OP_EQUALVERIFY,
|
||||
OP_2,
|
||||
OP_SWAP,
|
||||
BytesToPushOntoStack(33),
|
||||
ScriptConstant(ByteVector.fromValidHex(
|
||||
"030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7")),
|
||||
OP_2,
|
||||
OP_CHECKMULTISIG,
|
||||
OP_ELSE,
|
||||
OP_DROP,
|
||||
BytesToPushOntoStack(2),
|
||||
ScriptConstant(ByteVector.fromValidHex("f401")),
|
||||
OP_CHECKLOCKTIMEVERIFY,
|
||||
OP_DROP,
|
||||
OP_CHECKSIG,
|
||||
OP_ENDIF,
|
||||
OP_ENDIF
|
||||
)
|
||||
}
|
||||
|
||||
asm must be (expectedAsm)
|
||||
asm must be(expectedAsm)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.util
|
||||
|
||||
import org.bitcoins.core.gen.StringGenerators
|
||||
import org.bitcoins.testkit.core.gen.StringGenerators
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.util
|
||||
|
||||
import org.bitcoins.core.gen.CryptoGenerators
|
||||
import org.bitcoins.testkit.core.gen.CryptoGenerators
|
||||
import org.scalatest.prop.{Configuration, PropertyChecks}
|
||||
import org.scalatest.{FlatSpec, MustMatchers}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.util
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.number.UInt8
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
|
|
|
@ -62,11 +62,12 @@ sealed abstract class ECDigitalSignature extends BitcoinSLogger {
|
|||
decodeSignature._2
|
||||
}
|
||||
|
||||
def sBytes:ByteVector = {
|
||||
def sBytes: ByteVector = {
|
||||
val bytes = s.bigInteger.toByteArray.takeRight(32)
|
||||
val padded = ByteVector(bytes).padLeft(32)
|
||||
padded
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ByteVector with only
|
||||
* the 32byte r value and 32 byte s value
|
||||
|
@ -151,8 +152,8 @@ object ECDigitalSignature extends Factory[ECDigitalSignature] {
|
|||
require(
|
||||
byteVector.length == 64,
|
||||
s"Incorrect size for reading a ECDigital signature from a bytevec, got ${byteVector.length}")
|
||||
val r = BigInt(1,byteVector.take(32).toArray)
|
||||
val s = BigInt(1,byteVector.takeRight(32).toArray)
|
||||
val r = BigInt(1, byteVector.take(32).toArray)
|
||||
val s = BigInt(1, byteVector.takeRight(32).toArray)
|
||||
fromRS(r, s)
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ sealed abstract class Sha256Digest extends HashDigest {
|
|||
object Sha256Digest extends Factory[Sha256Digest] {
|
||||
private case class Sha256DigestImpl(bytes: ByteVector) extends Sha256Digest {
|
||||
require(bytes.length == 32,
|
||||
// $COVERAGE-OFF$
|
||||
// $COVERAGE-OFF$
|
||||
"Sha256Digest must be 32 bytes in size, got: " + bytes.length)
|
||||
override def toString = s"Sha256DigestImpl($hex)"
|
||||
// $COVERAGE-ON$
|
||||
|
|
|
@ -229,16 +229,16 @@ object LnInvoice extends BitcoinSLogger {
|
|||
}
|
||||
|
||||
def apply(
|
||||
hrp: LnHumanReadablePart,
|
||||
timestamp: UInt64,
|
||||
lnTags: LnTaggedFields,
|
||||
privateKey: ECPrivateKey): LnInvoice = {
|
||||
hrp: LnHumanReadablePart,
|
||||
timestamp: UInt64,
|
||||
lnTags: LnTaggedFields,
|
||||
privateKey: ECPrivateKey): LnInvoice = {
|
||||
|
||||
val signature = buildLnInvoiceSignature(hrp,timestamp,lnTags,privateKey)
|
||||
val signature = buildLnInvoiceSignature(hrp, timestamp, lnTags, privateKey)
|
||||
LnInvoiceImpl(hrp = hrp,
|
||||
timestamp = timestamp,
|
||||
lnTags = lnTags,
|
||||
signature = signature)
|
||||
timestamp = timestamp,
|
||||
lnTags = lnTags,
|
||||
signature = signature)
|
||||
}
|
||||
|
||||
def buildSignatureData(
|
||||
|
@ -251,7 +251,6 @@ object LnInvoice extends BitcoinSLogger {
|
|||
val payload = UInt8.toBytes(payloadU8)
|
||||
val allBytes = hrp.bytes ++ payload
|
||||
|
||||
|
||||
//for an explanation of why this is needed see
|
||||
//https://github.com/bitcoin-s/bitcoin-s-core/issues/277
|
||||
//https://github.com/bitcoin-s/bitcoin-s-core/pull/285
|
||||
|
|
|
@ -18,7 +18,9 @@ sealed abstract class LnInvoiceSignature extends NetworkElement {
|
|||
require(recoverId.toInt >= 0 && recoverId.toInt <= 3,
|
||||
s"signature recovery byte must be 0,1,2,3, got ${recoverId.toInt}")
|
||||
|
||||
require(bytes.length == 65, s"LnInvoiceSignatures MUST be 65 bytes in length, got ${bytes.length}")
|
||||
require(
|
||||
bytes.length == 65,
|
||||
s"LnInvoiceSignatures MUST be 65 bytes in length, got ${bytes.length}")
|
||||
def signature: ECDigitalSignature
|
||||
|
||||
def recoverId: UInt8
|
||||
|
@ -35,12 +37,12 @@ sealed abstract class LnInvoiceSignature extends NetworkElement {
|
|||
|
||||
object LnInvoiceSignature extends Factory[LnInvoiceSignature] {
|
||||
private case class LnInvoiceSignatureImpl(
|
||||
recoverId: UInt8,
|
||||
recoverId: UInt8,
|
||||
signature: ECDigitalSignature)
|
||||
extends LnInvoiceSignature
|
||||
|
||||
def apply(
|
||||
recoverId: UInt8,
|
||||
recoverId: UInt8,
|
||||
signature: ECDigitalSignature): LnInvoiceSignature = {
|
||||
LnInvoiceSignatureImpl(recoverId, signature)
|
||||
}
|
||||
|
@ -54,8 +56,11 @@ object LnInvoiceSignature extends Factory[LnInvoiceSignature] {
|
|||
LnInvoiceSignature.apply(recoverId = recoverId, signature = signature)
|
||||
}
|
||||
|
||||
def fromRS(r:BigInteger, s: BigInteger, recovId: UInt8): LnInvoiceSignature = {
|
||||
val sig = ECDigitalSignature.fromRS(r,s)
|
||||
def fromRS(
|
||||
r: BigInteger,
|
||||
s: BigInteger,
|
||||
recovId: UInt8): LnInvoiceSignature = {
|
||||
val sig = ECDigitalSignature.fromRS(r, s)
|
||||
LnInvoiceSignature(recovId, sig)
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ case class FeeProportionalMillionths(u32: UInt32) extends NetworkElement {
|
|||
}
|
||||
|
||||
object FeeProportionalMillionths {
|
||||
|
||||
def fromBigInt(bigInt: BigInt): FeeProportionalMillionths =
|
||||
FeeProportionalMillionths(UInt32(bigInt))
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ abstract class LnUtil extends BitcoinSLogger {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/** Decodes a number from Bech32 to a long */
|
||||
@tailrec
|
||||
final def decodeNumber(list: List[UInt5], accum: BigInt = 0): BigInt = {
|
||||
|
|
|
@ -128,7 +128,7 @@ trait CryptoUtil extends BitcoinSLogger {
|
|||
|
||||
val pub1 = ECPublicKey.fromPoint(Q1)
|
||||
val pub2 = ECPublicKey.fromPoint(Q2)
|
||||
(pub1,pub2)
|
||||
(pub1, pub2)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,10 @@ import org.bitcoins.core.util.BitcoinSLogger
|
|||
import org.bitcoins.eclair.rpc.client.EclairRpcClient
|
||||
import org.bitcoins.eclair.rpc.config.{EclairAuthCredentials, EclairInstance}
|
||||
import org.bitcoins.eclair.rpc.json._
|
||||
import org.bitcoins.rpc.BitcoindRpcTestUtil
|
||||
import org.bitcoins.rpc.client.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.util.AsyncUtil
|
||||
import org.bitcoins.testkit.eclair.rpc.{EclairNodes4, EclairRpcTestUtil}
|
||||
import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil
|
||||
import org.scalatest.{Assertion, AsyncFlatSpec, BeforeAndAfterAll}
|
||||
import org.slf4j.Logger
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ package org.bitcoins.eclair.rpc
|
|||
import akka.actor.ActorSystem
|
||||
import akka.testkit.TestKit
|
||||
import org.bitcoins.eclair.rpc.client.EclairRpcClient
|
||||
import org.bitcoins.rpc.BitcoindRpcTestUtil
|
||||
import org.bitcoins.testkit.eclair.rpc.EclairRpcTestUtil
|
||||
import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil
|
||||
import org.scalatest.{AsyncFlatSpec, BeforeAndAfterAll}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ trait EclairApi {
|
|||
feerateSatPerByte: Option[SatoshisPerByte],
|
||||
channelFlags: Option[Byte]): Future[FundedChannelId]
|
||||
|
||||
|
||||
/** The network that this [[org.bitcoins.eclair.rpc.api.EclairApi EclairApi]] is
|
||||
* running on. This is not available directly from the eclair api, but is a very
|
||||
* useful helper method
|
||||
|
|
|
@ -425,8 +425,7 @@ class EclairRpcClient(val instance: EclairInstance)(
|
|||
if (amountMsat.isEmpty) {
|
||||
List(JsString(invoice.toString))
|
||||
} else {
|
||||
List(JsString(invoice.toString),
|
||||
JsNumber(amountMsat.get.toMSat.toLong))
|
||||
List(JsString(invoice.toString), JsNumber(amountMsat.get.toMSat.toLong))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,7 +483,10 @@ class EclairRpcClient(val instance: EclairInstance)(
|
|||
case class RpcError(code: Int, message: String)
|
||||
implicit val rpcErrorReads: Reads[RpcError] = Json.reads[RpcError]
|
||||
|
||||
private def parseResult[T](result: JsResult[T], json: JsValue, commandName: String): T = {
|
||||
private def parseResult[T](
|
||||
result: JsResult[T],
|
||||
json: JsValue,
|
||||
commandName: String): T = {
|
||||
result match {
|
||||
case res: JsSuccess[T] =>
|
||||
res.value
|
||||
|
@ -494,7 +496,8 @@ class EclairRpcClient(val instance: EclairInstance)(
|
|||
val datadirMsg = instance.authCredentials.datadir
|
||||
.map(d => s"datadir=${d}")
|
||||
.getOrElse("")
|
||||
val errMsg = s"Error for command=${commandName} ${datadirMsg}, ${err.value.code}=${err.value.message}"
|
||||
val errMsg =
|
||||
s"Error for command=${commandName} ${datadirMsg}, ${err.value.code}=${err.value.message}"
|
||||
logger.error(errMsg)
|
||||
throw new RuntimeException(errMsg)
|
||||
case _: JsError =>
|
||||
|
@ -573,7 +576,8 @@ class EclairRpcClient(val instance: EclairInstance)(
|
|||
|
||||
val _ = {
|
||||
|
||||
require(instance.authCredentials.datadir.isDefined, s"A datadir needs to be provided to start eclair")
|
||||
require(instance.authCredentials.datadir.isDefined,
|
||||
s"A datadir needs to be provided to start eclair")
|
||||
|
||||
if (process.isEmpty) {
|
||||
val p = Process(
|
||||
|
@ -590,11 +594,9 @@ class EclairRpcClient(val instance: EclairInstance)(
|
|||
}
|
||||
}
|
||||
|
||||
val started = AsyncUtil.retryUntilSatisfiedF(
|
||||
() => isStarted,
|
||||
duration = 1.seconds,
|
||||
maxTries = 60)
|
||||
|
||||
val started = AsyncUtil.retryUntilSatisfiedF(() => isStarted,
|
||||
duration = 1.seconds,
|
||||
maxTries = 60)
|
||||
|
||||
started
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package org.bitcoins.util
|
||||
package org.bitcoins.testkit.async
|
||||
import akka.actor.ActorSystem
|
||||
import org.scalatest.exceptions.{StackDepthException, TestFailedException}
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
abstract class AsyncUtil extends org.bitcoins.rpc.util.AsyncUtil {
|
||||
abstract class TestAsyncUtil extends org.bitcoins.rpc.util.AsyncUtil {
|
||||
override protected def retryUntilSatisfiedWithCounter(
|
||||
conditionF: () => Future[Boolean],
|
||||
duration: FiniteDuration,
|
||||
|
@ -20,24 +20,26 @@ abstract class AsyncUtil extends org.bitcoins.rpc.util.AsyncUtil {
|
|||
maxTries,
|
||||
stackTrace)
|
||||
|
||||
AsyncUtil.transformRetryToTestFailure(retryF)(system.dispatcher)
|
||||
TestAsyncUtil.transformRetryToTestFailure(retryF)(system.dispatcher)
|
||||
}
|
||||
}
|
||||
|
||||
object AsyncUtil extends AsyncUtil {
|
||||
object TestAsyncUtil extends TestAsyncUtil {
|
||||
|
||||
/**
|
||||
* As opposed to the AsyncUtil in the rpc project, in the testkit, we can assume that
|
||||
* AsyncUtil methods are being called from tests and as such, we want to trim the stack
|
||||
* TestAsyncUtil methods are being called from tests and as such, we want to trim the stack
|
||||
* trace to exclude stack elements that occur before the beginning of a test.
|
||||
* Additionally, we want to transform RpcRetryExceptions to TestFailedExceptions which
|
||||
* conveniently mention the line that called the AsyncUtil method.
|
||||
* conveniently mention the line that called the TestAsyncUtil method.
|
||||
*/
|
||||
def transformRetryToTestFailure[T](fut: Future[T])(implicit ec: ExecutionContext): Future[T] = {
|
||||
def transformRetryToTestFailure[T](fut: Future[T])(
|
||||
implicit ec: ExecutionContext): Future[T] = {
|
||||
def transformRetry(err: Throwable): Throwable = {
|
||||
if (err.isInstanceOf[RpcRetryException]) {
|
||||
val retryErr = err.asInstanceOf[RpcRetryException]
|
||||
val relevantStackTrace = retryErr.caller.tail
|
||||
.dropWhile(_.getFileName == "AsyncUtil.scala")
|
||||
.dropWhile(elem => retryErr.internalFiles.contains(elem.getFileName))
|
||||
.takeWhile(!_.getFileName.contains("TestSuite"))
|
||||
val stackElement = relevantStackTrace.head
|
||||
val file = stackElement.getFileName
|
||||
|
@ -54,6 +56,8 @@ object AsyncUtil extends AsyncUtil {
|
|||
}
|
||||
}
|
||||
|
||||
fut.transform({ elem: T => elem }, transformRetry)
|
||||
fut.transform({ elem: T =>
|
||||
elem
|
||||
}, transformRetry)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.protocol._
|
||||
import org.scalacheck.Gen
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.consensus.Merkle
|
||||
import org.bitcoins.core.crypto.DoubleSha256Digest
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.bloom._
|
||||
import org.scalacheck.Gen
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.config._
|
||||
import org.bitcoins.core.protocol.ln.LnParams
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.crypto.Sign
|
||||
import org.bitcoins.core.number.UInt32
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.script.crypto.HashType
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.currency.{
|
||||
Bitcoins,
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.bloom.BloomFilter
|
||||
import org.bitcoins.core.crypto.DoubleSha256Digest
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.number._
|
||||
import org.bitcoins.core.protocol.CompactSizeUInt
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.consensus.Consensus
|
||||
import org.bitcoins.core.crypto.{TransactionSignatureCreator, _}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.scalacheck.Gen
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency.{CurrencyUnit, CurrencyUnits, Satoshis}
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.core.gen
|
||||
package org.bitcoins.testkit.core.gen
|
||||
|
||||
import org.bitcoins.core.crypto._
|
||||
import org.bitcoins.core.currency.CurrencyUnit
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.gen.ln
|
||||
package org.bitcoins.testkit.core.gen.ln
|
||||
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.testkit.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.protocol.ln._
|
||||
import org.bitcoins.core.protocol.ln.currency._
|
||||
import org.scalacheck.Gen
|
||||
|
@ -39,7 +39,7 @@ trait LnCurrencyUnitGen {
|
|||
}
|
||||
|
||||
def realisticLnInvoice: Gen[LnCurrencyUnit] = {
|
||||
val gen = Gen.choose(0,LnPolicy.maxAmountMSat.toLong)
|
||||
val gen = Gen.choose(0, LnPolicy.maxAmountMSat.toLong)
|
||||
val msat = gen.map(MilliSatoshis(_))
|
||||
msat.map(LnCurrencyUnits.fromMSat(_))
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.bitcoins.core.gen.ln
|
||||
package org.bitcoins.testkit.core.gen.ln
|
||||
|
||||
import org.bitcoins.core.crypto.ECPrivateKey
|
||||
import org.bitcoins.core.gen._
|
||||
import org.bitcoins.testkit.core.gen._
|
||||
import org.bitcoins.core.number.{UInt64, UInt8}
|
||||
import org.bitcoins.core.protocol.ln.LnTag.NodeIdTag
|
||||
import org.bitcoins.core.protocol.ln._
|
||||
|
@ -113,7 +113,6 @@ sealed abstract class LnInvoiceGen {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
def optionalTags(nodeIdOpt: Option[NodeId]): Gen[LnTaggedFields] = {
|
||||
for {
|
||||
paymentHash <- paymentHashTag
|
||||
|
@ -158,17 +157,13 @@ sealed abstract class LnInvoiceGen {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
/** Generated a tagged fields with an explicit
|
||||
* [[org.bitcoins.core.protocol.ln.LnTag.NodeIdTag LnTag.NodeIdTag]]
|
||||
* */
|
||||
def taggedFields(nodeIdOpt: Option[NodeId]): Gen[LnTaggedFields] = {
|
||||
Gen.oneOf(allTags(nodeIdOpt),
|
||||
mandatoryTags,
|
||||
optionalTags(nodeIdOpt))
|
||||
Gen.oneOf(allTags(nodeIdOpt), mandatoryTags, optionalTags(nodeIdOpt))
|
||||
}
|
||||
|
||||
|
||||
def signatureVersion: Gen[UInt8] = {
|
||||
Gen.choose(0, 3).map(UInt8(_))
|
||||
}
|
||||
|
@ -199,14 +194,12 @@ sealed abstract class LnInvoiceGen {
|
|||
)
|
||||
|
||||
LnInvoice(hrp = hrp,
|
||||
timestamp = timestamp,
|
||||
lnTags = tags,
|
||||
signature = signature)
|
||||
timestamp = timestamp,
|
||||
lnTags = tags,
|
||||
signature = signature)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
def lnInvoice(tags: LnTaggedFields): Gen[LnInvoice] = {
|
||||
for {
|
||||
privateKey <- CryptoGenerators.privateKey
|
||||
|
@ -222,9 +215,9 @@ sealed abstract class LnInvoiceGen {
|
|||
)
|
||||
|
||||
LnInvoice(hrp = hrp,
|
||||
timestamp = timestamp,
|
||||
lnTags = tags,
|
||||
signature = signature)
|
||||
timestamp = timestamp,
|
||||
lnTags = tags,
|
||||
signature = signature)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.bitcoins.core.gen.ln
|
||||
package org.bitcoins.testkit.core.gen.ln
|
||||
|
||||
import org.bitcoins.core.gen.{CryptoGenerators, NumberGenerator}
|
||||
import org.bitcoins.testkit.core.gen.{CryptoGenerators, NumberGenerator}
|
||||
import org.bitcoins.core.protocol.ln.ShortChannelId
|
||||
import org.bitcoins.core.protocol.ln.currency.MilliSatoshis
|
||||
import org.bitcoins.core.protocol.ln.fee.{
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.eclair.rpc
|
||||
package org.bitcoins.testkit.eclair.rpc
|
||||
|
||||
import java.io.{File, PrintWriter}
|
||||
import java.net.URI
|
||||
|
@ -18,11 +18,10 @@ import org.bitcoins.core.util.BitcoinSLogger
|
|||
import org.bitcoins.eclair.rpc.client.EclairRpcClient
|
||||
import org.bitcoins.eclair.rpc.config.EclairInstance
|
||||
import org.bitcoins.eclair.rpc.json.PaymentResult
|
||||
import org.bitcoins.rpc.BitcoindRpcTestUtil
|
||||
import org.bitcoins.rpc.client.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.config.{BitcoindInstance, ZmqConfig}
|
||||
import org.bitcoins.rpc.RpcUtil
|
||||
import org.bitcoins.util.AsyncUtil
|
||||
import org.bitcoins.testkit.async.TestAsyncUtil
|
||||
import org.bitcoins.testkit.rpc.{BitcoindRpcTestUtil, TestRpcUtil}
|
||||
|
||||
import scala.concurrent.duration.DurationInt
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
@ -223,8 +222,8 @@ trait EclairRpcTestUtil extends BitcoinSLogger {
|
|||
}(system.dispatcher)
|
||||
}
|
||||
|
||||
AsyncUtil.retryUntilSatisfiedF(conditionF = () => isState(),
|
||||
duration = 1.seconds)
|
||||
TestAsyncUtil.retryUntilSatisfiedF(conditionF = () => isState(),
|
||||
duration = 1.seconds)
|
||||
}
|
||||
|
||||
private def createNodeLink(
|
||||
|
@ -415,9 +414,9 @@ trait EclairRpcTestUtil extends BitcoinSLogger {
|
|||
}
|
||||
|
||||
logger.debug(s"Awaiting connection between clients")
|
||||
val connected = RpcUtil.retryUntilSatisfiedF(conditionF =
|
||||
() => isConnected(),
|
||||
duration = 1.second)
|
||||
val connected = TestRpcUtil.retryUntilSatisfiedF(conditionF =
|
||||
() => isConnected(),
|
||||
duration = 1.second)
|
||||
|
||||
connected.map(_ => logger.debug(s"Successfully connected two clients"))
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.bitcoins.rpc
|
||||
package org.bitcoins.testkit.rpc
|
||||
|
||||
import java.io.{File, PrintWriter}
|
||||
import java.net.URI
|
||||
|
@ -10,8 +10,12 @@ import org.bitcoins.core.config.RegTest
|
|||
import org.bitcoins.core.crypto.DoubleSha256Digest
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.bitcoins.rpc.client.BitcoindRpcClient
|
||||
import org.bitcoins.rpc.config.{BitcoindAuthCredentials, BitcoindInstance, ZmqConfig}
|
||||
import org.bitcoins.util.AsyncUtil
|
||||
import org.bitcoins.rpc.config.{
|
||||
BitcoindAuthCredentials,
|
||||
BitcoindInstance,
|
||||
ZmqConfig
|
||||
}
|
||||
import org.bitcoins.testkit.async.TestAsyncUtil
|
||||
|
||||
import scala.collection.immutable.Map
|
||||
import scala.concurrent.duration.{DurationInt, FiniteDuration}
|
||||
|
@ -20,6 +24,7 @@ import scala.util.{Failure, Success, Try}
|
|||
|
||||
trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
def randomDirName: String =
|
||||
0.until(5).map(_ => scala.util.Random.alphanumeric.head).mkString
|
||||
|
||||
|
@ -67,7 +72,8 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
.map(entry => {
|
||||
val key = entry.getKey
|
||||
val value = entry.getValue.unwrapped
|
||||
s"$key=$value"})
|
||||
s"$key=$value"
|
||||
})
|
||||
.mkString("\n")
|
||||
|
||||
val datadir = new java.io.File("/tmp/" + randomDirName)
|
||||
|
@ -143,9 +149,9 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
|
||||
RpcUtil.awaitConditionF(conditionF = () => isConnected(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
TestRpcUtil.awaitConditionF(conditionF = () => isConnected(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
}
|
||||
|
||||
def awaitSynced(
|
||||
|
@ -163,9 +169,9 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
|
||||
RpcUtil.awaitConditionF(conditionF = () => isSynced(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
TestRpcUtil.awaitConditionF(conditionF = () => isSynced(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
}
|
||||
|
||||
def awaitSameBlockHeight(
|
||||
|
@ -183,9 +189,9 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
|
||||
RpcUtil.awaitConditionF(conditionF = () => isSameBlockHeight(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
TestRpcUtil.awaitConditionF(conditionF = () => isSameBlockHeight(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
}
|
||||
|
||||
def awaitDisconnected(
|
||||
|
@ -204,9 +210,9 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
|
||||
}
|
||||
|
||||
RpcUtil.awaitConditionF(conditionF = () => isDisconnected(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
TestRpcUtil.awaitConditionF(conditionF = () => isDisconnected(),
|
||||
duration = duration,
|
||||
maxTries = maxTries)
|
||||
}
|
||||
|
||||
/** Returns a pair of RpcClients that are connected with 100 blocks in the chain */
|
||||
|
@ -226,13 +232,13 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
client1.start()
|
||||
client2.start()
|
||||
|
||||
val try1 = Try(RpcUtil.awaitServer(client1))
|
||||
val try1 = Try(TestRpcUtil.awaitServer(client1))
|
||||
if (try1.isFailure) {
|
||||
deleteNodePair(client1, client2)
|
||||
throw try1.failed.get
|
||||
}
|
||||
|
||||
val try2 = Try(RpcUtil.awaitServer(client2))
|
||||
val try2 = Try(TestRpcUtil.awaitServer(client2))
|
||||
if (try2.isFailure) {
|
||||
deleteNodePair(client1, client2)
|
||||
throw try2.failed.get
|
||||
|
@ -303,7 +309,7 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
|||
}
|
||||
|
||||
val blocksGeneratedF = generatedF.flatMap { _ =>
|
||||
AsyncUtil.retryUntilSatisfiedF(
|
||||
TestAsyncUtil.retryUntilSatisfiedF(
|
||||
() => isBlocksGenerated,
|
||||
duration = 1.seconds
|
||||
)
|
Loading…
Add table
Reference in a new issue