func tests: move function to utils
This commit is contained in:
parent
fdab722eff
commit
68b2503b12
@ -8,6 +8,7 @@ from test_framework.utils import (
|
||||
RpcError,
|
||||
COIN,
|
||||
sign_and_broadcast,
|
||||
sign_and_broadcast_psbt,
|
||||
)
|
||||
from test_framework.serializations import PSBT
|
||||
|
||||
@ -409,14 +410,6 @@ def test_conflicting_unconfirmed_spend_txs(lianad, bitcoind):
|
||||
wait_for(lambda: is_spent_by(lianad, spent_coin["outpoint"], txid_b))
|
||||
|
||||
|
||||
def sign_and_broadcast_psbt(lianad, psbt):
|
||||
txid = psbt.tx.txid().hex()
|
||||
psbt = lianad.signer.sign_psbt(psbt)
|
||||
lianad.rpc.updatespend(psbt.to_base64())
|
||||
lianad.rpc.broadcastspend(txid)
|
||||
return txid
|
||||
|
||||
|
||||
def test_spend_replacement(lianad, bitcoind):
|
||||
"""Test we detect the new version of the unconfirmed spending transaction."""
|
||||
# Get three coins.
|
||||
|
||||
@ -85,6 +85,15 @@ def sign_and_broadcast(lianad, bitcoind, psbt, recovery=False):
|
||||
return bitcoind.rpc.sendrawtransaction(tx)
|
||||
|
||||
|
||||
def sign_and_broadcast_psbt(lianad, psbt):
|
||||
"""Sign a PSBT, save it to the DB and broadcast it."""
|
||||
txid = psbt.tx.txid().hex()
|
||||
psbt = lianad.signer.sign_psbt(psbt)
|
||||
lianad.rpc.updatespend(psbt.to_base64())
|
||||
lianad.rpc.broadcastspend(txid)
|
||||
return txid
|
||||
|
||||
|
||||
class RpcError(ValueError):
|
||||
def __init__(self, method: str, params: dict, error: str):
|
||||
super(ValueError, self).__init__(
|
||||
|
||||
@ -16,6 +16,7 @@ from test_framework.utils import (
|
||||
get_txid,
|
||||
spend_coins,
|
||||
sign_and_broadcast,
|
||||
sign_and_broadcast_psbt,
|
||||
)
|
||||
|
||||
|
||||
@ -663,13 +664,6 @@ def test_start_rescan(lianad, bitcoind):
|
||||
def test_listtransactions(lianad, bitcoind):
|
||||
"""Test listing of transactions by txid and timespan"""
|
||||
|
||||
def sign_and_broadcast(psbt):
|
||||
txid = psbt.tx.txid().hex()
|
||||
psbt = lianad.signer.sign_psbt(psbt)
|
||||
lianad.rpc.updatespend(psbt.to_base64())
|
||||
lianad.rpc.broadcastspend(txid)
|
||||
return txid
|
||||
|
||||
def wait_synced():
|
||||
wait_for(
|
||||
lambda: lianad.rpc.getinfo()["block_height"] == bitcoind.rpc.getblockcount()
|
||||
@ -715,7 +709,7 @@ def test_listtransactions(lianad, bitcoind):
|
||||
}
|
||||
res = lianad.rpc.createspend(destinations, [outpoint], 6)
|
||||
psbt = PSBT.from_base64(res["psbt"])
|
||||
txid = sign_and_broadcast(psbt)
|
||||
txid = sign_and_broadcast_psbt(lianad, psbt)
|
||||
bitcoind.generate_block(1, wait_for_mempool=txid)
|
||||
|
||||
# Mine 12 blocks to force the blocktime to increase
|
||||
@ -742,7 +736,7 @@ def test_listtransactions(lianad, bitcoind):
|
||||
}
|
||||
res = lianad.rpc.createspend(destinations, [outpoint], 6)
|
||||
psbt = PSBT.from_base64(res["psbt"])
|
||||
txid = sign_and_broadcast(psbt)
|
||||
txid = sign_and_broadcast_psbt(lianad, psbt)
|
||||
bitcoind.generate_block(1, wait_for_mempool=txid)
|
||||
|
||||
# Deposit a coin that will be spending (unconfirmed spend transaction)
|
||||
@ -758,7 +752,7 @@ def test_listtransactions(lianad, bitcoind):
|
||||
}
|
||||
res = lianad.rpc.createspend(destinations, [outpoint], 6)
|
||||
psbt = PSBT.from_base64(res["psbt"])
|
||||
txid = sign_and_broadcast(psbt)
|
||||
txid = sign_and_broadcast_psbt(lianad, psbt)
|
||||
|
||||
# At this point we have 12 spent and unspent coins, one of them is unconfirmed.
|
||||
wait_for(lambda: len(lianad.rpc.listcoins()["coins"]) == 12)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user