test: rename CTransaction .rehash()/.hash -> .txid_hex for consistency

Note that we unfortunately can't use a scripted diff here, as the same
property and method name is also used for `CBlockHeader`/`CBlock` instances.
This commit is contained in:
Sebastian Falbesoner committed 2025-06-11 00:49:10 +02:00
1 parent e9cdaefb0a
commit ce83924237
30 files changed
+136 -141

No files matched your search

+1 -1
View File
@@ -605,7 +605,7 @@ class AssumeutxoTest(BitcoinTestFramework):
privkey = n0.get_deterministic_priv_key().key privkey = n0.get_deterministic_priv_key().key
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99}) raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99})
signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex'] signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex']
signed_txid = tx_from_hex(signed_tx).rehash() signed_txid = tx_from_hex(signed_tx).txid_hex
assert n1.gettxout(prev_tx['txid'], 0) is not None assert n1.gettxout(prev_tx['txid'], 0) is not None
n1.sendrawtransaction(signed_tx) n1.sendrawtransaction(signed_tx)
+13 -13
View File
@@ -246,7 +246,7 @@ class BIP68Test(BitcoinTestFramework):
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])] tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)] tx.vout = [CTxOut(int(orig_tx.vout[0].nValue - relayfee * COIN), SCRIPT_W0_SH_OP_TRUE)]
if (orig_tx.hash in node.getrawmempool()): if (orig_tx.txid_hex in node.getrawmempool()):
# sendrawtransaction should fail if the tx is in the mempool # sendrawtransaction should fail if the tx is in the mempool
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.wallet.sendrawtransaction, from_node=node, tx_hex=tx.serialize().hex()) assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.wallet.sendrawtransaction, from_node=node, tx_hex=tx.serialize().hex())
else: else:
@@ -260,43 +260,43 @@ class BIP68Test(BitcoinTestFramework):
# Now mine some blocks, but make sure tx2 doesn't get mined. # Now mine some blocks, but make sure tx2 doesn't get mined.
# Use prioritisetransaction to lower the effective feerate to 0 # Use prioritisetransaction to lower the effective feerate to 0
self.nodes[0].prioritisetransaction(txid=tx2.hash, fee_delta=int(-self.relayfee*COIN)) self.nodes[0].prioritisetransaction(txid=tx2.txid_hex, fee_delta=int(-self.relayfee*COIN))
cur_time = int(time.time()) cur_time = int(time.time())
for _ in range(10): for _ in range(10):
self.nodes[0].setmocktime(cur_time + 600) self.nodes[0].setmocktime(cur_time + 600)
self.generate(self.wallet, 1, sync_fun=self.no_op) self.generate(self.wallet, 1, sync_fun=self.no_op)
cur_time += 600 cur_time += 600
assert tx2.hash in self.nodes[0].getrawmempool() assert tx2.txid_hex in self.nodes[0].getrawmempool()
test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=True) test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=True)
test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False) test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False)
# Mine tx2, and then try again # Mine tx2, and then try again
self.nodes[0].prioritisetransaction(txid=tx2.hash, fee_delta=int(self.relayfee*COIN)) self.nodes[0].prioritisetransaction(txid=tx2.txid_hex, fee_delta=int(self.relayfee*COIN))
# Advance the time on the node so that we can test timelocks # Advance the time on the node so that we can test timelocks
self.nodes[0].setmocktime(cur_time+600) self.nodes[0].setmocktime(cur_time+600)
# Save block template now to use for the reorg later # Save block template now to use for the reorg later
tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS) tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
assert tx2.hash not in self.nodes[0].getrawmempool() assert tx2.txid_hex not in self.nodes[0].getrawmempool()
# Now that tx2 is not in the mempool, a sequence locked spend should # Now that tx2 is not in the mempool, a sequence locked spend should
# succeed # succeed
tx3 = test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False) tx3 = test_nonzero_locks(tx2, self.nodes[0], self.relayfee, use_height_lock=False)
assert tx3.hash in self.nodes[0].getrawmempool() assert tx3.txid_hex in self.nodes[0].getrawmempool()
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
assert tx3.hash not in self.nodes[0].getrawmempool() assert tx3.txid_hex not in self.nodes[0].getrawmempool()
# One more test, this time using height locks # One more test, this time using height locks
tx4 = test_nonzero_locks(tx3, self.nodes[0], self.relayfee, use_height_lock=True) tx4 = test_nonzero_locks(tx3, self.nodes[0], self.relayfee, use_height_lock=True)
assert tx4.hash in self.nodes[0].getrawmempool() assert tx4.txid_hex in self.nodes[0].getrawmempool()
# Now try combining confirmed and unconfirmed inputs # Now try combining confirmed and unconfirmed inputs
tx5 = test_nonzero_locks(tx4, self.nodes[0], self.relayfee, use_height_lock=True) tx5 = test_nonzero_locks(tx4, self.nodes[0], self.relayfee, use_height_lock=True)
assert tx5.hash not in self.nodes[0].getrawmempool() assert tx5.txid_hex not in self.nodes[0].getrawmempool()
utxo = self.wallet.get_utxo() utxo = self.wallet.get_utxo()
tx5.vin.append(CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=1)) tx5.vin.append(CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=1))
@@ -315,8 +315,8 @@ class BIP68Test(BitcoinTestFramework):
# If we invalidate the tip, tx3 should get added to the mempool, causing # If we invalidate the tip, tx3 should get added to the mempool, causing
# tx4 to be removed (fails sequence-lock). # tx4 to be removed (fails sequence-lock).
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
assert tx4.hash not in self.nodes[0].getrawmempool() assert tx4.txid_hex not in self.nodes[0].getrawmempool()
assert tx3.hash in self.nodes[0].getrawmempool() assert tx3.txid_hex in self.nodes[0].getrawmempool()
# Now mine 2 empty blocks to reorg out the current tip (labeled tip-1 in # Now mine 2 empty blocks to reorg out the current tip (labeled tip-1 in
# diagram above). # diagram above).
@@ -333,8 +333,8 @@ class BIP68Test(BitcoinTestFramework):
cur_time += 1 cur_time += 1
mempool = self.nodes[0].getrawmempool() mempool = self.nodes[0].getrawmempool()
assert tx3.hash not in mempool assert tx3.txid_hex not in mempool
assert tx2.hash in mempool assert tx2.txid_hex in mempool
# Reset the chain and get rid of the mocktimed-blocks # Reset the chain and get rid of the mocktimed-blocks
self.nodes[0].setmocktime(0) self.nodes[0].setmocktime(0)
+5 -5
View File
@@ -150,7 +150,7 @@ class FullBlockTest(BitcoinTestFramework):
# MAX_SCRIPT_SIZE + 1 wasn't added to the utxo set # MAX_SCRIPT_SIZE + 1 wasn't added to the utxo set
tx.vin[0] = min_size_unspendable_output tx.vin[0] = min_size_unspendable_output
assert_raises_rpc_error(-25, f'TestBlockValidity failed: bad-txns-inputs-missingorspent, CheckTxInputs: inputs missing/spent in transaction {tx.rehash()}', self.generateblock, self.nodes[0], output="raw(55)", transactions=[tx.serialize().hex()]) assert_raises_rpc_error(-25, f'TestBlockValidity failed: bad-txns-inputs-missingorspent, CheckTxInputs: inputs missing/spent in transaction {tx.txid_hex}', self.generateblock, self.nodes[0], output="raw(55)", transactions=[tx.serialize().hex()])
# collect spendable outputs now to avoid cluttering the code later on # collect spendable outputs now to avoid cluttering the code later on
out = [] out = []
@@ -878,10 +878,10 @@ class FullBlockTest(BitcoinTestFramework):
b_dup_2.vtx[0].vin[0].scriptSig = DUPLICATE_COINBASE_SCRIPT_SIG b_dup_2.vtx[0].vin[0].scriptSig = DUPLICATE_COINBASE_SCRIPT_SIG
b_dup_2 = self.update_block('dup_2', []) b_dup_2 = self.update_block('dup_2', [])
assert_equal(duplicate_tx.serialize(), b_dup_2.vtx[0].serialize()) assert_equal(duplicate_tx.serialize(), b_dup_2.vtx[0].serialize())
assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.hash, n=0)['confirmations'], 119) assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.txid_hex, n=0)['confirmations'], 119)
self.send_blocks([b_spend_dup_cb, b_dup_2], success=True) self.send_blocks([b_spend_dup_cb, b_dup_2], success=True)
# The duplicate has less confirmations # The duplicate has less confirmations
assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.hash, n=0)['confirmations'], 1) assert_equal(self.nodes[0].gettxout(txid=duplicate_tx.txid_hex, n=0)['confirmations'], 1)
# Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests) # Test tx.isFinal is properly rejected (not an exhaustive tx.isFinal test, that should be in data-driven transaction tests)
# #
@@ -1211,8 +1211,8 @@ class FullBlockTest(BitcoinTestFramework):
# now check that tx78 and tx79 have been put back into the peer's mempool # now check that tx78 and tx79 have been put back into the peer's mempool
mempool = self.nodes[0].getrawmempool() mempool = self.nodes[0].getrawmempool()
assert_equal(len(mempool), 2) assert_equal(len(mempool), 2)
assert tx78.hash in mempool assert tx78.txid_hex in mempool
assert tx79.hash in mempool assert tx79.txid_hex in mempool
# Test invalid opcodes in dead execution paths. # Test invalid opcodes in dead execution paths.
# #
+1 -1
View File
@@ -162,7 +162,7 @@ class BIP65Test(BitcoinTestFramework):
][i] ][i]
# First we show that this tx is valid except for CLTV by getting it # First we show that this tx is valid except for CLTV by getting it
# rejected from the mempool for exactly that reason. # rejected from the mempool for exactly that reason.
spendtx_txid = spendtx.hash spendtx_txid = spendtx.txid_hex
spendtx_wtxid = spendtx.getwtxid() spendtx_wtxid = spendtx.getwtxid()
assert_equal( assert_equal(
[{ [{
+1 -1
View File
@@ -103,7 +103,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
self.supports_cli = False self.supports_cli = False
def create_self_transfer_from_utxo(self, input_tx): def create_self_transfer_from_utxo(self, input_tx):
utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False) utxo = self.miniwallet.get_utxo(txid=input_tx.txid_hex, mark_as_spent=False)
tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx'] tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx']
return tx return tx
+1 -1
View File
@@ -114,7 +114,7 @@ class BIP66Test(BitcoinTestFramework):
# First we show that this tx is valid except for DERSIG by getting it # First we show that this tx is valid except for DERSIG by getting it
# rejected from the mempool for exactly that reason. # rejected from the mempool for exactly that reason.
spendtx_txid = spendtx.hash spendtx_txid = spendtx.txid_hex
spendtx_wtxid = spendtx.getwtxid() spendtx_wtxid = spendtx.getwtxid()
assert_equal( assert_equal(
[{ [{
+1 -1
View File
@@ -61,7 +61,7 @@ def small_txpuzzle_randfee(
tx.vout[0].nValue = int((total_in - amount - fee) * COIN) tx.vout[0].nValue = int((total_in - amount - fee) * COIN)
tx.vout.append(deepcopy(tx.vout[0])) tx.vout.append(deepcopy(tx.vout[0]))
tx.vout[1].nValue = int(amount * COIN) tx.vout[1].nValue = int(amount * COIN)
txid = tx.hash txid = tx.txid_hex
tx_hex = tx.serialize().hex() tx_hex = tx.serialize().hex()
batch_reqs.append(from_node.sendrawtransaction.get_request(hexstring=tx_hex, maxfeerate=0)) batch_reqs.append(from_node.sendrawtransaction.get_request(hexstring=tx_hex, maxfeerate=0))
+1 -1
View File
@@ -110,7 +110,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
self.block_submit(self.nodes[0], [test2tx], accept=True) self.block_submit(self.nodes[0], [test2tx], accept=True)
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation") self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
test4tx = self.create_transaction(txid=test2tx.hash, input_details=ms_unlock_details, test4tx = self.create_transaction(txid=test2tx.txid_hex, input_details=ms_unlock_details,
addr=getnewdestination()[2], amount=46, addr=getnewdestination()[2], amount=46,
privkey=self.privkey) privkey=self.privkey)
test6txs = [CTransaction(test4tx)] test6txs = [CTransaction(test4tx)]
+5 -5
View File
@@ -110,7 +110,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception due to insufficient fee # This will raise an exception due to insufficient fee
reject_reason = "insufficient fee" reject_reason = "insufficient fee"
reject_details = f"{reject_reason}, rejecting replacement {tx.hash}; new feerate 0.00300000 BTC/kvB <= old feerate 0.00300000 BTC/kvB" reject_details = f"{reject_reason}, rejecting replacement {tx.txid_hex}; new feerate 0.00300000 BTC/kvB <= old feerate 0.00300000 BTC/kvB"
res = self.nodes[0].testmempoolaccept(rawtxs=[tx_hex])[0] res = self.nodes[0].testmempoolaccept(rawtxs=[tx_hex])[0]
assert_equal(res["reject-reason"], reject_reason) assert_equal(res["reject-reason"], reject_reason)
assert_equal(res["reject-details"], reject_details) assert_equal(res["reject-details"], reject_details)
@@ -160,7 +160,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception due to insufficient fee # This will raise an exception due to insufficient fee
reject_reason = "insufficient fee" reject_reason = "insufficient fee"
reject_details = f"{reject_reason}, rejecting replacement {dbl_tx.hash}, less fees than conflicting txs; 3.00 < 4.00" reject_details = f"{reject_reason}, rejecting replacement {dbl_tx.txid_hex}, less fees than conflicting txs; 3.00 < 4.00"
res = self.nodes[0].testmempoolaccept(rawtxs=[dbl_tx_hex])[0] res = self.nodes[0].testmempoolaccept(rawtxs=[dbl_tx_hex])[0]
assert_equal(res["reject-reason"], reject_reason) assert_equal(res["reject-reason"], reject_reason)
assert_equal(res["reject-details"], reject_details) assert_equal(res["reject-details"], reject_details)
@@ -303,7 +303,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception # This will raise an exception
reject_reason = "bad-txns-spends-conflicting-tx" reject_reason = "bad-txns-spends-conflicting-tx"
reject_details = f"{reject_reason}, {tx2.hash} spends conflicting transaction {tx1a['tx'].hash}" reject_details = f"{reject_reason}, {tx2.txid_hex} spends conflicting transaction {tx1a['tx'].txid_hex}"
res = self.nodes[0].testmempoolaccept(rawtxs=[tx2_hex])[0] res = self.nodes[0].testmempoolaccept(rawtxs=[tx2_hex])[0]
assert_equal(res["reject-reason"], reject_reason) assert_equal(res["reject-reason"], reject_reason)
assert_equal(res["reject-details"], reject_details) assert_equal(res["reject-details"], reject_details)
@@ -348,7 +348,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception # This will raise an exception
reject_reason = "replacement-adds-unconfirmed" reject_reason = "replacement-adds-unconfirmed"
reject_details = f"{reject_reason}, replacement {tx2.hash} adds unconfirmed input, idx 1" reject_details = f"{reject_reason}, replacement {tx2.txid_hex} adds unconfirmed input, idx 1"
res = self.nodes[0].testmempoolaccept(rawtxs=[tx2_hex])[0] res = self.nodes[0].testmempoolaccept(rawtxs=[tx2_hex])[0]
assert_equal(res["reject-reason"], reject_reason) assert_equal(res["reject-reason"], reject_reason)
assert_equal(res["reject-details"], reject_details) assert_equal(res["reject-details"], reject_details)
@@ -396,7 +396,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
# This will raise an exception # This will raise an exception
reject_reason = "too many potential replacements" reject_reason = "too many potential replacements"
reject_details = f"{reject_reason}, rejecting replacement {double_tx.hash}; too many potential replacements ({MAX_REPLACEMENT_LIMIT + 1} > {MAX_REPLACEMENT_LIMIT})" reject_details = f"{reject_reason}, rejecting replacement {double_tx.txid_hex}; too many potential replacements ({MAX_REPLACEMENT_LIMIT + 1} > {MAX_REPLACEMENT_LIMIT})"
res = self.nodes[0].testmempoolaccept(rawtxs=[double_tx_hex])[0] res = self.nodes[0].testmempoolaccept(rawtxs=[double_tx_hex])[0]
assert_equal(res["reject-reason"], reject_reason) assert_equal(res["reject-reason"], reject_reason)
assert_equal(res["reject-details"], reject_details) assert_equal(res["reject-details"], reject_details)
+2 -2
View File
@@ -1540,7 +1540,7 @@ class TaprootTest(BitcoinTestFramework):
msg = ','.join(utxo.spender.comment + ("*" if n == fail_input else "") for n, utxo in enumerate(input_utxos)) msg = ','.join(utxo.spender.comment + ("*" if n == fail_input else "") for n, utxo in enumerate(input_utxos))
if is_standard_tx: if is_standard_tx:
node.sendrawtransaction(tx.serialize().hex(), 0) node.sendrawtransaction(tx.serialize().hex(), 0)
assert node.getmempoolentry(tx.hash) is not None, "Failed to accept into mempool: " + msg assert node.getmempoolentry(tx.txid_hex) is not None, "Failed to accept into mempool: " + msg
else: else:
assert_raises_rpc_error(-26, None, node.sendrawtransaction, tx.serialize().hex(), 0) assert_raises_rpc_error(-26, None, node.sendrawtransaction, tx.serialize().hex(), 0)
# Submit in a block # Submit in a block
@@ -1566,7 +1566,7 @@ class TaprootTest(BitcoinTestFramework):
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)] coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)]
coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))] coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))]
coinbase.nLockTime = 0 coinbase.nLockTime = 0
assert coinbase.hash == "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20" assert coinbase.txid_hex == "f60c73405d499a956d3162e3483c395526ef78286458a4cb17b125aa92e49b20"
# Mine it # Mine it
block = create_block(hashprev=int(self.nodes[0].getbestblockhash(), 16), coinbase=coinbase) block = create_block(hashprev=int(self.nodes[0].getbestblockhash(), 16), coinbase=coinbase)
block.rehash() block.rehash()
+1 -1
View File
@@ -55,7 +55,7 @@ class UTXOSetHashTest(BitcoinTestFramework):
if (coinbase and n > 0): if (coinbase and n > 0):
continue continue
data = COutPoint(int(tx.rehash(), 16), n).serialize() data = COutPoint(int(tx.txid_hex, 16), n).serialize()
data += (height * 2 + coinbase).to_bytes(4, "little") data += (height * 2 + coinbase).to_bytes(4, "little")
data += tx_out.serialize() data += tx_out.serialize()
+1 -1
View File
@@ -323,7 +323,7 @@ class MempoolTracepointTest(BitcoinTestFramework):
self.log.info("Ensuring mempool:rejected event was handled successfully...") self.log.info("Ensuring mempool:rejected event was handled successfully...")
assert_equal(1, len(events)) assert_equal(1, len(events))
event = events[0] event = events[0]
assert_equal(bytes(event.hash)[::-1].hex(), tx["tx"].hash) assert_equal(bytes(event.hash)[::-1].hex(), tx["tx"].txid_hex)
assert_equal(event.reason.decode("UTF-8"), "min relay fee not met") assert_equal(event.reason.decode("UTF-8"), "min relay fee not met")
bpf.cleanup() bpf.cleanup()
+2 -2
View File
@@ -212,14 +212,14 @@ class ZMQTest (BitcoinTestFramework):
# Should receive the coinbase raw transaction. # Should receive the coinbase raw transaction.
tx = tx_from_hex(rawtx.receive().hex()) tx = tx_from_hex(rawtx.receive().hex())
assert_equal(tx.hash, txid.hex()) assert_equal(tx.txid_hex, txid.hex())
# Should receive the generated raw block. # Should receive the generated raw block.
hex = rawblock.receive() hex = rawblock.receive()
block = CBlock() block = CBlock()
block.deserialize(BytesIO(hex)) block.deserialize(BytesIO(hex))
assert block.is_valid() assert block.is_valid()
assert_equal(block.vtx[0].hash, tx.hash) assert_equal(block.vtx[0].txid_hex, tx.txid_hex)
assert_equal(len(block.vtx), 1) assert_equal(len(block.vtx), 1)
assert_equal(genhashes[x], hash256_reversed(hex[:80]).hex()) assert_equal(genhashes[x], hash256_reversed(hex[:80]).hex())
+34 -34
View File
@@ -123,7 +123,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = self.wallet.create_self_transfer(utxo_to_spend=utxo_to_spend, sequence=MAX_BIP125_RBF_SEQUENCE)['tx'] tx = self.wallet.create_self_transfer(utxo_to_spend=utxo_to_spend, sequence=MAX_BIP125_RBF_SEQUENCE)['tx']
tx.vout[0].nValue = int((Decimal('0.3') - fee) * COIN) tx.vout[0].nValue = int((Decimal('0.3') - fee) * COIN)
raw_tx_0 = tx.serialize().hex() raw_tx_0 = tx.serialize().hex()
txid_0 = tx.rehash() txid_0 = tx.txid_hex
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': fee}}], result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': fee}}],
rawtxs=[raw_tx_0], rawtxs=[raw_tx_0],
@@ -140,7 +140,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_final) tx = tx_from_hex(raw_tx_final)
fee_expected = Decimal('50.0') - output_amount fee_expected = Decimal('50.0') - output_amount
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': fee_expected}}], result_expected=[{'txid': tx.txid_hex, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': fee_expected}}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -159,7 +159,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_0) tx = tx_from_hex(raw_tx_0)
tx.vout[0].nValue -= int(fee * COIN) # Double the fee tx.vout[0].nValue -= int(fee * COIN) # Double the fee
raw_tx_0 = tx.serialize().hex() raw_tx_0 = tx.serialize().hex()
txid_0 = tx.rehash() txid_0 = tx.txid_hex
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': (2 * fee)}}], result_expected=[{'txid': txid_0, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': (2 * fee)}}],
rawtxs=[raw_tx_0], rawtxs=[raw_tx_0],
@@ -170,7 +170,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_0) tx = tx_from_hex(raw_tx_0)
tx.vin[0].prevout = COutPoint(hash=int('ff' * 32, 16), n=14) tx.vin[0].prevout = COutPoint(hash=int('ff' * 32, 16), n=14)
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'missing-inputs'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'missing-inputs'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -207,7 +207,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
raw_tx_reference = tx.serialize().hex() raw_tx_reference = tx.serialize().hex()
# Reference tx should be valid on itself # Reference tx should be valid on itself
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': { 'base': Decimal('0.1') - Decimal('0.05')}}], result_expected=[{'txid': tx.txid_hex, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': { 'base': Decimal('0.1') - Decimal('0.05')}}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -216,7 +216,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vout = [] tx.vout = []
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-empty'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-vout-empty'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -224,7 +224,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vin = [tx.vin[0]] * math.ceil((MAX_BLOCK_WEIGHT // WITNESS_SCALE_FACTOR) / len(tx.vin[0].serialize())) tx.vin = [tx.vin[0]] * math.ceil((MAX_BLOCK_WEIGHT // WITNESS_SCALE_FACTOR) / len(tx.vin[0].serialize()))
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-oversize'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-oversize'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -232,7 +232,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vout[0].nValue *= -1 tx.vout[0].nValue *= -1
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-negative'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-vout-negative'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -241,7 +241,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vout[0].nValue = MAX_MONEY + 1 tx.vout[0].nValue = MAX_MONEY + 1
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -250,7 +250,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx.vout = [tx.vout[0]] * 2 tx.vout = [tx.vout[0]] * 2
tx.vout[0].nValue = MAX_MONEY tx.vout[0].nValue = MAX_MONEY
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -258,7 +258,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vin = [tx.vin[0]] * 2 tx.vin = [tx.vin[0]] * 2
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-inputs-duplicate'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-inputs-duplicate'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -266,7 +266,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vin.append(CTxIn(COutPoint(hash=0, n=0xffffffff))) tx.vin.append(CTxIn(COutPoint(hash=0, n=0xffffffff)))
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-prevout-null'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bad-txns-prevout-null'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -276,7 +276,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
raw_tx_coinbase_spent = node.getrawtransaction(txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid']) raw_tx_coinbase_spent = node.getrawtransaction(txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid'])
tx = tx_from_hex(raw_tx_coinbase_spent) tx = tx_from_hex(raw_tx_coinbase_spent)
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'coinbase'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'coinbase'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -284,32 +284,32 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.version = 4 # A version currently non-standard tx.version = 4 # A version currently non-standard
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'version'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'version'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vout[0].scriptPubKey = CScript([OP_0]) # Some non-standard script tx.vout[0].scriptPubKey = CScript([OP_0]) # Some non-standard script
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptpubkey'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'scriptpubkey'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
_, pubkey = generate_keypair() _, pubkey = generate_keypair()
tx.vout[0].scriptPubKey = keys_to_multisig_script([pubkey] * 3, k=2) # Some bare multisig script (2-of-3) tx.vout[0].scriptPubKey = keys_to_multisig_script([pubkey] * 3, k=2) # Some bare multisig script (2-of-3)
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bare-multisig'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'bare-multisig'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vin[0].scriptSig = CScript([OP_HASH160]) # Some not-pushonly scriptSig tx.vin[0].scriptSig = CScript([OP_HASH160]) # Some not-pushonly scriptSig
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptsig-not-pushonly'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'scriptsig-not-pushonly'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vin[0].scriptSig = CScript([b'a' * 1648]) # Some too large scriptSig (>1650 bytes) tx.vin[0].scriptSig = CScript([b'a' * 1648]) # Some too large scriptSig (>1650 bytes)
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptsig-size'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'scriptsig-size'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
@@ -317,14 +317,14 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
num_scripts = 100000 // len(output_p2sh_burn.serialize()) # Use enough outputs to make the tx too large for our policy num_scripts = 100000 // len(output_p2sh_burn.serialize()) # Use enough outputs to make the tx too large for our policy
tx.vout = [output_p2sh_burn] * num_scripts tx.vout = [output_p2sh_burn] * num_scripts
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'tx-size'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'tx-size'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vout[0] = output_p2sh_burn tx.vout[0] = output_p2sh_burn
tx.vout[0].nValue -= 1 # Make output smaller, such that it is dust for our policy tx.vout[0].nValue -= 1 # Make output smaller, such that it is dust for our policy
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'dust'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'dust'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -332,7 +332,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vout[0].scriptPubKey = CScript([OP_RETURN, OP_HASH160]) tx.vout[0].scriptPubKey = CScript([OP_RETURN, OP_HASH160])
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptpubkey'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'scriptpubkey'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -343,7 +343,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx.vout.append(CTxOut(0, CScript([OP_RETURN, b'\xff' * 50000]))) tx.vout.append(CTxOut(0, CScript([OP_RETURN, b'\xff' * 50000])))
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal('0.05')}}], result_expected=[{'txid': tx.txid_hex, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': {'base': Decimal('0.05')}}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
maxfeerate=0 maxfeerate=0
) )
@@ -355,7 +355,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx.vout[0].scriptPubKey = CScript([OP_RETURN, b'\xff']) tx.vout[0].scriptPubKey = CScript([OP_RETURN, b'\xff'])
tx.vout = [tx.vout[0]] * op_return_count tx.vout = [tx.vout[0]] * op_return_count
self.check_mempool_result( self.check_mempool_result(
result_expected=[{"txid": tx.rehash(), "allowed": True, "vsize": tx.get_vsize(), "fees": {"base": Decimal("0.05000026")}}], result_expected=[{"txid": tx.txid_hex, "allowed": True, "vsize": tx.get_vsize(), "fees": {"base": Decimal("0.05000026")}}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -366,13 +366,13 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx.vout[0].scriptPubKey = CScript([OP_RETURN, b"\xff" * (data_len)]) tx.vout[0].scriptPubKey = CScript([OP_RETURN, b"\xff" * (data_len)])
assert_equal(tx.get_vsize(), int(MAX_STANDARD_TX_WEIGHT / 4)) assert_equal(tx.get_vsize(), int(MAX_STANDARD_TX_WEIGHT / 4))
self.check_mempool_result( self.check_mempool_result(
result_expected=[{"txid": tx.rehash(), "allowed": True, "vsize": tx.get_vsize(), "fees": {"base": Decimal("0.1") - Decimal("0.05")}}], result_expected=[{"txid": tx.txid_hex, "allowed": True, "vsize": tx.get_vsize(), "fees": {"base": Decimal("0.1") - Decimal("0.05")}}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
tx.vout[0].scriptPubKey = CScript([OP_RETURN, b"\xff" * (data_len + 1)]) tx.vout[0].scriptPubKey = CScript([OP_RETURN, b"\xff" * (data_len + 1)])
assert_greater_than(tx.get_vsize(), int(MAX_STANDARD_TX_WEIGHT / 4)) assert_greater_than(tx.get_vsize(), int(MAX_STANDARD_TX_WEIGHT / 4))
self.check_mempool_result( self.check_mempool_result(
result_expected=[{"txid": tx.rehash(), "allowed": False, "reject-reason": "tx-size"}], result_expected=[{"txid": tx.txid_hex, "allowed": False, "reject-reason": "tx-size"}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -381,7 +381,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx.vin[0].nSequence -= 1 # Should be non-max, so locktime is not ignored tx.vin[0].nSequence -= 1 # Should be non-max, so locktime is not ignored
tx.nLockTime = node.getblockcount() + 1 tx.nLockTime = node.getblockcount() + 1
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'non-final'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'non-final'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
) )
@@ -389,7 +389,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx = tx_from_hex(raw_tx_reference) tx = tx_from_hex(raw_tx_reference)
tx.vin[0].nSequence = 2 # We could include it in the second block mined from now, but not the very next one tx.vin[0].nSequence = 2 # We could include it in the second block mined from now, but not the very next one
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'non-BIP68-final'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'non-BIP68-final'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -410,7 +410,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
assert_greater_than(len(tx.serialize()), 64) assert_greater_than(len(tx.serialize()), 64)
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'tx-size-small'}], result_expected=[{'txid': tx.txid_hex, 'allowed': False, 'reject-reason': 'tx-size-small'}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -419,7 +419,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
tx.vout[0] = CTxOut(COIN - 1000, DUMMY_MIN_OP_RETURN_SCRIPT) tx.vout[0] = CTxOut(COIN - 1000, DUMMY_MIN_OP_RETURN_SCRIPT)
assert_equal(len(tx.serialize_without_witness()), MIN_STANDARD_TX_NONWITNESS_SIZE) assert_equal(len(tx.serialize_without_witness()), MIN_STANDARD_TX_NONWITNESS_SIZE)
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx.rehash(), 'allowed': True, 'vsize': tx.get_vsize(), 'fees': { 'base': Decimal('0.00001000')}}], result_expected=[{'txid': tx.txid_hex, 'allowed': True, 'vsize': tx.get_vsize(), 'fees': { 'base': Decimal('0.00001000')}}],
rawtxs=[tx.serialize().hex()], rawtxs=[tx.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -437,7 +437,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
anchor_nonempty_wit_spend.wit.vtxinwit[0].scriptWitness.stack.append(b"f") anchor_nonempty_wit_spend.wit.vtxinwit[0].scriptWitness.stack.append(b"f")
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': anchor_nonempty_wit_spend.rehash(), 'allowed': False, 'reject-reason': 'bad-witness-nonstandard'}], result_expected=[{'txid': anchor_nonempty_wit_spend.txid_hex, 'allowed': False, 'reject-reason': 'bad-witness-nonstandard'}],
rawtxs=[anchor_nonempty_wit_spend.serialize().hex()], rawtxs=[anchor_nonempty_wit_spend.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -454,10 +454,10 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
anchor_spend.vout.append(CTxOut(anchor_value - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE])))) anchor_spend.vout.append(CTxOut(anchor_value - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
anchor_spend.wit.vtxinwit.append(CTxInWitness()) anchor_spend.wit.vtxinwit.append(CTxInWitness())
# It's "segwit" but txid == wtxid since there is no witness data # It's "segwit" but txid == wtxid since there is no witness data
assert_equal(anchor_spend.rehash(), anchor_spend.getwtxid()) assert_equal(anchor_spend.txid_hex, anchor_spend.getwtxid())
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': anchor_spend.rehash(), 'allowed': True, 'vsize': anchor_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}], result_expected=[{'txid': anchor_spend.txid_hex, 'allowed': True, 'vsize': anchor_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}],
rawtxs=[anchor_spend.serialize().hex()], rawtxs=[anchor_spend.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -473,7 +473,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
nested_anchor_spend.vout.append(CTxOut(nested_anchor_tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE])))) nested_anchor_spend.vout.append(CTxOut(nested_anchor_tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': nested_anchor_spend.rehash(), 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Witness version reserved for soft-fork upgrades)'}], result_expected=[{'txid': nested_anchor_spend.txid_hex, 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Witness version reserved for soft-fork upgrades)'}],
rawtxs=[nested_anchor_spend.serialize().hex()], rawtxs=[nested_anchor_spend.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
@@ -492,7 +492,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework):
sign_input_legacy(tx_spend, 0, tx.vout[0].scriptPubKey, privkey, sighash_type=SIGHASH_ALL) sign_input_legacy(tx_spend, 0, tx.vout[0].scriptPubKey, privkey, sighash_type=SIGHASH_ALL)
tx_spend.vin[0].scriptSig = bytes(CScript([OP_0])) + tx_spend.vin[0].scriptSig tx_spend.vin[0].scriptSig = bytes(CScript([OP_0])) + tx_spend.vin[0].scriptSig
self.check_mempool_result( self.check_mempool_result(
result_expected=[{'txid': tx_spend.rehash(), 'allowed': True, 'vsize': tx_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}], result_expected=[{'txid': tx_spend.txid_hex, 'allowed': True, 'vsize': tx_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}],
rawtxs=[tx_spend.serialize().hex()], rawtxs=[tx_spend.serialize().hex()],
maxfeerate=0, maxfeerate=0,
) )
+2 -2
View File
@@ -77,13 +77,13 @@ class MempoolWtxidTest(BitcoinTestFramework):
child_one.wit.vtxinwit.append(CTxInWitness()) child_one.wit.vtxinwit.append(CTxInWitness())
child_one.wit.vtxinwit[0].scriptWitness.stack = [b'Preimage', b'\x01', witness_script] child_one.wit.vtxinwit[0].scriptWitness.stack = [b'Preimage', b'\x01', witness_script]
child_one_wtxid = child_one.getwtxid() child_one_wtxid = child_one.getwtxid()
child_one_txid = child_one.rehash() child_one_txid = child_one.txid_hex
# Create another identical transaction with witness solving second branch # Create another identical transaction with witness solving second branch
child_two = deepcopy(child_one) child_two = deepcopy(child_one)
child_two.wit.vtxinwit[0].scriptWitness.stack = [b'', witness_script] child_two.wit.vtxinwit[0].scriptWitness.stack = [b'', witness_script]
child_two_wtxid = child_two.getwtxid() child_two_wtxid = child_two.getwtxid()
child_two_txid = child_two.rehash() child_two_txid = child_two.txid_hex
assert_equal(child_one_txid, child_two_txid) assert_equal(child_one_txid, child_two_txid)
assert_not_equal(child_one_wtxid, child_two_wtxid) assert_not_equal(child_one_wtxid, child_two_wtxid)
+1 -1
View File
@@ -41,7 +41,7 @@ class DataCarrierTest(BitcoinTestFramework):
if success: if success:
self.wallet.sendrawtransaction(from_node=node, tx_hex=tx_hex) self.wallet.sendrawtransaction(from_node=node, tx_hex=tx_hex)
assert tx.rehash() in node.getrawmempool(True), f'{tx_hex} not in mempool' assert tx.txid_hex in node.getrawmempool(True), f'{tx_hex} not in mempool'
else: else:
assert_raises_rpc_error(-26, "datacarrier", self.wallet.sendrawtransaction, from_node=node, tx_hex=tx_hex) assert_raises_rpc_error(-26, "datacarrier", self.wallet.sendrawtransaction, from_node=node, tx_hex=tx_hex)
+1 -1
View File
@@ -38,7 +38,7 @@ class EphemeralDustTest(BitcoinTestFramework):
# Take value from first output # Take value from first output
result["tx"].vout[0].nValue -= output_value result["tx"].vout[0].nValue -= output_value
result["new_utxos"][0]["value"] = Decimal(result["tx"].vout[0].nValue) / COIN result["new_utxos"][0]["value"] = Decimal(result["tx"].vout[0].nValue) / COIN
new_txid = result["tx"].rehash() new_txid = result["tx"].txid_hex
result["txid"] = new_txid result["txid"] = new_txid
result["wtxid"] = result["tx"].getwtxid() result["wtxid"] = result["tx"].getwtxid()
result["hex"] = result["tx"].serialize().hex() result["hex"] = result["tx"].serialize().hex()
+15 -15
View File
@@ -114,7 +114,7 @@ class PackageRBFTest(BitcoinTestFramework):
# But accepted during normal submission # But accepted during normal submission
submitres = node.submitpackage(package_hex2) submitres = node.submitpackage(package_hex2)
assert_equal(set(submitres["replaced-transactions"]), set([tx.rehash() for tx in package_txns1])) assert_equal(set(submitres["replaced-transactions"]), set([tx.txid_hex for tx in package_txns1]))
self.assert_mempool_contents(expected=package_txns2) self.assert_mempool_contents(expected=package_txns2)
# Make sure 2nd node gets a basic package RBF over p2p # Make sure 2nd node gets a basic package RBF over p2p
@@ -135,7 +135,7 @@ class PackageRBFTest(BitcoinTestFramework):
package_hex, package_txns = self.create_simple_package(singleton_coin, DEFAULT_FEE, singleton_tx["fee"] * 2) package_hex, package_txns = self.create_simple_package(singleton_coin, DEFAULT_FEE, singleton_tx["fee"] * 2)
submitres = node.submitpackage(package_hex) submitres = node.submitpackage(package_hex)
assert_equal(submitres["replaced-transactions"], [singleton_tx["tx"].rehash()]) assert_equal(submitres["replaced-transactions"], [singleton_tx["tx"].txid_hex])
self.assert_mempool_contents(expected=package_txns) self.assert_mempool_contents(expected=package_txns)
self.generate(node, 1) self.generate(node, 1)
@@ -156,7 +156,7 @@ class PackageRBFTest(BitcoinTestFramework):
# Package 2 has a higher feerate but lower absolute fee # Package 2 has a higher feerate but lower absolute fee
package_hex2, package_txns2 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE - Decimal("0.00000001")) package_hex2, package_txns2 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE - Decimal("0.00000001"))
pkg_results2 = node.submitpackage(package_hex2) pkg_results2 = node.submitpackage(package_hex2)
assert_equal(f"package RBF failed: insufficient anti-DoS fees, rejecting replacement {package_txns2[1].rehash()}, less fees than conflicting txs; {PACKAGE_FEE_MINUS_ONE} < {PACKAGE_FEE}", pkg_results2["package_msg"]) assert_equal(f"package RBF failed: insufficient anti-DoS fees, rejecting replacement {package_txns2[1].txid_hex}, less fees than conflicting txs; {PACKAGE_FEE_MINUS_ONE} < {PACKAGE_FEE}", pkg_results2["package_msg"])
self.assert_mempool_contents(expected=package_txns1) self.assert_mempool_contents(expected=package_txns1)
self.log.info("Check replacement pays for incremental bandwidth") self.log.info("Check replacement pays for incremental bandwidth")
@@ -168,7 +168,7 @@ class PackageRBFTest(BitcoinTestFramework):
failure_package_hex3, failure_package_txns3 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE + incremental_sats_short) failure_package_hex3, failure_package_txns3 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE + incremental_sats_short)
assert_equal(package_3_size, sum([tx.get_vsize() for tx in failure_package_txns3])) assert_equal(package_3_size, sum([tx.get_vsize() for tx in failure_package_txns3]))
pkg_results3 = node.submitpackage(failure_package_hex3) pkg_results3 = node.submitpackage(failure_package_hex3)
assert_equal(f"package RBF failed: insufficient anti-DoS fees, rejecting replacement {failure_package_txns3[1].rehash()}, not enough additional fees to relay; {incremental_sats_short} < {incremental_sats_required}", pkg_results3["package_msg"]) assert_equal(f"package RBF failed: insufficient anti-DoS fees, rejecting replacement {failure_package_txns3[1].txid_hex}, not enough additional fees to relay; {incremental_sats_short} < {incremental_sats_required}", pkg_results3["package_msg"])
self.assert_mempool_contents(expected=package_txns1) self.assert_mempool_contents(expected=package_txns1)
success_package_hex3, success_package_txns3 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE + incremental_sats_required) success_package_hex3, success_package_txns3 = self.create_simple_package(coin, parent_fee=DEFAULT_FEE, child_fee=DEFAULT_CHILD_FEE + incremental_sats_required)
@@ -218,7 +218,7 @@ class PackageRBFTest(BitcoinTestFramework):
package_child = self.wallet.create_self_transfer(fee_rate=child_feerate, utxo_to_spend=package_parent["new_utxos"][0]) package_child = self.wallet.create_self_transfer(fee_rate=child_feerate, utxo_to_spend=package_parent["new_utxos"][0])
pkg_results = node.submitpackage([package_parent["hex"], package_child["hex"]], maxfeerate=0) pkg_results = node.submitpackage([package_parent["hex"], package_child["hex"]], maxfeerate=0)
assert_equal(f"package RBF failed: too many potential replacements, rejecting replacement {package_child['tx'].rehash()}; too many potential replacements (102 > 100)", pkg_results["package_msg"]) assert_equal(f"package RBF failed: too many potential replacements, rejecting replacement {package_child['tx'].txid_hex}; too many potential replacements (102 > 100)", pkg_results["package_msg"])
self.assert_mempool_contents(expected=expected_txns) self.assert_mempool_contents(expected=expected_txns)
# Make singleton tx to conflict with in next batch # Make singleton tx to conflict with in next batch
@@ -233,7 +233,7 @@ class PackageRBFTest(BitcoinTestFramework):
package_parent = self.wallet.create_self_transfer_multi(utxos_to_spend=double_spending_coins, fee_per_output=parent_fee_per_conflict) package_parent = self.wallet.create_self_transfer_multi(utxos_to_spend=double_spending_coins, fee_per_output=parent_fee_per_conflict)
package_child = self.wallet.create_self_transfer(fee_rate=child_feerate, utxo_to_spend=package_parent["new_utxos"][0]) package_child = self.wallet.create_self_transfer(fee_rate=child_feerate, utxo_to_spend=package_parent["new_utxos"][0])
pkg_results = node.submitpackage([package_parent["hex"], package_child["hex"]], maxfeerate=0) pkg_results = node.submitpackage([package_parent["hex"], package_child["hex"]], maxfeerate=0)
assert_equal(f"package RBF failed: too many potential replacements, rejecting replacement {package_child['tx'].rehash()}; too many potential replacements (101 > 100)", pkg_results["package_msg"]) assert_equal(f"package RBF failed: too many potential replacements, rejecting replacement {package_child['tx'].txid_hex}; too many potential replacements (101 > 100)", pkg_results["package_msg"])
self.assert_mempool_contents(expected=expected_txns) self.assert_mempool_contents(expected=expected_txns)
# Finally, evict MAX_REPLACEMENT_CANDIDATES # Finally, evict MAX_REPLACEMENT_CANDIDATES
@@ -331,15 +331,15 @@ class PackageRBFTest(BitcoinTestFramework):
package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex1) package_result = node.submitpackage(package_hex1)
assert_equal(f"package RBF failed: {parent_result['tx'].rehash()} has 2 descendants, max 1 allowed", package_result["package_msg"]) assert_equal(f"package RBF failed: {parent_result['tx'].txid_hex} has 2 descendants, max 1 allowed", package_result["package_msg"])
package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex2) package_result = node.submitpackage(package_hex2)
assert_equal(f"package RBF failed: {child_result['tx'].rehash()} has both ancestor and descendant, exceeding cluster limit of 2", package_result["package_msg"]) assert_equal(f"package RBF failed: {child_result['tx'].txid_hex} has both ancestor and descendant, exceeding cluster limit of 2", package_result["package_msg"])
package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex3) package_result = node.submitpackage(package_hex3)
assert_equal(f"package RBF failed: {grandchild_result['tx'].rehash()} has 2 ancestors, max 1 allowed", package_result["package_msg"]) assert_equal(f"package RBF failed: {grandchild_result['tx'].txid_hex} has 2 ancestors, max 1 allowed", package_result["package_msg"])
# Check that replacements were actually rejected # Check that replacements were actually rejected
self.assert_mempool_contents(expected=expected_txns) self.assert_mempool_contents(expected=expected_txns)
@@ -383,15 +383,15 @@ class PackageRBFTest(BitcoinTestFramework):
# Now make conflicting packages for each coin # Now make conflicting packages for each coin
package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex1) package_result = node.submitpackage(package_hex1)
assert_equal(f"package RBF failed: {parent1_result['tx'].rehash()} is not the only parent of child {child_result['tx'].rehash()}", package_result["package_msg"]) assert_equal(f"package RBF failed: {parent1_result['tx'].txid_hex} is not the only parent of child {child_result['tx'].txid_hex}", package_result["package_msg"])
package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex2) package_result = node.submitpackage(package_hex2)
assert_equal(f"package RBF failed: {child_result['tx'].rehash()} has 2 ancestors, max 1 allowed", package_result["package_msg"]) assert_equal(f"package RBF failed: {child_result['tx'].txid_hex} has 2 ancestors, max 1 allowed", package_result["package_msg"])
package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex3) package_result = node.submitpackage(package_hex3)
assert_equal(f"package RBF failed: {child_result['tx'].rehash()} has 2 ancestors, max 1 allowed", package_result["package_msg"]) assert_equal(f"package RBF failed: {child_result['tx'].txid_hex} has 2 ancestors, max 1 allowed", package_result["package_msg"])
# Check that replacements were actually rejected # Check that replacements were actually rejected
self.assert_mempool_contents(expected=expected_txns) self.assert_mempool_contents(expected=expected_txns)
@@ -437,15 +437,15 @@ class PackageRBFTest(BitcoinTestFramework):
# Now make conflicting packages for each coin # Now make conflicting packages for each coin
package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex1, _package_txns1 = self.create_simple_package(coin1, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex1) package_result = node.submitpackage(package_hex1)
assert_equal(f"package RBF failed: {child1_result['tx'].rehash()} is not the only child of parent {parent_result['tx'].rehash()}", package_result["package_msg"]) assert_equal(f"package RBF failed: {child1_result['tx'].txid_hex} is not the only child of parent {parent_result['tx'].txid_hex}", package_result["package_msg"])
package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex2, _package_txns2 = self.create_simple_package(coin2, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex2) package_result = node.submitpackage(package_hex2)
assert_equal(f"package RBF failed: {child1_result['tx'].rehash()} is not the only child of parent {parent_result['tx'].rehash()}", package_result["package_msg"]) assert_equal(f"package RBF failed: {child1_result['tx'].txid_hex} is not the only child of parent {parent_result['tx'].txid_hex}", package_result["package_msg"])
package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE) package_hex3, _package_txns3 = self.create_simple_package(coin3, DEFAULT_FEE, DEFAULT_CHILD_FEE)
package_result = node.submitpackage(package_hex3) package_result = node.submitpackage(package_hex3)
assert_equal(f"package RBF failed: {child2_result['tx'].rehash()} is not the only child of parent {parent_result['tx'].rehash()}", package_result["package_msg"]) assert_equal(f"package RBF failed: {child2_result['tx'].txid_hex} is not the only child of parent {parent_result['tx'].txid_hex}", package_result["package_msg"])
# Check that replacements were actually rejected # Check that replacements were actually rejected
self.assert_mempool_contents(expected=expected_txns) self.assert_mempool_contents(expected=expected_txns)
+4 -4
View File
@@ -121,13 +121,13 @@ class BytesPerSigOpTest(BitcoinTestFramework):
parent_txid = tx.vin[0].prevout.hash.to_bytes(32, 'big').hex() parent_txid = tx.vin[0].prevout.hash.to_bytes(32, 'big').hex()
parent_tx = tx_from_hex(self.nodes[0].getrawtransaction(txid=parent_txid)) parent_tx = tx_from_hex(self.nodes[0].getrawtransaction(txid=parent_txid))
entry_child = self.nodes[0].getmempoolentry(tx.rehash()) entry_child = self.nodes[0].getmempoolentry(tx.txid_hex)
assert_equal(entry_child['descendantcount'], 1) assert_equal(entry_child['descendantcount'], 1)
assert_equal(entry_child['descendantsize'], sigop_equivalent_vsize) assert_equal(entry_child['descendantsize'], sigop_equivalent_vsize)
assert_equal(entry_child['ancestorcount'], 2) assert_equal(entry_child['ancestorcount'], 2)
assert_equal(entry_child['ancestorsize'], sigop_equivalent_vsize + parent_tx.get_vsize()) assert_equal(entry_child['ancestorsize'], sigop_equivalent_vsize + parent_tx.get_vsize())
entry_parent = self.nodes[0].getmempoolentry(parent_tx.rehash()) entry_parent = self.nodes[0].getmempoolentry(parent_tx.txid_hex)
assert_equal(entry_parent['ancestorcount'], 1) assert_equal(entry_parent['ancestorcount'], 1)
assert_equal(entry_parent['ancestorsize'], parent_tx.get_vsize()) assert_equal(entry_parent['ancestorsize'], parent_tx.get_vsize())
assert_equal(entry_parent['descendantcount'], 2) assert_equal(entry_parent['descendantcount'], 2)
@@ -147,7 +147,7 @@ class BytesPerSigOpTest(BitcoinTestFramework):
tx = tx_dict["tx"] tx = tx_dict["tx"]
tx.vout.append(CTxOut(amount_for_bare, keys_to_multisig_script([pubkey], k=1))) tx.vout.append(CTxOut(amount_for_bare, keys_to_multisig_script([pubkey], k=1)))
tx.vout[0].nValue -= amount_for_bare tx.vout[0].nValue -= amount_for_bare
tx_utxo["txid"] = tx.rehash() tx_utxo["txid"] = tx.txid_hex
tx_utxo["value"] -= Decimal("0.00005000") tx_utxo["value"] -= Decimal("0.00005000")
return (tx_utxo, tx) return (tx_utxo, tx)
@@ -169,7 +169,7 @@ class BytesPerSigOpTest(BitcoinTestFramework):
# When we actually try to submit, the parent makes it into the mempool, but the child would exceed ancestor vsize limits # When we actually try to submit, the parent makes it into the mempool, but the child would exceed ancestor vsize limits
res = self.nodes[0].submitpackage([tx_parent.serialize().hex(), tx_child.serialize().hex()]) res = self.nodes[0].submitpackage([tx_parent.serialize().hex(), tx_child.serialize().hex()])
assert "too-long-mempool-chain" in res["tx-results"][tx_child.getwtxid()]["error"] assert "too-long-mempool-chain" in res["tx-results"][tx_child.getwtxid()]["error"]
assert tx_parent.rehash() in self.nodes[0].getrawmempool() assert tx_parent.txid_hex in self.nodes[0].getrawmempool()
# Transactions are tiny in weight # Transactions are tiny in weight
assert_greater_than(2000, tx_parent.get_weight() + tx_child.get_weight()) assert_greater_than(2000, tx_parent.get_weight() + tx_child.get_weight())
+6 -6
View File
@@ -346,7 +346,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# Check that all prefilled_txn entries match what's in the block. # Check that all prefilled_txn entries match what's in the block.
for entry in header_and_shortids.prefilled_txn: for entry in header_and_shortids.prefilled_txn:
# This checks the non-witness parts of the tx agree # This checks the non-witness parts of the tx agree
assert_equal(entry.tx.rehash(), block.vtx[entry.index].rehash()) assert_equal(entry.tx.txid_hex, block.vtx[entry.index].txid_hex)
# And this checks the witness # And this checks the witness
assert_equal(entry.tx.getwtxid(), block.vtx[entry.index].getwtxid()) assert_equal(entry.tx.getwtxid(), block.vtx[entry.index].getwtxid())
@@ -476,7 +476,7 @@ class CompactBlocksTest(BitcoinTestFramework):
block = self.build_block_with_transactions(node, utxo, 5) block = self.build_block_with_transactions(node, utxo, 5)
self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue]) self.utxos.append([block.vtx[-1].sha256, 0, block.vtx[-1].vout[0].nValue])
test_node.send_and_ping(msg_tx(block.vtx[1])) test_node.send_and_ping(msg_tx(block.vtx[1]))
assert block.vtx[1].hash in node.getrawmempool() assert block.vtx[1].txid_hex in node.getrawmempool()
# Prefill 4 out of the 6 transactions, and verify that only the one # Prefill 4 out of the 6 transactions, and verify that only the one
# that was not in the mempool is requested. # that was not in the mempool is requested.
@@ -497,7 +497,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# Make sure all transactions were accepted. # Make sure all transactions were accepted.
mempool = node.getrawmempool() mempool = node.getrawmempool()
for tx in block.vtx[1:]: for tx in block.vtx[1:]:
assert tx.hash in mempool assert tx.txid_hex in mempool
# Clear out last request. # Clear out last request.
with p2p_lock: with p2p_lock:
@@ -525,7 +525,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# Make sure all transactions were accepted. # Make sure all transactions were accepted.
mempool = node.getrawmempool() mempool = node.getrawmempool()
for tx in block.vtx[1:6]: for tx in block.vtx[1:6]:
assert tx.hash in mempool assert tx.txid_hex in mempool
# Send compact block # Send compact block
comp_block = HeaderAndShortIDs() comp_block = HeaderAndShortIDs()
@@ -584,7 +584,7 @@ class CompactBlocksTest(BitcoinTestFramework):
all_indices = msg.block_txn_request.to_absolute() all_indices = msg.block_txn_request.to_absolute()
for index in all_indices: for index in all_indices:
tx = test_node.last_message["blocktxn"].block_transactions.transactions.pop(0) tx = test_node.last_message["blocktxn"].block_transactions.transactions.pop(0)
assert_equal(tx.rehash(), block.vtx[index].rehash()) assert_equal(tx.txid_hex, block.vtx[index].txid_hex)
# Check that the witness matches # Check that the witness matches
assert_equal(tx.getwtxid(), block.vtx[index].getwtxid()) assert_equal(tx.getwtxid(), block.vtx[index].getwtxid())
test_node.last_message.pop("blocktxn", None) test_node.last_message.pop("blocktxn", None)
@@ -765,7 +765,7 @@ class CompactBlocksTest(BitcoinTestFramework):
delivery_peer.sync_with_ping() delivery_peer.sync_with_ping()
mempool = node.getrawmempool() mempool = node.getrawmempool()
for tx in block.vtx[1:]: for tx in block.vtx[1:]:
assert tx.hash in mempool assert tx.txid_hex in mempool
delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p())) delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
assert_equal(int(node.getbestblockhash(), 16), block.sha256) assert_equal(int(node.getbestblockhash(), 16), block.sha256)
+2 -2
View File
@@ -129,7 +129,7 @@ class InvalidTxRequestTest(BitcoinTestFramework):
# Transactions that should end up in the mempool # Transactions that should end up in the mempool
expected_mempool = { expected_mempool = {
t.hash t.txid_hex
for t in [ for t in [
tx_withhold, # The transaction that is the root for all orphans tx_withhold, # The transaction that is the root for all orphans
tx_orphan_1, # The orphan transaction that splits the coins tx_orphan_1, # The orphan transaction that splits the coins
@@ -156,7 +156,7 @@ class InvalidTxRequestTest(BitcoinTestFramework):
rejected_parent = CTransaction() rejected_parent = CTransaction()
rejected_parent.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_2_invalid.sha256, 0))) rejected_parent.vin.append(CTxIn(outpoint=COutPoint(tx_orphan_2_invalid.sha256, 0)))
rejected_parent.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE)) rejected_parent.vout.append(CTxOut(nValue=11 * COIN, scriptPubKey=SCRIPT_PUB_KEY_OP_TRUE))
with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(rejected_parent.hash)]): with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(rejected_parent.txid_hex)]):
node.p2ps[0].send_txs_and_test([rejected_parent], node, success=False) node.p2ps[0].send_txs_and_test([rejected_parent], node, success=False)
self.log.info('Test that a peer disconnection causes erase its transactions from the orphan pool') self.log.info('Test that a peer disconnection causes erase its transactions from the orphan pool')
+3 -3
View File
@@ -245,7 +245,7 @@ class PackageRelayTest(BitcoinTestFramework):
# 4. Transactions should not be in mempool. # 4. Transactions should not be in mempool.
node_mempool = node.getrawmempool() node_mempool = node.getrawmempool()
assert low_fee_parent["txid"] not in node_mempool assert low_fee_parent["txid"] not in node_mempool
assert tx_orphan_bad_wit.rehash() not in node_mempool assert tx_orphan_bad_wit.txid_hex not in node_mempool
# 5. Have the other peer send the tx too, so that tx_orphan_bad_wit package is attempted. # 5. Have the other peer send the tx too, so that tx_orphan_bad_wit package is attempted.
bad_orphan_sender.send_without_ping(msg_tx(low_fee_parent["tx"])) bad_orphan_sender.send_without_ping(msg_tx(low_fee_parent["tx"]))
@@ -276,7 +276,7 @@ class PackageRelayTest(BitcoinTestFramework):
package_sender.send_and_ping(msg_tx(high_fee_child["tx"])) package_sender.send_and_ping(msg_tx(high_fee_child["tx"]))
# 2. Node requests the missing parent by txid. # 2. Node requests the missing parent by txid.
parent_txid_int = int(tx_parent_bad_wit.rehash(), 16) parent_txid_int = int(tx_parent_bad_wit.txid_hex, 16)
package_sender.wait_for_getdata([parent_txid_int]) package_sender.wait_for_getdata([parent_txid_int])
# 3. A different node relays the parent. The parent is first evaluated by itself and # 3. A different node relays the parent. The parent is first evaluated by itself and
@@ -286,7 +286,7 @@ class PackageRelayTest(BitcoinTestFramework):
# 4. Transactions should not be in mempool. # 4. Transactions should not be in mempool.
node_mempool = node.getrawmempool() node_mempool = node.getrawmempool()
assert tx_parent_bad_wit.rehash() not in node_mempool assert tx_parent_bad_wit.txid_hex not in node_mempool
assert high_fee_child["txid"] not in node_mempool assert high_fee_child["txid"] not in node_mempool
self.log.info("Check that fake parent does not cause orphan to be deleted and real package can still be submitted") self.log.info("Check that fake parent does not cause orphan to be deleted and real package can still be submitted")
+11 -11
View File
@@ -149,7 +149,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
# classify it as a transaction in which the witness was missing rather than wrong. # classify it as a transaction in which the witness was missing rather than wrong.
tx_bad_wit.wit.vtxinwit[0].scriptWitness.stack = [b'garbage'] tx_bad_wit.wit.vtxinwit[0].scriptWitness.stack = [b'garbage']
assert_equal(tx["txid"], tx_bad_wit.rehash()) assert_equal(tx["txid"], tx_bad_wit.txid_hex)
assert_not_equal(tx["wtxid"], tx_bad_wit.getwtxid()) assert_not_equal(tx["wtxid"], tx_bad_wit.getwtxid())
return tx_bad_wit return tx_bad_wit
@@ -242,7 +242,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
# The parent should be requested because even though the txid commits to the fee, it doesn't # The parent should be requested because even though the txid commits to the fee, it doesn't
# commit to the feerate. Delayed because it's by txid and this is not a preferred relay peer. # commit to the feerate. Delayed because it's by txid and this is not a preferred relay peer.
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY) self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
peer2.wait_for_getdata([int(parent_low_fee["tx"].rehash(), 16)]) peer2.wait_for_getdata([int(parent_low_fee["tx"].txid_hex, 16)])
self.log.info("Test orphan handling when a parent was previously downloaded with witness stripped") self.log.info("Test orphan handling when a parent was previously downloaded with witness stripped")
parent_normal = self.wallet.create_self_transfer() parent_normal = self.wallet.create_self_transfer()
@@ -251,8 +251,8 @@ class OrphanHandlingTest(BitcoinTestFramework):
# Relay the parent with witness stripped. It should not be accepted. # Relay the parent with witness stripped. It should not be accepted.
self.relay_transaction(peer1, parent1_witness_stripped) self.relay_transaction(peer1, parent1_witness_stripped)
assert_equal(parent_normal["txid"], parent1_witness_stripped.rehash()) assert_equal(parent_normal["txid"], parent1_witness_stripped.txid_hex)
assert parent1_witness_stripped.rehash() not in node.getrawmempool() assert parent1_witness_stripped.txid_hex not in node.getrawmempool()
# Relay the child. It should not be accepted because it has missing inputs. # Relay the child. It should not be accepted because it has missing inputs.
self.relay_transaction(peer2, child_invalid_witness["tx"]) self.relay_transaction(peer2, child_invalid_witness["tx"])
@@ -262,7 +262,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
# The parent should be requested since the unstripped wtxid would differ. Delayed because # The parent should be requested since the unstripped wtxid would differ. Delayed because
# it's by txid and this is not a preferred relay peer. # it's by txid and this is not a preferred relay peer.
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY) self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
peer2.wait_for_getdata([int(parent_normal["tx"].rehash(), 16)]) peer2.wait_for_getdata([int(parent_normal["tx"].txid_hex, 16)])
# parent_normal can be relayed again even though parent1_witness_stripped was rejected # parent_normal can be relayed again even though parent1_witness_stripped was rejected
self.relay_transaction(peer1, parent_normal["tx"]) self.relay_transaction(peer1, parent_normal["tx"])
@@ -661,15 +661,15 @@ class OrphanHandlingTest(BitcoinTestFramework):
# The outbound peer should be preferred for getting orphan parents # The outbound peer should be preferred for getting orphan parents
self.nodes[0].bumpmocktime(TXID_RELAY_DELAY) self.nodes[0].bumpmocktime(TXID_RELAY_DELAY)
peer_outbound.wait_for_parent_requests([int(parent_tx.rehash(), 16)]) peer_outbound.wait_for_parent_requests([int(parent_tx.txid_hex, 16)])
# There should be no request to the inbound peer # There should be no request to the inbound peer
peer_inbound.assert_never_requested(int(parent_tx.rehash(), 16)) peer_inbound.assert_never_requested(int(parent_tx.txid_hex, 16))
self.log.info("Test that, if the preferred peer doesn't respond, the node sends another request") self.log.info("Test that, if the preferred peer doesn't respond, the node sends another request")
self.nodes[0].bumpmocktime(GETDATA_TX_INTERVAL) self.nodes[0].bumpmocktime(GETDATA_TX_INTERVAL)
peer_inbound.sync_with_ping() peer_inbound.sync_with_ping()
peer_inbound.wait_for_parent_requests([int(parent_tx.rehash(), 16)]) peer_inbound.wait_for_parent_requests([int(parent_tx.txid_hex, 16)])
@cleanup @cleanup
def test_announcers_before_and_after(self): def test_announcers_before_and_after(self):
@@ -701,7 +701,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
# Peer disconnects before responding to request # Peer disconnects before responding to request
self.nodes[0].bumpmocktime(TXID_RELAY_DELAY) self.nodes[0].bumpmocktime(TXID_RELAY_DELAY)
peer_early_disconnected.wait_for_parent_requests([int(parent_tx.rehash(), 16)]) peer_early_disconnected.wait_for_parent_requests([int(parent_tx.txid_hex, 16)])
peer_early_disconnected.peer_disconnect() peer_early_disconnected.peer_disconnect()
# The orphan should have 1 announcer left after the node finishes disconnecting peer_early_disconnected. # The orphan should have 1 announcer left after the node finishes disconnecting peer_early_disconnected.
@@ -710,7 +710,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
# The node should retry with the other peer that announced the orphan earlier. # The node should retry with the other peer that announced the orphan earlier.
# This node's request was additionally delayed because it's an inbound peer. # This node's request was additionally delayed because it's an inbound peer.
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY) self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY)
peer_early_unresponsive.wait_for_parent_requests([int(parent_tx.rehash(), 16)]) peer_early_unresponsive.wait_for_parent_requests([int(parent_tx.txid_hex, 16)])
self.log.info("Test that the node uses peers who announce the tx after realizing it's an orphan") self.log.info("Test that the node uses peers who announce the tx after realizing it's an orphan")
peer_late_announcer.send_and_ping(msg_inv([orphan_inv])) peer_late_announcer.send_and_ping(msg_inv([orphan_inv]))
@@ -721,7 +721,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
assert_equal(len(orphanage[0]["from"]), 2) assert_equal(len(orphanage[0]["from"]), 2)
self.nodes[0].bumpmocktime(GETDATA_TX_INTERVAL) self.nodes[0].bumpmocktime(GETDATA_TX_INTERVAL)
peer_late_announcer.wait_for_parent_requests([int(parent_tx.rehash(), 16)]) peer_late_announcer.wait_for_parent_requests([int(parent_tx.txid_hex, 16)])
@cleanup @cleanup
def test_parents_change(self): def test_parents_change(self):
+2 -2
View File
@@ -111,7 +111,7 @@ class P2PPermissionsTests(BitcoinTestFramework):
self.log.debug("Send a tx from the wallet initially") self.log.debug("Send a tx from the wallet initially")
tx = self.wallet.create_self_transfer(sequence=SEQUENCE_FINAL)['tx'] tx = self.wallet.create_self_transfer(sequence=SEQUENCE_FINAL)['tx']
txid = tx.rehash() txid = tx.txid_hex
self.log.debug("Wait until tx is in node[1]'s mempool") self.log.debug("Wait until tx is in node[1]'s mempool")
p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1]) p2p_rebroadcast_wallet.send_txs_and_test([tx], self.nodes[1])
@@ -127,7 +127,7 @@ class P2PPermissionsTests(BitcoinTestFramework):
# add dust to cause policy rejection but no disconnection # add dust to cause policy rejection but no disconnection
tx.vout.append(tx.vout[0]) tx.vout.append(tx.vout[0])
tx.vout[-1].nValue = 0 tx.vout[-1].nValue = 0
txid = tx.rehash() txid = tx.txid_hex
# Send the transaction twice. The first time, it'll be rejected by ATMP because it conflicts # Send the transaction twice. The first time, it'll be rejected by ATMP because it conflicts
# with a mempool transaction. The second time, it'll be in the m_lazy_recent_rejects filter. # with a mempool transaction. The second time, it'll be in the m_lazy_recent_rejects filter.
p2p_rebroadcast_wallet.send_txs_and_test( p2p_rebroadcast_wallet.send_txs_and_test(
+9 -9
View File
@@ -132,7 +132,7 @@ def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=No
reason = [reason] if reason else [] reason = [reason] if reason else []
with node.assert_debug_log(expected_msgs=reason): with node.assert_debug_log(expected_msgs=reason):
p2p.send_and_ping(msg_tx(tx) if with_witness else msg_no_witness_tx(tx)) p2p.send_and_ping(msg_tx(tx) if with_witness else msg_no_witness_tx(tx))
assert_equal(tx.hash in node.getrawmempool(), accepted) assert_equal(tx.txid_hex in node.getrawmempool(), accepted)
def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=None): def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=None):
@@ -319,7 +319,7 @@ class SegWitTest(BitcoinTestFramework):
assert_equal(msg_no_witness_tx(tx).serialize(), msg_tx(tx).serialize()) assert_equal(msg_no_witness_tx(tx).serialize(), msg_tx(tx).serialize())
self.test_node.send_and_ping(msg_tx(tx)) # make sure the block was processed self.test_node.send_and_ping(msg_tx(tx)) # make sure the block was processed
assert tx.hash in self.nodes[0].getrawmempool() assert tx.txid_hex in self.nodes[0].getrawmempool()
# Save this transaction for later # Save this transaction for later
self.utxo.append(UTXO(tx.sha256, 0, 49 * 100000000)) self.utxo.append(UTXO(tx.sha256, 0, 49 * 100000000))
self.generate(self.nodes[0], 1) self.generate(self.nodes[0], 1)
@@ -336,7 +336,7 @@ class SegWitTest(BitcoinTestFramework):
# Verify the hash with witness differs from the txid # Verify the hash with witness differs from the txid
# (otherwise our testing framework must be broken!) # (otherwise our testing framework must be broken!)
assert_not_equal(tx.rehash(), tx.getwtxid()) assert_not_equal(tx.txid_hex, tx.getwtxid())
# Construct a block that includes the transaction. # Construct a block that includes the transaction.
block = self.build_next_block() block = self.build_next_block()
@@ -614,7 +614,7 @@ class SegWitTest(BitcoinTestFramework):
testres3[0]["fees"].pop("effective-includes") testres3[0]["fees"].pop("effective-includes")
assert_equal(testres3, assert_equal(testres3,
[{ [{
'txid': tx3.hash, 'txid': tx3.txid_hex,
'wtxid': tx3.getwtxid(), 'wtxid': tx3.getwtxid(),
'allowed': True, 'allowed': True,
'vsize': tx3.get_vsize(), 'vsize': tx3.get_vsize(),
@@ -632,7 +632,7 @@ class SegWitTest(BitcoinTestFramework):
testres3_replaced[0]["fees"].pop("effective-includes") testres3_replaced[0]["fees"].pop("effective-includes")
assert_equal(testres3_replaced, assert_equal(testres3_replaced,
[{ [{
'txid': tx3.hash, 'txid': tx3.txid_hex,
'wtxid': tx3.getwtxid(), 'wtxid': tx3.getwtxid(),
'allowed': True, 'allowed': True,
'vsize': tx3.get_vsize(), 'vsize': tx3.get_vsize(),
@@ -692,13 +692,13 @@ class SegWitTest(BitcoinTestFramework):
# segwit activation. Note that older bitcoind's that are not # segwit activation. Note that older bitcoind's that are not
# segwit-aware would also reject this for failing CLEANSTACK. # segwit-aware would also reject this for failing CLEANSTACK.
with self.nodes[0].assert_debug_log( with self.nodes[0].assert_debug_log(
expected_msgs=[spend_tx.hash, 'was not accepted: mandatory-script-verify-flag-failed (Witness program was passed an empty witness)']): expected_msgs=[spend_tx.txid_hex, 'was not accepted: mandatory-script-verify-flag-failed (Witness program was passed an empty witness)']):
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False) test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False)
# Try to put the witness script in the scriptSig, should also fail. # Try to put the witness script in the scriptSig, should also fail.
spend_tx.vin[0].scriptSig = CScript([p2wsh_pubkey, b'a']) spend_tx.vin[0].scriptSig = CScript([p2wsh_pubkey, b'a'])
with self.nodes[0].assert_debug_log( with self.nodes[0].assert_debug_log(
expected_msgs=[spend_tx.hash, 'was not accepted: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)']): expected_msgs=[spend_tx.txid_hex, 'was not accepted: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element)']):
test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False) test_transaction_acceptance(self.nodes[0], self.test_node, spend_tx, with_witness=False, accepted=False)
# Now put the witness script in the witness, should succeed after # Now put the witness script in the witness, should succeed after
@@ -1257,7 +1257,7 @@ class SegWitTest(BitcoinTestFramework):
# Test that getrawtransaction returns correct witness information # Test that getrawtransaction returns correct witness information
# hash, size, vsize # hash, size, vsize
raw_tx = self.nodes[0].getrawtransaction(tx3.hash, 1) raw_tx = self.nodes[0].getrawtransaction(tx3.txid_hex, 1)
assert_equal(raw_tx["hash"], tx3.getwtxid()) assert_equal(raw_tx["hash"], tx3.getwtxid())
assert_equal(raw_tx["size"], len(tx3.serialize_with_witness())) assert_equal(raw_tx["size"], len(tx3.serialize_with_witness()))
vsize = tx3.get_vsize() vsize = tx3.get_vsize()
@@ -2006,7 +2006,7 @@ class SegWitTest(BitcoinTestFramework):
test_transaction_acceptance(self.nodes[0], self.wtx_node, tx, with_witness=False, accepted=True) test_transaction_acceptance(self.nodes[0], self.wtx_node, tx, with_witness=False, accepted=True)
# Check tx2 is there now # Check tx2 is there now
assert_equal(tx2.hash in self.nodes[0].getrawmempool(), True) assert_equal(tx2.txid_hex in self.nodes[0].getrawmempool(), True)
if __name__ == '__main__': if __name__ == '__main__':
+4 -4
View File
@@ -106,7 +106,7 @@ class RPCPackagesTest(BitcoinTestFramework):
# Package validation is atomic: if the node cannot find a UTXO for any single tx in the package, # Package validation is atomic: if the node cannot find a UTXO for any single tx in the package,
# it terminates immediately to avoid unnecessary, expensive signature verification. # it terminates immediately to avoid unnecessary, expensive signature verification.
package_bad = self.independent_txns_hex + [garbage_tx] package_bad = self.independent_txns_hex + [garbage_tx]
testres_bad = self.independent_txns_testres_blank + [{"txid": tx.rehash(), "wtxid": tx.getwtxid(), "allowed": False, "reject-reason": "missing-inputs"}] testres_bad = self.independent_txns_testres_blank + [{"txid": tx.txid_hex, "wtxid": tx.getwtxid(), "allowed": False, "reject-reason": "missing-inputs"}]
self.assert_testres_equal(package_bad, testres_bad) self.assert_testres_equal(package_bad, testres_bad)
self.log.info("Check testmempoolaccept tells us when some transactions completed validation successfully") self.log.info("Check testmempoolaccept tells us when some transactions completed validation successfully")
@@ -117,7 +117,7 @@ class RPCPackagesTest(BitcoinTestFramework):
# By the time the signature for the last transaction is checked, all the other transactions # By the time the signature for the last transaction is checked, all the other transactions
# have been fully validated, which is why the node returns full validation results for all # have been fully validated, which is why the node returns full validation results for all
# transactions here but empty results in other cases. # transactions here but empty results in other cases.
tx_bad_sig_txid = tx_bad_sig.rehash() tx_bad_sig_txid = tx_bad_sig.txid_hex
tx_bad_sig_wtxid = tx_bad_sig.getwtxid() tx_bad_sig_wtxid = tx_bad_sig.getwtxid()
assert_equal(testres_bad_sig, self.independent_txns_testres + [{ assert_equal(testres_bad_sig, self.independent_txns_testres + [{
"txid": tx_bad_sig_txid, "txid": tx_bad_sig_txid,
@@ -146,7 +146,7 @@ class RPCPackagesTest(BitcoinTestFramework):
self.log.info("Check that testmempoolaccept requires packages to be sorted by dependency") self.log.info("Check that testmempoolaccept requires packages to be sorted by dependency")
assert_equal(node.testmempoolaccept(rawtxs=chain_hex[::-1]), assert_equal(node.testmempoolaccept(rawtxs=chain_hex[::-1]),
[{"txid": tx.rehash(), "wtxid": tx.getwtxid(), "package-error": "package-not-sorted"} for tx in chain_txns[::-1]]) [{"txid": tx.txid_hex, "wtxid": tx.getwtxid(), "package-error": "package-not-sorted"} for tx in chain_txns[::-1]])
self.log.info("Testmempoolaccept a chain of 25 transactions") self.log.info("Testmempoolaccept a chain of 25 transactions")
testres_multiple = node.testmempoolaccept(rawtxs=chain_hex) testres_multiple = node.testmempoolaccept(rawtxs=chain_hex)
@@ -357,7 +357,7 @@ class RPCPackagesTest(BitcoinTestFramework):
wtxid = tx.getwtxid() wtxid = tx.getwtxid()
assert wtxid in submitpackage_result["tx-results"] assert wtxid in submitpackage_result["tx-results"]
tx_result = submitpackage_result["tx-results"][wtxid] tx_result = submitpackage_result["tx-results"][wtxid]
assert_equal(tx_result["txid"], tx.rehash()) assert_equal(tx_result["txid"], tx.txid_hex)
assert_equal(tx_result["vsize"], tx.get_vsize()) assert_equal(tx_result["vsize"], tx.get_vsize())
assert_equal(tx_result["fees"]["base"], DEFAULT_FEE) assert_equal(tx_result["fees"]["base"], DEFAULT_FEE)
if wtxid not in presubmitted_wtxids: if wtxid not in presubmitted_wtxids:
@@ -34,7 +34,7 @@ def assert_mempool_contents(test_framework, node, expected=None, sync=True):
mempool = node.getrawmempool(verbose=False) mempool = node.getrawmempool(verbose=False)
assert_equal(len(mempool), len(expected)) assert_equal(len(mempool), len(expected))
for tx in expected: for tx in expected:
assert tx.rehash() in mempool assert tx.txid_hex in mempool
def fill_mempool(test_framework, node, *, tx_sync_fun=None): def fill_mempool(test_framework, node, *, tx_sync_fun=None):
@@ -104,5 +104,5 @@ def fill_mempool(test_framework, node, *, tx_sync_fun=None):
def tx_in_orphanage(node, tx: CTransaction) -> bool: def tx_in_orphanage(node, tx: CTransaction) -> bool:
"""Returns true if the transaction is in the orphanage.""" """Returns true if the transaction is in the orphanage."""
found = [o for o in node.getorphantxs(verbosity=1) if o["txid"] == tx.rehash() and o["wtxid"] == tx.getwtxid()] found = [o for o in node.getorphantxs(verbosity=1) if o["txid"] == tx.txid_hex and o["wtxid"] == tx.getwtxid()]
return len(found) == 1 return len(found) == 1
+1 -6
View File
@@ -667,7 +667,7 @@ class CTransaction:
return uint256_from_str(hash256(self.serialize_with_witness())) return uint256_from_str(hash256(self.serialize_with_witness()))
@property @property
def hash(self): def txid_hex(self):
"""Return txid (transaction hash without witness) as hex string.""" """Return txid (transaction hash without witness) as hex string."""
return hash256(self.serialize_without_witness())[::-1].hex() return hash256(self.serialize_without_witness())[::-1].hex()
@@ -676,11 +676,6 @@ class CTransaction:
"""Return txid (transaction hash without witness) as integer.""" """Return txid (transaction hash without witness) as integer."""
return uint256_from_str(hash256(self.serialize_without_witness())) return uint256_from_str(hash256(self.serialize_without_witness()))
# Recalculate the txid (transaction hash without witness)
# TODO: get rid of this method, replace call-sites by .hash access
def rehash(self):
return self.hash
def is_valid(self): def is_valid(self):
for tout in self.vout: for tout in self.vout:
if tout.nValue < 0 or tout.nValue > 21000000 * COIN: if tout.nValue < 0 or tout.nValue > 21000000 * COIN:
+3 -3
View File
@@ -619,7 +619,7 @@ class P2PInterface(P2PConnection):
def test_function(): def test_function():
if not self.last_message.get('tx'): if not self.last_message.get('tx'):
return False return False
return self.last_message['tx'].tx.rehash() == txid return self.last_message['tx'].tx.txid_hex == txid
self.wait_until(test_function, timeout=timeout) self.wait_until(test_function, timeout=timeout)
@@ -927,11 +927,11 @@ class P2PDataStore(P2PInterface):
if success: if success:
# Check that all txs are now in the mempool # Check that all txs are now in the mempool
for tx in txs: for tx in txs:
assert tx.hash in raw_mempool, "{} not found in mempool".format(tx.hash) assert tx.txid_hex in raw_mempool, "{} not found in mempool".format(tx.txid_hex)
else: else:
# Check that none of the txs are now in the mempool # Check that none of the txs are now in the mempool
for tx in txs: for tx in txs:
assert tx.hash not in raw_mempool, "{} tx found in mempool".format(tx.hash) assert tx.txid_hex not in raw_mempool, "{} tx found in mempool".format(tx.txid_hex)
class P2PTxInvStore(P2PInterface): class P2PTxInvStore(P2PInterface):
"""A P2PInterface which stores a count of how many times each txid has been announced.""" """A P2PInterface which stores a count of how many times each txid has been announced."""
+1 -1
View File
@@ -340,7 +340,7 @@ class MiniWallet:
if target_vsize: if target_vsize:
self._bulk_tx(tx, target_vsize) self._bulk_tx(tx, target_vsize)
txid = tx.rehash() txid = tx.txid_hex
return { return {
"new_utxos": [self._create_utxo( "new_utxos": [self._create_utxo(
txid=txid, txid=txid,