Skip to content

Commit

Permalink
Merge 807169e into merged_master (Bitcoin PR bitcoin/bitcoin#24035)
Browse files Browse the repository at this point in the history
  • Loading branch information
delta1 committed Jun 20, 2023
2 parents 3b87e4e + 807169e commit c53eb39
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 89 deletions.
7 changes: 4 additions & 3 deletions test/functional/data/invalid_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
CTxIn,
CTxOut,
MAX_MONEY,
SEQUENCE_FINAL,
)
from test_framework.blocktools import create_tx_with_script, MAX_BLOCK_SIGOPS
from test_framework.script import (
Expand Down Expand Up @@ -78,7 +79,7 @@ class BadTxTemplate:
def __init__(self, *, spend_tx=None, spend_block=None):
self.spend_tx = spend_block.vtx[0] if spend_block else spend_tx
self.spend_avail = sum(o.nValue.getAmount() for o in self.spend_tx.vout)
self.valid_txin = CTxIn(COutPoint(self.spend_tx.sha256, 0), b"", 0xffffffff)
self.valid_txin = CTxIn(COutPoint(self.spend_tx.sha256, 0), b"", SEQUENCE_FINAL)

@abc.abstractmethod
def get_tx(self, *args, **kwargs):
Expand Down Expand Up @@ -140,7 +141,7 @@ def get_tx(self):
bad_idx = num_indices + 100

tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256, bad_idx), b"", 0xffffffff))
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256, bad_idx), b"", SEQUENCE_FINAL))
tx.vout.append(CTxOut(0, basic_p2sh))
tx.calc_sha256()
return tx
Expand Down Expand Up @@ -178,7 +179,7 @@ class NonexistentInput(BadTxTemplate):

def get_tx(self):
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256 + 1, 0), b"", 0xffffffff))
tx.vin.append(CTxIn(COutPoint(self.spend_tx.sha256 + 1, 0), b"", SEQUENCE_FINAL))
tx.vin.append(self.valid_txin)
tx.vout.append(CTxOut(1, basic_p2sh))
tx.calc_sha256()
Expand Down
13 changes: 9 additions & 4 deletions test/functional/feature_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CTxIn,
CTxOut,
MAX_BLOCK_WEIGHT,
SEQUENCE_FINAL,
uint256_from_compact,
uint256_from_str,
)
Expand Down Expand Up @@ -50,9 +51,13 @@
script_to_p2sh_script,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
from test_framework.util import (
assert_equal,
assert_greater_than,
)
from data import invalid_txs


# Use this class for tests that require behavior other than normal p2p behavior.
# For now, it is used to serialize a bloated varint (b64).
class CBrokenBlock(CBlock):
Expand Down Expand Up @@ -812,7 +817,7 @@ def run_test(self):
b58 = self.next_block(58, spend=out[17])
tx = CTransaction()
assert len(out[17].vout) < 42
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), 0xffffffff))
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
tx.vout.append(CTxOut(0, b""))
tx.calc_sha256()
b58 = self.update_block(58, [tx])
Expand Down Expand Up @@ -887,7 +892,7 @@ def run_test(self):
tx.nLockTime = 0xffffffff # this locktime is non-final
tx.vin.append(CTxIn(COutPoint(out[18].sha256, 0))) # don't set nSequence
tx.vout.append(CTxOut(0, CScript([OP_TRUE])))
assert tx.vin[0].nSequence < 0xffffffff
assert_greater_than(SEQUENCE_FINAL, tx.vin[0].nSequence)
tx.calc_sha256()
b62 = self.update_block(62, [tx])
self.send_blocks([b62], success=False, reject_reason='bad-txns-nonfinal', reconnect=True)
Expand Down Expand Up @@ -1038,7 +1043,7 @@ def run_test(self):
bogus_tx = CTransaction()
bogus_tx.sha256 = uint256_from_str(b"23c70ed7c0506e9178fc1a987f40a33946d4ad4c962b5ae3a52546da53af0c5c")
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", 0xffffffff))
tx.vin.append(CTxIn(COutPoint(bogus_tx.sha256, 0), b"", SEQUENCE_FINAL))
tx.vout.append(CTxOut(1, b""))
b70 = self.update_block(70, [tx])
self.send_blocks([b70], success=False, reject_reason='bad-txns-inputs-missingorspent', reconnect=True)
Expand Down
9 changes: 5 additions & 4 deletions test/functional/feature_cltv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from test_framework.messages import (
CTransaction,
SEQUENCE_FINAL,
msg_block,
)
from test_framework.p2p import P2PInterface
Expand Down Expand Up @@ -53,7 +54,7 @@ def cltv_invalidate(tx, failure_reason):
# 3) the lock-time type (height vs. timestamp) of the top stack item and the
# nLockTime field are not the same
# 4) the top stack item is greater than the transaction's nLockTime field
# 5) the nSequence field of the txin is 0xffffffff
# 5) the nSequence field of the txin is 0xffffffff (SEQUENCE_FINAL)
assert failure_reason in range(5)
scheme = [
# | Script to prepend to scriptSig | nSequence | nLockTime |
Expand All @@ -62,7 +63,7 @@ def cltv_invalidate(tx, failure_reason):
[[OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP], None, None],
[[CScriptNum(100), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, 1296688602], # timestamp of genesis block
[[CScriptNum(100), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0, 50],
[[CScriptNum(50), OP_CHECKLOCKTIMEVERIFY, OP_DROP], 0xffffffff, 50],
[[CScriptNum(50), OP_CHECKLOCKTIMEVERIFY, OP_DROP], SEQUENCE_FINAL, 50],
][failure_reason]

cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
Expand Down Expand Up @@ -115,7 +116,7 @@ def run_test(self):
# create one invalid tx per CLTV failure reason (5 in total) and collect them
invalid_cltv_txs = []
for i in range(5):
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
spendtx = wallet.create_self_transfer()['tx']
cltv_invalidate(spendtx, i)
invalid_cltv_txs.append(spendtx)

Expand Down Expand Up @@ -146,7 +147,7 @@ def run_test(self):

# create and test one invalid tx per CLTV failure reason (5 in total)
for i in range(5):
spendtx = wallet.create_self_transfer(from_node=self.nodes[0])['tx']
spendtx = wallet.create_self_transfer()['tx']
cltv_invalidate(spendtx, i)

expected_cltv_reject_reason = [
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_csv_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def set_test_params(self):

def create_self_transfer_from_utxo(self, input_tx):
utxo = self.miniwallet.get_utxo(txid=input_tx.rehash(), mark_as_spent=False)
tx = self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo)['tx']
tx = self.miniwallet.create_self_transfer(utxo_to_spend=utxo)['tx']
return tx

def create_bip112special(self, input, txversion):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_dersig.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set_test_params(self):

def create_tx(self, input_txid):
utxo_to_spend = self.miniwallet.get_utxo(txid=input_txid, mark_as_spent=False)
return self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
return self.miniwallet.create_self_transfer(utxo_to_spend=utxo_to_spend)['tx']

def test_dersig_info(self, *, is_active):
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],
Expand Down
13 changes: 6 additions & 7 deletions test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CTxIn,
CTxOut,
CTxOutValue,
SEQUENCE_FINAL,
)
from test_framework.script import CScript, OP_DROP
from test_framework.test_framework import BitcoinTestFramework
Expand Down Expand Up @@ -418,7 +419,7 @@ def test_opt_in(self):

# Create a non-opting in transaction
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0xffffffff)]
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=SEQUENCE_FINAL)]
tx1a.vout = [CTxOut(1 * COIN, DUMMY_P2WPKH_SCRIPT), CTxOut(int(0.1*COIN))]
tx1a_hex = tx1a.serialize().hex()
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, 0)
Expand Down Expand Up @@ -461,7 +462,7 @@ def test_opt_in(self):
tx2a_txid = int(tx2a_txid, 16)

tx3a = CTransaction()
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=SEQUENCE_FINAL),
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
tx3a.vout = [CTxOut(int(0.9 * COIN), CScript([b'c'])), CTxOut(int(0.9 * COIN), CScript([b'd']))]
tx3a.vout.append(CTxOut(int(0.2 * COIN)))
Expand Down Expand Up @@ -580,7 +581,6 @@ def test_no_inherited_signaling(self):
assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])

replacement_parent_tx = self.wallet.create_self_transfer(
from_node=self.nodes[0],
utxo_to_spend=confirmed_utxo,
sequence=BIP125_SEQUENCE_NUMBER,
fee_rate=Decimal('0.02'),
Expand All @@ -597,17 +597,16 @@ def test_no_inherited_signaling(self):
optout_child_tx = self.wallet.send_self_transfer(
from_node=self.nodes[0],
utxo_to_spend=parent_utxo,
sequence=0xffffffff,
sequence=SEQUENCE_FINAL,
fee_rate=Decimal('0.01'),
)

# Reports true due to inheritance
assert_equal(True, self.nodes[0].getmempoolentry(optout_child_tx['txid'])['bip125-replaceable'])

replacement_child_tx = self.wallet.create_self_transfer(
from_node=self.nodes[0],
utxo_to_spend=parent_utxo,
sequence=0xffffffff,
sequence=SEQUENCE_FINAL,
fee_rate=Decimal('0.02'),
mempool_valid=False,
)
Expand All @@ -626,7 +625,7 @@ def test_no_inherited_signaling(self):
replacement_parent_tx = self.wallet.send_self_transfer(
from_node=self.nodes[0],
utxo_to_spend=confirmed_utxo,
sequence=0xffffffff,
sequence=SEQUENCE_FINAL,
fee_rate=Decimal('0.03'),
)
# Check that child is removed and update wallet utxo state
Expand Down
7 changes: 4 additions & 3 deletions test/functional/feature_taproot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CTxOutValue,
CTxOutWitness,
uint256_from_str,
SEQUENCE_FINAL,
)
from test_framework.script import (
ANNEX_TAG,
Expand Down Expand Up @@ -1545,7 +1546,7 @@ def gen_test_vectors(self):
assert self.nodes[1].getblockcount() == 0
coinbase = CTransaction()
coinbase.nVersion = 1
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), 0xffffffff)]
coinbase.vin = [CTxIn(COutPoint(0, 0xffffffff), CScript([OP_1, OP_1]), SEQUENCE_FINAL)]
coinbase.vout = [CTxOut(5000000000, CScript([OP_1]))]
coinbase.nLockTime = 0
coinbase.rehash()
Expand Down Expand Up @@ -1633,7 +1634,7 @@ def gen_test_vectors(self):
val = 42000000 * (i + 7)
tx = CTransaction()
tx.nVersion = 1
tx.vin = [CTxIn(COutPoint(lasttxid, i & 1), CScript([]), 0xffffffff)]
tx.vin = [CTxIn(COutPoint(lasttxid, i & 1), CScript([]), SEQUENCE_FINAL)]
tx.vout = [CTxOut(val, spk), CTxOut(amount - val, CScript([OP_1]))]
if i & 1:
tx.vout = list(reversed(tx.vout))
Expand Down Expand Up @@ -1693,7 +1694,7 @@ def pr(node):
tx.vin = []
inputs = []
input_spks = [tap_spks[0], tap_spks[1], old_spks[0], tap_spks[2], tap_spks[5], old_spks[2], tap_spks[6], tap_spks[3], tap_spks[4]]
sequences = [0, 0xffffffff, 0xffffffff, 0xfffffffe, 0xfffffffe, 0, 0, 0xffffffff, 0xffffffff]
sequences = [0, SEQUENCE_FINAL, SEQUENCE_FINAL, 0xfffffffe, 0xfffffffe, 0, 0, SEQUENCE_FINAL, SEQUENCE_FINAL]
hashtypes = [SIGHASH_SINGLE, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, SIGHASH_ALL, SIGHASH_ALL, SIGHASH_DEFAULT, SIGHASH_ALL, SIGHASH_NONE, SIGHASH_NONE|SIGHASH_ANYONECANPAY, SIGHASH_ALL|SIGHASH_ANYONECANPAY]
for i, spk in enumerate(input_spks):
tx.vin.append(CTxIn(spend_info[spk]['prevout'], CScript(), sequences[i]))
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_utxo_set_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def test_muhash_implementation(self):
assert_equal(finalized[::-1].hex(), node_muhash)

self.log.info("Test deterministic UTXO set hash results")
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "583f20a8cb93ad78ea2e0952b39beb79252bf94adf8bb1845f9625dbe8cf39ed")
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "8415065423b8f892c018535af74bcdc58cd79314f52c4ae1948f6a7382d43cae")
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "4f08452f289a6cb0f277db2cef735d6332532f917321d8d8650b811d5119ec7c")
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "0352e9a14613eea9f00ed9f437444450bdd64ea998b88579fdd71811a2d0d7cf")

def run_test(self):
self.test_muhash_implementation()
Expand Down
Loading

0 comments on commit c53eb39

Please sign in to comment.