mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 10:46:42 +01:00
Deprecate generate (#728)
This commit is contained in:
parent
8a58d7dde8
commit
e0a5646258
19 changed files with 127 additions and 100 deletions
|
@ -133,7 +133,7 @@ class BitcoindInstanceTest extends BitcoindRpcTest {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- client.start()
|
_ <- client.start()
|
||||||
_ <- client.generate(101)
|
_ <- client.getNewAddress.flatMap(client.generateToAddress(101, _))
|
||||||
balance <- client.getBalance
|
balance <- client.getBalance
|
||||||
_ <- BitcoindRpcTestUtil.stopServers(Vector(client))
|
_ <- BitcoindRpcTestUtil.stopServers(Vector(client))
|
||||||
_ <- client.getBalance
|
_ <- client.getBalance
|
||||||
|
|
|
@ -26,7 +26,8 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- pruneClient.start()
|
_ <- pruneClient.start()
|
||||||
_ <- pruneClient.generate(1000)
|
_ <- pruneClient.getNewAddress.flatMap(
|
||||||
|
pruneClient.generateToAddress(1000, _))
|
||||||
} yield pruneClient
|
} yield pruneClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,14 +91,14 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
address <- otherClient.getNewAddress(addressType = AddressType.P2SHSegwit)
|
address <- otherClient.getNewAddress(addressType = AddressType.P2SHSegwit)
|
||||||
txid <- BitcoindRpcTestUtil
|
txid <- BitcoindRpcTestUtil
|
||||||
.fundMemPoolTransaction(client, address, Bitcoins(1))
|
.fundMemPoolTransaction(client, address, Bitcoins(1))
|
||||||
blocks <- client.generate(1)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(1, _))
|
||||||
mostRecentBlock <- client.getBlock(blocks.head)
|
mostRecentBlock <- client.getBlock(blocks.head)
|
||||||
_ <- client.invalidateBlock(blocks.head)
|
_ <- client.invalidateBlock(blocks.head)
|
||||||
mempool <- client.getRawMemPool
|
mempool <- client.getRawMemPool
|
||||||
count1 <- client.getBlockCount
|
count1 <- client.getBlockCount
|
||||||
count2 <- otherClient.getBlockCount
|
count2 <- otherClient.getBlockCount
|
||||||
|
|
||||||
_ <- client.generate(2) // Ensure client and otherClient have the same blockchain
|
_ <- client.getNewAddress.flatMap(client.generateToAddress(2, _)) // Ensure client and otherClient have the same blockchain
|
||||||
} yield {
|
} yield {
|
||||||
assert(mostRecentBlock.tx.contains(txid))
|
assert(mostRecentBlock.tx.contains(txid))
|
||||||
assert(mempool.contains(txid))
|
assert(mempool.contains(txid))
|
||||||
|
@ -108,7 +109,7 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to get block hash by height" in {
|
it should "be able to get block hash by height" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(2)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(2, _))
|
||||||
count <- client.getBlockCount
|
count <- client.getBlockCount
|
||||||
hash <- client.getBlockHash(count)
|
hash <- client.getBlockHash(count)
|
||||||
prevhash <- client.getBlockHash(count - 1)
|
prevhash <- client.getBlockHash(count - 1)
|
||||||
|
@ -125,8 +126,10 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
_ <- freshClient.disconnectNode(otherFreshClient.getDaemon.uri)
|
_ <- freshClient.disconnectNode(otherFreshClient.getDaemon.uri)
|
||||||
_ <- BitcoindRpcTestUtil.awaitDisconnected(freshClient, otherFreshClient)
|
_ <- BitcoindRpcTestUtil.awaitDisconnected(freshClient, otherFreshClient)
|
||||||
|
|
||||||
blocks1 <- freshClient.generate(1)
|
blocks1 <- freshClient.getNewAddress.flatMap(
|
||||||
blocks2 <- otherFreshClient.generate(1)
|
freshClient.generateToAddress(1, _))
|
||||||
|
blocks2 <- otherFreshClient.getNewAddress.flatMap(
|
||||||
|
otherFreshClient.generateToAddress(1, _))
|
||||||
|
|
||||||
bestHash1 <- freshClient.getBestBlockHash
|
bestHash1 <- freshClient.getBestBlockHash
|
||||||
_ = assert(bestHash1 == blocks1.head)
|
_ = assert(bestHash1 == blocks1.head)
|
||||||
|
@ -182,7 +185,7 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to get a raw block" in {
|
it should "be able to get a raw block" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(1)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(1, _))
|
||||||
block <- client.getBlockRaw(blocks.head)
|
block <- client.getBlockRaw(blocks.head)
|
||||||
blockHeader <- client.getBlockHeaderRaw(blocks.head)
|
blockHeader <- client.getBlockHeaderRaw(blocks.head)
|
||||||
} yield assert(block.blockHeader == blockHeader)
|
} yield assert(block.blockHeader == blockHeader)
|
||||||
|
@ -191,7 +194,7 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to get a block" in {
|
it should "be able to get a block" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(1)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(1, _))
|
||||||
block <- client.getBlock(blocks.head)
|
block <- client.getBlock(blocks.head)
|
||||||
} yield {
|
} yield {
|
||||||
assert(block.hash == blocks(0))
|
assert(block.hash == blocks(0))
|
||||||
|
@ -222,7 +225,7 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to get a block with verbose transactions" in {
|
it should "be able to get a block with verbose transactions" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(2)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(2, _))
|
||||||
block <- client.getBlockWithTransactions(blocks(1))
|
block <- client.getBlockWithTransactions(blocks(1))
|
||||||
} yield {
|
} yield {
|
||||||
assert(block.hash == blocks(1))
|
assert(block.hash == blocks(1))
|
||||||
|
@ -249,7 +252,7 @@ class BlockchainRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to list all blocks since a given block" in {
|
it should "be able to list all blocks since a given block" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(3)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(3, _))
|
||||||
list <- client.listSinceBlock(blocks(0))
|
list <- client.listSinceBlock(blocks(0))
|
||||||
} yield {
|
} yield {
|
||||||
assert(list.transactions.length >= 2)
|
assert(list.transactions.length >= 2)
|
||||||
|
|
|
@ -91,7 +91,7 @@ class MempoolRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to get mem pool info" in {
|
it should "be able to get mem pool info" in {
|
||||||
for {
|
for {
|
||||||
(client, otherClient) <- clientsF
|
(client, otherClient) <- clientsF
|
||||||
_ <- client.generate(1)
|
_ <- client.getNewAddress.flatMap(client.generateToAddress(1, _))
|
||||||
info <- client.getMemPoolInfo
|
info <- client.getMemPoolInfo
|
||||||
_ <- BitcoindRpcTestUtil
|
_ <- BitcoindRpcTestUtil
|
||||||
.sendCoinbaseTransaction(client, otherClient)
|
.sendCoinbaseTransaction(client, otherClient)
|
||||||
|
@ -122,7 +122,7 @@ class MempoolRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to find mem pool ancestors and descendants" in {
|
it should "be able to find mem pool ancestors and descendants" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
_ <- client.generate(1)
|
_ <- client.getNewAddress.flatMap(client.generateToAddress(1, _))
|
||||||
address1 <- client.getNewAddress
|
address1 <- client.getNewAddress
|
||||||
txid1 <- BitcoindRpcTestUtil.fundMemPoolTransaction(client,
|
txid1 <- BitcoindRpcTestUtil.fundMemPoolTransaction(client,
|
||||||
address1,
|
address1,
|
||||||
|
|
|
@ -31,7 +31,7 @@ class MiningRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to generate blocks" in {
|
it should "be able to generate blocks" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(3)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(3, _))
|
||||||
} yield assert(blocks.length == 3)
|
} yield assert(blocks.length == 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class MiningRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to generate blocks and then get their serialized headers" in {
|
it should "be able to generate blocks and then get their serialized headers" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(2)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(2, _))
|
||||||
header <- client.getBlockHeaderRaw(blocks(1))
|
header <- client.getBlockHeaderRaw(blocks(1))
|
||||||
} yield assert(header.previousBlockHashBE == blocks(0))
|
} yield assert(header.previousBlockHashBE == blocks(0))
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class MiningRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to generate blocks and then get their headers" in {
|
it should "be able to generate blocks and then get their headers" in {
|
||||||
for {
|
for {
|
||||||
(client, _) <- clientsF
|
(client, _) <- clientsF
|
||||||
blocks <- client.generate(2)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(2, _))
|
||||||
firstHeader <- client.getBlockHeader(blocks(0))
|
firstHeader <- client.getBlockHeader(blocks(0))
|
||||||
secondHeader <- client.getBlockHeader(blocks(1))
|
secondHeader <- client.getBlockHeader(blocks(1))
|
||||||
} yield {
|
} yield {
|
||||||
|
|
|
@ -17,13 +17,15 @@ class NodeRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to abort a rescan of the blockchain" in {
|
it should "be able to abort a rescan of the blockchain" in {
|
||||||
clientF.flatMap { client =>
|
clientF.flatMap { client =>
|
||||||
// generate some extra blocks so rescan isn't too quick
|
// generate some extra blocks so rescan isn't too quick
|
||||||
client.generate(3000).flatMap { _ =>
|
client.getNewAddress
|
||||||
val rescanFailedF =
|
.flatMap(client.generateToAddress(3000, _))
|
||||||
recoverToSucceededIf[MiscError](client.rescanBlockChain())
|
.flatMap { _ =>
|
||||||
client.abortRescan().flatMap { _ =>
|
val rescanFailedF =
|
||||||
rescanFailedF
|
recoverToSucceededIf[MiscError](client.rescanBlockChain())
|
||||||
|
client.abortRescan().flatMap { _ =>
|
||||||
|
rescanFailedF
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ class P2PRpcTest extends BitcoindRpcTest {
|
||||||
|
|
||||||
(client1, client2) <- BitcoindRpcTestUtil.createUnconnectedNodePair(
|
(client1, client2) <- BitcoindRpcTestUtil.createUnconnectedNodePair(
|
||||||
clientAccum = clientAccum)
|
clientAccum = clientAccum)
|
||||||
hash <- client2.generate(1)
|
hash <- client2.getNewAddress.flatMap(client2.generateToAddress(1, _))
|
||||||
block <- client2.getBlockRaw(hash.head)
|
block <- client2.getBlockRaw(hash.head)
|
||||||
preCount1 <- client1.getBlockCount
|
preCount1 <- client1.getBlockCount
|
||||||
preCount2 <- client2.getBlockCount
|
preCount2 <- client2.getBlockCount
|
||||||
|
|
|
@ -88,7 +88,7 @@ class RawTransactionRpcTest extends BitcoindRpcTest {
|
||||||
it should "be able to create a raw transaction" in {
|
it should "be able to create a raw transaction" in {
|
||||||
for {
|
for {
|
||||||
(client, otherClient) <- clientsF
|
(client, otherClient) <- clientsF
|
||||||
blocks <- client.generate(2)
|
blocks <- client.getNewAddress.flatMap(client.generateToAddress(2, _))
|
||||||
firstBlock <- client.getBlock(blocks(0))
|
firstBlock <- client.getBlock(blocks(0))
|
||||||
transaction0 <- client.getTransaction(firstBlock.tx(0))
|
transaction0 <- client.getTransaction(firstBlock.tx(0))
|
||||||
secondBlock <- client.getBlock(blocks(1))
|
secondBlock <- client.getBlock(blocks(1))
|
||||||
|
@ -123,7 +123,7 @@ class RawTransactionRpcTest extends BitcoindRpcTest {
|
||||||
otherClient)
|
otherClient)
|
||||||
signedTransaction <- BitcoindRpcTestUtil.signRawTransaction(client, rawTx)
|
signedTransaction <- BitcoindRpcTestUtil.signRawTransaction(client, rawTx)
|
||||||
|
|
||||||
_ <- client.generate(100) // Can't spend coinbase until depth 100
|
_ <- client.getNewAddress.flatMap(client.generateToAddress(100, _)) // Can't spend coinbase until depth 100
|
||||||
|
|
||||||
_ <- client.sendRawTransaction(signedTransaction.hex,
|
_ <- client.sendRawTransaction(signedTransaction.hex,
|
||||||
allowHighFees = true)
|
allowHighFees = true)
|
||||||
|
|
|
@ -40,7 +40,8 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_ <- walletClient.start()
|
_ <- walletClient.start()
|
||||||
_ <- walletClient.generate(200)
|
_ <- walletClient.getNewAddress.flatMap(
|
||||||
|
walletClient.generateToAddress(200, _))
|
||||||
_ <- walletClient.encryptWallet(password)
|
_ <- walletClient.encryptWallet(password)
|
||||||
_ <- walletClient.stop()
|
_ <- walletClient.stop()
|
||||||
_ <- RpcUtil.awaitServerShutdown(walletClient)
|
_ <- RpcUtil.awaitServerShutdown(walletClient)
|
||||||
|
@ -220,7 +221,7 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||||
.fundBlockChainTransaction(client, address, Bitcoins(1.5))
|
.fundBlockChainTransaction(client, address, Bitcoins(1.5))
|
||||||
val txid = await(txidF)
|
val txid = await(txidF)
|
||||||
|
|
||||||
await(client.generate(1))
|
await(client.getNewAddress.flatMap(client.generateToAddress(1, _)))
|
||||||
|
|
||||||
val tx = await(client.getTransaction(txid))
|
val tx = await(client.getTransaction(txid))
|
||||||
|
|
||||||
|
@ -344,7 +345,7 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||||
for {
|
for {
|
||||||
(client, _, _) <- clientsF
|
(client, _, _) <- clientsF
|
||||||
balance <- client.getBalance
|
balance <- client.getBalance
|
||||||
_ <- client.generate(1)
|
_ <- client.getNewAddress.flatMap(client.generateToAddress(1, _))
|
||||||
newBalance <- client.getBalance
|
newBalance <- client.getBalance
|
||||||
} yield {
|
} yield {
|
||||||
assert(balance.toBigDecimal > 0)
|
assert(balance.toBigDecimal > 0)
|
||||||
|
|
|
@ -42,7 +42,8 @@ class BitcoindV16RpcClientTest extends BitcoindRpcTest {
|
||||||
(client, otherClient) <- clientsF
|
(client, otherClient) <- clientsF
|
||||||
addr <- client.getNewAddress
|
addr <- client.getNewAddress
|
||||||
_ <- otherClient.sendToAddress(addr, Bitcoins.one)
|
_ <- otherClient.sendToAddress(addr, Bitcoins.one)
|
||||||
_ <- otherClient.generate(6)
|
_ <- otherClient.getNewAddress.flatMap(
|
||||||
|
otherClient.generateToAddress(6, _))
|
||||||
peers <- client.getPeerInfo
|
peers <- client.getPeerInfo
|
||||||
_ = assert(peers.exists(_.networkInfo.addr == otherClient.getDaemon.uri))
|
_ = assert(peers.exists(_.networkInfo.addr == otherClient.getDaemon.uri))
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,8 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
||||||
addressNoLabel <- client.getNewAddress
|
addressNoLabel <- client.getNewAddress
|
||||||
_ <- otherClient.sendToAddress(addressNoLabel, Bitcoins.one)
|
_ <- otherClient.sendToAddress(addressNoLabel, Bitcoins.one)
|
||||||
_ <- otherClient.sendToAddress(addressWithLabel, Bitcoins.one)
|
_ <- otherClient.sendToAddress(addressWithLabel, Bitcoins.one)
|
||||||
newBlock +: _ <- otherClient.generate(1)
|
newBlock +: _ <- client.getNewAddress.flatMap(
|
||||||
|
otherClient.generateToAddress(1, _))
|
||||||
_ <- AsyncUtil.retryUntilSatisfiedF(() =>
|
_ <- AsyncUtil.retryUntilSatisfiedF(() =>
|
||||||
BitcoindRpcTestUtil.hasSeenBlock(client, newBlock))
|
BitcoindRpcTestUtil.hasSeenBlock(client, newBlock))
|
||||||
list <- client.listReceivedByLabel()
|
list <- client.listReceivedByLabel()
|
||||||
|
|
|
@ -15,6 +15,7 @@ import scala.concurrent.Future
|
||||||
*/
|
*/
|
||||||
trait MiningRpc { self: Client =>
|
trait MiningRpc { self: Client =>
|
||||||
|
|
||||||
|
@deprecated("use generateToAddress instead", since = "0.18.0")
|
||||||
def generate(
|
def generate(
|
||||||
blocks: Int,
|
blocks: Int,
|
||||||
maxTries: Int = 1000000): Future[Vector[DoubleSha256DigestBE]] = {
|
maxTries: Int = 1000000): Future[Vector[DoubleSha256DigestBE]] = {
|
||||||
|
|
|
@ -12,7 +12,7 @@ class BitcoindChainHandlerViaZmqTest extends ChainUnitTest {
|
||||||
|
|
||||||
override type FixtureParam = BitcoindChainHandlerViaZmq
|
override type FixtureParam = BitcoindChainHandlerViaZmq
|
||||||
|
|
||||||
override implicit val system: ActorSystem = ActorSystem("ChainUnitTest")
|
implicit override val system: ActorSystem = ActorSystem("ChainUnitTest")
|
||||||
|
|
||||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
override def withFixture(test: OneArgAsyncTest): FutureOutcome =
|
||||||
withBitcoindChainHandlerViaZmq(test)
|
withBitcoindChainHandlerViaZmq(test)
|
||||||
|
@ -25,27 +25,23 @@ class BitcoindChainHandlerViaZmqTest extends ChainUnitTest {
|
||||||
|
|
||||||
val chainHandler = bitcoindChainHandler.chainHandler
|
val chainHandler = bitcoindChainHandler.chainHandler
|
||||||
|
|
||||||
val assert1F = chainHandler.getBlockCount
|
for {
|
||||||
.map(count => assert(count == 0))
|
_ <- chainHandler.getBlockCount
|
||||||
|
.map(count => assert(count == 0))
|
||||||
//mine a block on bitcoind
|
address <- bitcoind.getNewAddress
|
||||||
val generatedF = assert1F.flatMap(_ => bitcoind.generate(1))
|
hash +: _ <- bitcoind.generateToAddress(1, address)
|
||||||
|
_ <- {
|
||||||
generatedF.flatMap { headers =>
|
|
||||||
val hash = headers.head
|
|
||||||
val foundHeaderF: Future[Unit] = {
|
|
||||||
//test case is totally async since we
|
//test case is totally async since we
|
||||||
//can't monitor processing flow for zmq
|
//can't monitor processing flow for zmq
|
||||||
//so we just need to await until we
|
//so we just need to await until we
|
||||||
//have fully processed the header
|
//have fully processed the header
|
||||||
RpcUtil.awaitConditionF(() =>
|
RpcUtil.awaitConditionF(
|
||||||
chainHandler.getHeader(hash).map(_.isDefined))
|
() => chainHandler.getHeader(hash).map(_.isDefined)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
header <- chainHandler.getHeader(hash)
|
||||||
_ <- foundHeaderF
|
} yield assert(header.get.hashBE == hash)
|
||||||
header <- chainHandler.getHeader(hash)
|
|
||||||
} yield assert(header.get.hashBE == hash)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import scala.concurrent.Future
|
||||||
class ChainSyncTest extends ChainUnitTest {
|
class ChainSyncTest extends ChainUnitTest {
|
||||||
override type FixtureParam = BitcoindChainHandlerViaRpc
|
override type FixtureParam = BitcoindChainHandlerViaRpc
|
||||||
|
|
||||||
override implicit val system = ActorSystem(
|
implicit override val system = ActorSystem(
|
||||||
s"chain-sync-test-${System.currentTimeMillis()}")
|
s"chain-sync-test-${System.currentTimeMillis()}")
|
||||||
|
|
||||||
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
override def withFixture(test: OneArgAsyncTest): FutureOutcome = {
|
||||||
|
@ -35,7 +35,8 @@ class ChainSyncTest extends ChainUnitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//let's generate a block on bitcoind
|
//let's generate a block on bitcoind
|
||||||
val block1F = bitcoind.generate(1)
|
val block1F =
|
||||||
|
bitcoind.getNewAddress.flatMap(bitcoind.generateToAddress(1, _))
|
||||||
val newChainHandlerF: Future[ChainApi] = block1F.flatMap { hashes =>
|
val newChainHandlerF: Future[ChainApi] = block1F.flatMap { hashes =>
|
||||||
ChainSync.sync(chainHandler = chainHandler,
|
ChainSync.sync(chainHandler = chainHandler,
|
||||||
getBlockHeaderFunc = getBlockHeaderFunc,
|
getBlockHeaderFunc = getBlockHeaderFunc,
|
||||||
|
|
|
@ -68,12 +68,12 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
val logger: Logger = BitcoinSLogger.logger
|
val logger: Logger = BitcoinSLogger.logger
|
||||||
|
|
||||||
lazy val bitcoindRpcClientF: Future[BitcoindRpcClient] = {
|
lazy val bitcoindRpcClientF: Future[BitcoindRpcClient] = {
|
||||||
val cliF = EclairRpcTestUtil.startedBitcoindRpcClient()
|
for {
|
||||||
// make sure we have enough money open channels
|
cli <- EclairRpcTestUtil.startedBitcoindRpcClient()
|
||||||
//not async safe
|
// make sure we have enough money to open channels
|
||||||
val blocksF = cliF.flatMap(_.generate(200))
|
address <- cli.getNewAddress
|
||||||
|
_ <- cli.generateToAddress(200, address)
|
||||||
blocksF.flatMap(_ => cliF)
|
} yield cli
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy val eclairNodesF: Future[EclairNodes4] = {
|
lazy val eclairNodesF: Future[EclairNodes4] = {
|
||||||
|
@ -383,15 +383,16 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
val getIsConfirmed = { (client: EclairRpcClient, _: EclairRpcClient) =>
|
val getIsConfirmed = { (client: EclairRpcClient, _: EclairRpcClient) =>
|
||||||
isOpenedF.flatMap {
|
isOpenedF.flatMap {
|
||||||
case (chanId, assertion) =>
|
case (chanId, assertion) =>
|
||||||
val generatedF = bitcoindRpcClientF.flatMap(_.generate(6))
|
for {
|
||||||
val normalF = generatedF.flatMap { _ =>
|
bitcoind <- bitcoindRpcClientF
|
||||||
EclairRpcTestUtil.awaitUntilChannelNormal(
|
address <- bitcoind.getNewAddress
|
||||||
|
_ <- bitcoind.generateToAddress(6, address)
|
||||||
|
_ <- EclairRpcTestUtil.awaitUntilChannelNormal(
|
||||||
client = client,
|
client = client,
|
||||||
chanId = chanId
|
chanId = chanId
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
normalF.map(_ => (chanId, assertion))
|
} yield (chanId, assertion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,7 +546,9 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
_ <- EclairRpcTestUtil.awaitUntilPaymentSucceeded(client, paymentId)
|
_ <- EclairRpcTestUtil.awaitUntilPaymentSucceeded(client, paymentId)
|
||||||
succeeded <- client.getSentInfo(invoice.lnTags.paymentHash.hash)
|
succeeded <- client.getSentInfo(invoice.lnTags.paymentHash.hash)
|
||||||
_ <- client.close(channelId)
|
_ <- client.close(channelId)
|
||||||
_ <- bitcoindRpcClientF.flatMap(_.generate(6))
|
bitcoind <- bitcoindRpcClientF
|
||||||
|
address <- bitcoind.getNewAddress
|
||||||
|
_ <- bitcoind.generateToAddress(6, address)
|
||||||
} yield {
|
} yield {
|
||||||
assert(succeeded.nonEmpty)
|
assert(succeeded.nonEmpty)
|
||||||
|
|
||||||
|
@ -578,7 +581,9 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
_ <- EclairRpcTestUtil.awaitUntilChannelClosing(otherClient,
|
_ <- EclairRpcTestUtil.awaitUntilChannelClosing(otherClient,
|
||||||
channelId)
|
channelId)
|
||||||
channel <- otherClient.channel(channelId)
|
channel <- otherClient.channel(channelId)
|
||||||
_ <- bitcoindRpcClientF.flatMap(_.generate(6))
|
bitcoind <- bitcoindRpcClientF
|
||||||
|
address <- bitcoind.getNewAddress
|
||||||
|
_ <- bitcoind.generateToAddress(6, address)
|
||||||
} yield {
|
} yield {
|
||||||
assert(succeeded.nonEmpty)
|
assert(succeeded.nonEmpty)
|
||||||
|
|
||||||
|
@ -610,7 +615,9 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
_ <- EclairRpcTestUtil.awaitUntilPaymentSucceeded(client, paymentId)
|
_ <- EclairRpcTestUtil.awaitUntilPaymentSucceeded(client, paymentId)
|
||||||
succeeded <- client.getSentInfo(invoice.lnTags.paymentHash.hash)
|
succeeded <- client.getSentInfo(invoice.lnTags.paymentHash.hash)
|
||||||
_ <- client.close(channelId)
|
_ <- client.close(channelId)
|
||||||
_ <- bitcoindRpcClientF.flatMap(_.generate(6))
|
bitcoind <- bitcoindRpcClientF
|
||||||
|
address <- bitcoind.getNewAddress
|
||||||
|
_ <- bitcoind.generateToAddress(6, address)
|
||||||
} yield {
|
} yield {
|
||||||
assert(succeeded.nonEmpty)
|
assert(succeeded.nonEmpty)
|
||||||
|
|
||||||
|
@ -811,7 +818,12 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
}
|
}
|
||||||
|
|
||||||
val gen10F =
|
val gen10F =
|
||||||
openedChannelsF.flatMap(_ => bitcoindRpcClientF.flatMap(_.generate(10)))
|
for {
|
||||||
|
_ <- openedChannelsF
|
||||||
|
bitcoind <- bitcoindRpcClientF
|
||||||
|
address <- bitcoind.getNewAddress
|
||||||
|
hashes <- bitcoind.generateToAddress(10, address)
|
||||||
|
} yield hashes
|
||||||
|
|
||||||
val nodesReadyForPayments = gen10F.flatMap(_ => connectedClientsF)
|
val nodesReadyForPayments = gen10F.flatMap(_ => connectedClientsF)
|
||||||
|
|
||||||
|
@ -1122,9 +1134,12 @@ class EclairRpcClientTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
}
|
}
|
||||||
|
|
||||||
//confirm the funding tx
|
//confirm the funding tx
|
||||||
val genF = channelIdF.flatMap { _ =>
|
val genF = for {
|
||||||
bitcoindRpcF.flatMap(_.generate(6))
|
_ <- channelIdF
|
||||||
}
|
bitcoind <- bitcoindRpcF
|
||||||
|
address <- bitcoind.getNewAddress
|
||||||
|
headers <- bitcoind.generateToAddress(6, address)
|
||||||
|
} yield headers
|
||||||
|
|
||||||
channelIdF.flatMap { cid =>
|
channelIdF.flatMap { cid =>
|
||||||
genF.flatMap { _ =>
|
genF.flatMap { _ =>
|
||||||
|
|
|
@ -12,11 +12,12 @@ class EclairRpcTestUtilTest extends AsyncFlatSpec with BeforeAndAfterAll {
|
||||||
implicit private val actorSystem: ActorSystem =
|
implicit private val actorSystem: ActorSystem =
|
||||||
ActorSystem("EclairRpcTestUtilTest", BitcoindRpcTestUtil.AKKA_CONFIG)
|
ActorSystem("EclairRpcTestUtilTest", BitcoindRpcTestUtil.AKKA_CONFIG)
|
||||||
|
|
||||||
private lazy val bitcoindRpcF = {
|
private lazy val bitcoindRpcF =
|
||||||
val cliF = EclairRpcTestUtil.startedBitcoindRpcClient()
|
for {
|
||||||
val blocksF = cliF.flatMap(_.generate(200))
|
cli <- EclairRpcTestUtil.startedBitcoindRpcClient()
|
||||||
blocksF.flatMap(_ => cliF)
|
address <- cli.getNewAddress
|
||||||
}
|
blocks <- cli.generateToAddress(200, address)
|
||||||
|
} yield cli
|
||||||
|
|
||||||
private val clients =
|
private val clients =
|
||||||
Vector.newBuilder[EclairRpcClient]
|
Vector.newBuilder[EclairRpcClient]
|
||||||
|
|
|
@ -32,9 +32,9 @@ class SpvNodeTest extends NodeUnitTest {
|
||||||
a2 <- spvNode.isInitialized.map(assert(_))
|
a2 <- spvNode.isInitialized.map(assert(_))
|
||||||
} yield a2
|
} yield a2
|
||||||
|
|
||||||
val hashF: Future[DoubleSha256DigestBE] = {
|
val hashF: Future[DoubleSha256DigestBE] = bitcoind.getNewAddress
|
||||||
bitcoind.generate(1).map(_.head)
|
.flatMap(bitcoind.generateToAddress(1, _))
|
||||||
}
|
.map(_.head)
|
||||||
|
|
||||||
//sync our spv node expecting to get that generated hash
|
//sync our spv node expecting to get that generated hash
|
||||||
val spvSyncF = for {
|
val spvSyncF = for {
|
||||||
|
@ -58,7 +58,8 @@ class SpvNodeTest extends NodeUnitTest {
|
||||||
//we need to generate 1 block for bitcoind to consider
|
//we need to generate 1 block for bitcoind to consider
|
||||||
//itself out of IBD. bitcoind will not sendheaders
|
//itself out of IBD. bitcoind will not sendheaders
|
||||||
//when it believes itself, or it's peer is in IBD
|
//when it believes itself, or it's peer is in IBD
|
||||||
val gen1F = bitcoind.generate(1)
|
val gen1F =
|
||||||
|
bitcoind.getNewAddress.flatMap(bitcoind.generateToAddress(1, _))
|
||||||
|
|
||||||
//this needs to be called to get our peer to send us headers
|
//this needs to be called to get our peer to send us headers
|
||||||
//as they happen with the 'sendheaders' message
|
//as they happen with the 'sendheaders' message
|
||||||
|
@ -103,7 +104,7 @@ class SpvNodeTest extends NodeUnitTest {
|
||||||
val genBlock = new Runnable {
|
val genBlock = new Runnable {
|
||||||
override def run(): Unit = {
|
override def run(): Unit = {
|
||||||
if (counter < desiredBlocks) {
|
if (counter < desiredBlocks) {
|
||||||
bitcoind.generate(1)
|
bitcoind.getNewAddress.flatMap(bitcoind.generateToAddress(1, _))
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
} else {
|
} else {
|
||||||
//do nothing
|
//do nothing
|
||||||
|
|
|
@ -29,8 +29,6 @@ import scala.concurrent.duration.{DurationInt, FiniteDuration}
|
||||||
import scala.concurrent.{ExecutionContext, Future}
|
import scala.concurrent.{ExecutionContext, Future}
|
||||||
import scala.util.{Failure, Success}
|
import scala.util.{Failure, Success}
|
||||||
import org.bitcoins.rpc.config.BitcoindAuthCredentials
|
import org.bitcoins.rpc.config.BitcoindAuthCredentials
|
||||||
import java.nio.file.Paths
|
|
||||||
import scala.util.Properties
|
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,16 +46,8 @@ trait EclairRpcTestUtil extends BitcoinSLogger {
|
||||||
import org.bitcoins.core.compat.JavaConverters._
|
import org.bitcoins.core.compat.JavaConverters._
|
||||||
|
|
||||||
/** Directory where sbt downloads Eclair binaries */
|
/** Directory where sbt downloads Eclair binaries */
|
||||||
private[bitcoins] lazy val binaryDirectory = {
|
private[bitcoins] val binaryDirectory =
|
||||||
val baseDirectory = {
|
BitcoindRpcTestUtil.baseBinaryDirectory.resolve("eclair")
|
||||||
val cwd = Paths.get(Properties.userDir)
|
|
||||||
if (cwd.endsWith("eclair-rpc-test") || cwd.endsWith("bitcoind-rpc-test")) {
|
|
||||||
cwd.getParent()
|
|
||||||
} else cwd
|
|
||||||
}
|
|
||||||
|
|
||||||
baseDirectory.resolve("binaries").resolve("eclair")
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Path to Jar downloaded by Eclair, if it exists */
|
/** Path to Jar downloaded by Eclair, if it exists */
|
||||||
private[bitcoins] lazy val binary: Option[File] = {
|
private[bitcoins] lazy val binary: Option[File] = {
|
||||||
|
@ -389,7 +379,8 @@ trait EclairRpcTestUtil extends BitcoinSLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
val genBlocksF = openChannelsF.flatMap { _ =>
|
val genBlocksF = openChannelsF.flatMap { _ =>
|
||||||
internalBitcoindF.flatMap(_.generate(3))
|
internalBitcoindF.flatMap(client =>
|
||||||
|
client.getNewAddress.flatMap(client.generateToAddress(3, _)))
|
||||||
}
|
}
|
||||||
|
|
||||||
genBlocksF.flatMap { _ =>
|
genBlocksF.flatMap { _ =>
|
||||||
|
@ -595,7 +586,11 @@ trait EclairRpcTestUtil extends BitcoinSLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val gen = fundedChannelIdF.flatMap(_ => bitcoindRpcClient.generate(6))
|
val gen = for {
|
||||||
|
_ <- fundedChannelIdF
|
||||||
|
address <- bitcoindRpcClient.getNewAddress
|
||||||
|
blocks <- bitcoindRpcClient.generateToAddress(6, address)
|
||||||
|
} yield blocks
|
||||||
|
|
||||||
val openedF = {
|
val openedF = {
|
||||||
gen.flatMap { _ =>
|
gen.flatMap { _ =>
|
||||||
|
|
|
@ -147,16 +147,25 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||||
|
|
||||||
lazy val network: RegTest.type = RegTest
|
lazy val network: RegTest.type = RegTest
|
||||||
|
|
||||||
|
/** The base directory where binaries needed in tests
|
||||||
|
* are located. */
|
||||||
|
private[bitcoins] val baseBinaryDirectory = {
|
||||||
|
val cwd = Paths.get(Properties.userDir)
|
||||||
|
val pathsToGoBackFrom = List("eclair-rpc-test",
|
||||||
|
"bitcoind-rpc-test",
|
||||||
|
"node-test",
|
||||||
|
"wallet-test",
|
||||||
|
"chain-test")
|
||||||
|
|
||||||
|
val rootDir = if (pathsToGoBackFrom.exists(cwd.endsWith)) {
|
||||||
|
cwd.getParent()
|
||||||
|
} else cwd
|
||||||
|
rootDir.resolve("binaries")
|
||||||
|
}
|
||||||
|
|
||||||
/** The directory that sbt downloads bitcoind binaries into */
|
/** The directory that sbt downloads bitcoind binaries into */
|
||||||
private[bitcoins] val binaryDirectory = {
|
private[bitcoins] val binaryDirectory = {
|
||||||
val baseDirectory = {
|
baseBinaryDirectory.resolve("bitcoind")
|
||||||
val cwd = Paths.get(Properties.userDir)
|
|
||||||
if (cwd.endsWith("bitcoind-rpc-test") || cwd.endsWith("eclair-rpc-test")) {
|
|
||||||
cwd.getParent()
|
|
||||||
} else cwd
|
|
||||||
}
|
|
||||||
|
|
||||||
baseDirectory.resolve("binaries").resolve("bitcoind")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getBinary(version: BitcoindVersion): File = version match {
|
private def getBinary(version: BitcoindVersion): File = version match {
|
||||||
|
|
|
@ -101,7 +101,7 @@ class WalletIntegrationTest extends BitcoinSWalletTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
txid <- bitcoind.sendRawTransaction(signedTx)
|
txid <- bitcoind.sendRawTransaction(signedTx)
|
||||||
_ <- bitcoind.generate(1)
|
_ <- bitcoind.getNewAddress.flatMap(bitcoind.generateToAddress(1, _))
|
||||||
tx <- bitcoind.getRawTransaction(txid)
|
tx <- bitcoind.getRawTransaction(txid)
|
||||||
|
|
||||||
_ <- wallet.listUtxos().map {
|
_ <- wallet.listUtxos().map {
|
||||||
|
|
Loading…
Add table
Reference in a new issue