mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
test: refactor: simplify p2p_tx_download.py by using MiniWallet
This commit is contained in:
parent
2343886217
commit
7aa4b32cd4
1 changed files with 7 additions and 18 deletions
|
@ -5,6 +5,7 @@
|
|||
"""
|
||||
Test transaction download behavior
|
||||
"""
|
||||
import time
|
||||
|
||||
from test_framework.messages import (
|
||||
CInv,
|
||||
|
@ -13,7 +14,6 @@ from test_framework.messages import (
|
|||
MSG_WTX,
|
||||
msg_inv,
|
||||
msg_notfound,
|
||||
tx_from_hex,
|
||||
)
|
||||
from test_framework.p2p import (
|
||||
P2PInterface,
|
||||
|
@ -23,9 +23,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import (
|
||||
assert_equal,
|
||||
)
|
||||
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
|
||||
|
||||
import time
|
||||
from test_framework.wallet import MiniWallet
|
||||
|
||||
|
||||
class TestP2PConn(P2PInterface):
|
||||
|
@ -88,19 +86,8 @@ class TxDownloadTest(BitcoinTestFramework):
|
|||
|
||||
def test_inv_block(self):
|
||||
self.log.info("Generate a transaction on node 0")
|
||||
tx = self.nodes[0].createrawtransaction(
|
||||
inputs=[{ # coinbase
|
||||
"txid": self.nodes[0].getblock(self.nodes[0].getblockhash(1))['tx'][0],
|
||||
"vout": 0
|
||||
}],
|
||||
outputs={ADDRESS_BCRT1_UNSPENDABLE: 50 - 0.00025},
|
||||
)
|
||||
tx = self.nodes[0].signrawtransactionwithkey(
|
||||
hexstring=tx,
|
||||
privkeys=[self.nodes[0].get_deterministic_priv_key().key],
|
||||
)['hex']
|
||||
ctx = tx_from_hex(tx)
|
||||
txid = int(ctx.rehash(), 16)
|
||||
tx = self.wallet.create_self_transfer()
|
||||
txid = int(tx['txid'], 16)
|
||||
|
||||
self.log.info(
|
||||
"Announce the transaction to all nodes from all {} incoming peers, but never send it".format(NUM_INBOUND))
|
||||
|
@ -109,7 +96,7 @@ class TxDownloadTest(BitcoinTestFramework):
|
|||
p.send_and_ping(msg)
|
||||
|
||||
self.log.info("Put the tx in node 0's mempool")
|
||||
self.nodes[0].sendrawtransaction(tx)
|
||||
self.nodes[0].sendrawtransaction(tx['hex'])
|
||||
|
||||
# Since node 1 is connected outbound to an honest peer (node 0), it
|
||||
# should get the tx within a timeout. (Assuming that node 0
|
||||
|
@ -255,6 +242,8 @@ class TxDownloadTest(BitcoinTestFramework):
|
|||
self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(MSG_TX, 1)]))
|
||||
|
||||
def run_test(self):
|
||||
self.wallet = MiniWallet(self.nodes[0])
|
||||
|
||||
# Run tests without mocktime that only need one peer-connection first, to avoid restarting the nodes
|
||||
self.test_expiry_fallback()
|
||||
self.test_disconnect_fallback()
|
||||
|
|
Loading…
Reference in a new issue