mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
Add receiver param to BitcoindRpcTestUtil.fundBlockChainTransaction() (#737)
* Add receiver param to BitcoindRpcTestUtil.fundBlockChainTransaction() * Actually implement awaiting for the hash to be seen
This commit is contained in:
parent
d4ccc2c441
commit
642a3366b1
@ -132,13 +132,16 @@ class RawTransactionRpcTest extends BitcoindRpcTest {
|
||||
|
||||
it should "be able to sign a raw transaction" in {
|
||||
for {
|
||||
(client, _) <- clientsF
|
||||
(client, server) <- clientsF
|
||||
address <- client.getNewAddress
|
||||
pubkey <- BitcoindRpcTestUtil.getPubkey(client, address)
|
||||
multisig <- client
|
||||
.addMultiSigAddress(1, Vector(Left(pubkey.get)))
|
||||
txid <- BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(client, multisig.address, Bitcoins(1.2))
|
||||
.fundBlockChainTransaction(client,
|
||||
server,
|
||||
multisig.address,
|
||||
Bitcoins(1.2))
|
||||
rawTx <- client.getTransaction(txid)
|
||||
|
||||
tx <- client.decodeRawTransaction(rawTx.hex)
|
||||
@ -187,6 +190,7 @@ class RawTransactionRpcTest extends BitcoindRpcTest {
|
||||
_ <- otherClient.addMultiSigAddress(2, keys)
|
||||
|
||||
txid <- BitcoindRpcTestUtil.fundBlockChainTransaction(client,
|
||||
otherClient,
|
||||
multisig.address,
|
||||
Bitcoins(1.2))
|
||||
|
||||
|
@ -7,11 +7,18 @@ import org.bitcoins.core.crypto.{ECPrivateKey, ECPublicKey}
|
||||
import org.bitcoins.core.currency.{Bitcoins, CurrencyUnit, Satoshis}
|
||||
import org.bitcoins.core.number.{Int64, UInt32}
|
||||
import org.bitcoins.core.protocol.script.ScriptSignature
|
||||
import org.bitcoins.core.protocol.transaction.{TransactionInput, TransactionOutPoint}
|
||||
import org.bitcoins.core.protocol.transaction.{
|
||||
TransactionInput,
|
||||
TransactionOutPoint
|
||||
}
|
||||
import org.bitcoins.core.protocol.{BitcoinAddress, P2PKHAddress}
|
||||
import org.bitcoins.core.wallet.fee.SatoshisPerByte
|
||||
import org.bitcoins.rpc.client.common.RpcOpts.AddressType
|
||||
import org.bitcoins.rpc.client.common.{BitcoindRpcClient, BitcoindVersion, RpcOpts}
|
||||
import org.bitcoins.rpc.client.common.{
|
||||
BitcoindRpcClient,
|
||||
BitcoindVersion,
|
||||
RpcOpts
|
||||
}
|
||||
import org.bitcoins.rpc.util.RpcUtil
|
||||
import org.bitcoins.testkit.rpc.BitcoindRpcTestUtil
|
||||
import org.bitcoins.testkit.util.BitcoindRpcTest
|
||||
@ -210,7 +217,7 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||
|
||||
val txidF =
|
||||
BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(client, address, Bitcoins(1.5))
|
||||
.fundBlockChainTransaction(client, thirdClient, address, Bitcoins(1.5))
|
||||
val txid = await(txidF)
|
||||
|
||||
await(client.getNewAddress.flatMap(client.generateToAddress(1, _)))
|
||||
@ -242,9 +249,14 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||
|
||||
val amount = Bitcoins(1.25)
|
||||
|
||||
def getChangeAddressAndAmount(client: BitcoindRpcClient, address: BitcoinAddress): Future[(BitcoinAddress, CurrencyUnit)] = {
|
||||
def getChangeAddressAndAmount(
|
||||
client: BitcoindRpcClient,
|
||||
address: BitcoinAddress): Future[(BitcoinAddress, CurrencyUnit)] = {
|
||||
for {
|
||||
listTx <- client.listTransactions().map(_.filter(tx => tx.address.contains(address) && tx.category == "send"))
|
||||
listTx <- client
|
||||
.listTransactions()
|
||||
.map(_.filter(tx =>
|
||||
tx.address.contains(address) && tx.category == "send"))
|
||||
_ = assert(listTx.nonEmpty)
|
||||
tx = listTx.head
|
||||
_ = assert(tx.txid.nonEmpty)
|
||||
@ -252,22 +264,26 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||
} yield {
|
||||
val outs = rawTx.outputs.filterNot(_.value == amount)
|
||||
val changeAddresses = outs
|
||||
.map(out => (BitcoinAddress.fromScriptPubKey(out.scriptPubKey, networkParam), out.value))
|
||||
.map(
|
||||
out =>
|
||||
(BitcoinAddress.fromScriptPubKey(out.scriptPubKey, networkParam),
|
||||
out.value))
|
||||
assert(changeAddresses.size == 1)
|
||||
(changeAddresses.head._1.get, changeAddresses.head._2)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
(client, _, _) <- clientsF
|
||||
(client, otherClient, _) <- clientsF
|
||||
groupingsBefore <- client.listAddressGroupings
|
||||
|
||||
address <- client.getNewAddress
|
||||
|
||||
_ <- BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(client, address, amount)
|
||||
.fundBlockChainTransaction(client, otherClient, address, amount)
|
||||
|
||||
(changeAddress, changeAmount) <- getChangeAddressAndAmount(client, address)
|
||||
(changeAddress, changeAmount) <- getChangeAddressAndAmount(client,
|
||||
address)
|
||||
|
||||
groupingsAfter <- client.listAddressGroupings
|
||||
} yield {
|
||||
@ -279,9 +295,13 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||
assert(rpcAddress.balance == amount)
|
||||
|
||||
// the change address should be added to an exiting address grouping
|
||||
val changeGrouping = groupingsAfter.find(after =>
|
||||
groupingsBefore.exists(before => before.head == after.head && before.size + 1 == after.size)).get
|
||||
val rpcChangeAddress = changeGrouping.find(addr => addr.address == changeAddress).get
|
||||
val changeGrouping = groupingsAfter
|
||||
.find(after =>
|
||||
groupingsBefore.exists(before =>
|
||||
before.head == after.head && before.size + 1 == after.size))
|
||||
.get
|
||||
val rpcChangeAddress =
|
||||
changeGrouping.find(addr => addr.address == changeAddress).get
|
||||
assert(rpcChangeAddress.address == changeAddress)
|
||||
assert(rpcChangeAddress.balance == changeAmount)
|
||||
}
|
||||
@ -319,7 +339,7 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||
(client, otherClient, _) <- clientsF
|
||||
address <- otherClient.getNewAddress
|
||||
txid <- BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(client, address, Bitcoins(1.5))
|
||||
.fundBlockChainTransaction(client, otherClient, address, Bitcoins(1.5))
|
||||
receivedList <- otherClient.listReceivedByAddress()
|
||||
} yield {
|
||||
val entryList =
|
||||
@ -339,6 +359,7 @@ class WalletRpcTest extends BitcoindRpcTest {
|
||||
address <- client.getNewAddress
|
||||
_ <- otherClient.importAddress(address)
|
||||
txid <- BitcoindRpcTestUtil.fundBlockChainTransaction(client,
|
||||
otherClient,
|
||||
address,
|
||||
Bitcoins(1.5))
|
||||
list <- otherClient.listReceivedByAddress(includeWatchOnly = true)
|
||||
|
@ -147,8 +147,12 @@ class BitcoindV16RpcClientTest extends BitcoindRpcTest {
|
||||
val emptyAccount = "empty_account"
|
||||
|
||||
val ourAccountAddress = await(client.getNewAddress(ourAccount))
|
||||
await(BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(otherClient, ourAccountAddress, Bitcoins(1.5)))
|
||||
await(
|
||||
BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(otherClient,
|
||||
client,
|
||||
ourAccountAddress,
|
||||
Bitcoins(1.5)))
|
||||
|
||||
val accountlessAddress = await(client.getNewAddress)
|
||||
|
||||
@ -156,7 +160,10 @@ class BitcoindV16RpcClientTest extends BitcoindRpcTest {
|
||||
|
||||
val _ = await(
|
||||
BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(otherClient, accountlessAddress, sendAmt))
|
||||
.fundBlockChainTransaction(otherClient,
|
||||
client,
|
||||
accountlessAddress,
|
||||
sendAmt))
|
||||
|
||||
if (Properties.isMac) Thread.sleep(10000)
|
||||
val ourAccountAmount = await(client.getReceivedByAccount(ourAccount))
|
||||
|
@ -153,10 +153,10 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
||||
|
||||
it should "be able to get the amount received by a label" in {
|
||||
for {
|
||||
(client, _) <- clientsF
|
||||
(client, otherClient) <- clientsF
|
||||
address <- client.getNewAddress(usedLabel)
|
||||
_ <- BitcoindRpcTestUtil
|
||||
.fundBlockChainTransaction(client, address, Bitcoins(1.5))
|
||||
.fundBlockChainTransaction(client, otherClient, address, Bitcoins(1.5))
|
||||
|
||||
amount <- client.getReceivedByLabel(usedLabel)
|
||||
} yield assert(amount == Bitcoins(1.5))
|
||||
@ -204,7 +204,10 @@ class BitcoindV17RpcClientTest extends BitcoindRpcTest {
|
||||
for {
|
||||
(client, otherClient) <- clientsF
|
||||
addr <- client.getNewAddress
|
||||
_ <- BitcoindRpcTestUtil.fundBlockChainTransaction(otherClient, addr, btc)
|
||||
_ <- BitcoindRpcTestUtil.fundBlockChainTransaction(otherClient,
|
||||
client,
|
||||
addr,
|
||||
btc)
|
||||
|
||||
newestBlock <- otherClient.getBestBlockHash
|
||||
_ <- AsyncUtil.retryUntilSatisfiedF(() =>
|
||||
|
@ -60,9 +60,10 @@ class PsbtRpcTest extends BitcoindRpcTest {
|
||||
|
||||
it should "finalize a simple PSBT" in {
|
||||
for {
|
||||
(client, _, _) <- clientsF
|
||||
(client, otherClient, _) <- clientsF
|
||||
addr <- client.getNewAddress
|
||||
txid <- BitcoindRpcTestUtil.fundBlockChainTransaction(client,
|
||||
otherClient,
|
||||
addr,
|
||||
Bitcoins.one)
|
||||
vout <- BitcoindRpcTestUtil.findOutput(client, txid, Bitcoins.one)
|
||||
|
@ -812,17 +812,22 @@ trait BitcoindRpcTestUtil extends BitcoinSLogger {
|
||||
*/
|
||||
def fundBlockChainTransaction(
|
||||
sender: BitcoindRpcClient,
|
||||
receiver: BitcoindRpcClient,
|
||||
address: BitcoinAddress,
|
||||
amount: Bitcoins)(
|
||||
implicit system: ActorSystem): Future[DoubleSha256DigestBE] = {
|
||||
implicit val mat: ActorMaterializer = ActorMaterializer.create(system)
|
||||
implicit val ec: ExecutionContextExecutor = mat.executionContext
|
||||
fundMemPoolTransaction(sender, address, amount).flatMap { txid =>
|
||||
sender.getNewAddress.flatMap(sender.generateToAddress(1, _)).map { _ =>
|
||||
|
||||
for {
|
||||
txid <- fundMemPoolTransaction(sender, address, amount)
|
||||
addr <- sender.getNewAddress
|
||||
blockHash <- sender.generateToAddress(1, addr).map(_.head)
|
||||
_ <- hasSeenBlock(receiver, blockHash)
|
||||
} yield {
|
||||
txid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a unconfirmed transaction from `sender` to `address`
|
||||
|
Loading…
Reference in New Issue
Block a user