diff options
author | Ava Chow <github@achow101.com> | 2024-01-25 16:27:08 -0500 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-06-07 12:40:21 -0400 |
commit | 27e70f1f5be1f536f2314cd2ea42b4f80d927fbd (patch) | |
tree | 0cdfa2c9d06bf39b9839de304975aba80caf3c28 /test/functional | |
parent | 6e4d18f37f42894fe9a0d7948c1da3f061fc6b60 (diff) |
consensus: Store transaction nVersion as uint32_t
Given that the use of a transaction's nVersion is always as an unsigned
int, it doesn't make sense to store it as signed and then cast it to
unsigned.
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/feature_taproot.py | 2 | ||||
-rwxr-xr-x | test/functional/p2p_segwit.py | 4 | ||||
-rwxr-xr-x | test/functional/rpc_packages.py | 2 | ||||
-rwxr-xr-x | test/functional/rpc_rawtransaction.py | 18 | ||||
-rwxr-xr-x | test/functional/test_framework/messages.py | 6 | ||||
-rw-r--r-- | test/functional/test_framework/script.py | 4 |
6 files changed, 25 insertions, 11 deletions
diff --git a/test/functional/feature_taproot.py b/test/functional/feature_taproot.py index e7d65b4539..210ec54329 100755 --- a/test/functional/feature_taproot.py +++ b/test/functional/feature_taproot.py @@ -1410,7 +1410,7 @@ class TaprootTest(BitcoinTestFramework): while left: # Construct CTransaction with random nVersion, nLocktime tx = CTransaction() - tx.nVersion = random.choice([1, 2, random.randint(-0x80000000, 0x7fffffff)]) + tx.nVersion = random.choice([1, 2, random.getrandbits(32)]) min_sequence = (tx.nVersion != 1 and tx.nVersion != 0) * 0x80000000 # The minimum sequence number to disable relative locktime if random.choice([True, False]): tx.nLockTime = random.randrange(LOCKTIME_THRESHOLD, self.lastblocktime - 7200) # all absolute locktimes in the past diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py index b63c2c7a8d..31f7f35cc3 100755 --- a/test/functional/p2p_segwit.py +++ b/test/functional/p2p_segwit.py @@ -1164,7 +1164,7 @@ class SegWitTest(BitcoinTestFramework): if not self.wit.is_null(): flags |= 1 r = b"" - r += self.nVersion.to_bytes(4, "little", signed=True) + r += self.nVersion.to_bytes(4, "little") if flags: dummy = [] r += ser_vector(dummy) @@ -1975,7 +1975,7 @@ class SegWitTest(BitcoinTestFramework): def serialize_with_bogus_witness(tx): flags = 3 r = b"" - r += tx.nVersion.to_bytes(4, "little", signed=True) + r += tx.nVersion.to_bytes(4, "little") if flags: dummy = [] r += ser_vector(dummy) diff --git a/test/functional/rpc_packages.py b/test/functional/rpc_packages.py index 113424c0a6..16c038746f 100755 --- a/test/functional/rpc_packages.py +++ b/test/functional/rpc_packages.py @@ -394,7 +394,7 @@ class RPCPackagesTest(BitcoinTestFramework): peer = node.add_p2p_connection(P2PTxInvStore()) txs = self.wallet.create_self_transfer_chain(chain_length=2) bad_child = tx_from_hex(txs[1]["hex"]) - bad_child.nVersion = -1 + bad_child.nVersion = 0xffffffff hex_partial_acceptance = [txs[0]["hex"], bad_child.serialize().hex()] res = node.submitpackage(hex_partial_acceptance) assert_equal(res["package_msg"], "transaction failed") diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index 3978c80dde..e18a735fbc 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -463,9 +463,9 @@ class RawTransactionsTest(BitcoinTestFramework): self.log.info("Test transaction version numbers") # Test the minimum transaction version number that fits in a signed 32-bit integer. - # As transaction version is unsigned, this should convert to its unsigned equivalent. + # As transaction version is serialized unsigned, this should convert to its unsigned equivalent. tx = CTransaction() - tx.nVersion = -0x80000000 + tx.nVersion = 0x80000000 rawtx = tx.serialize().hex() decrawtx = self.nodes[0].decoderawtransaction(rawtx) assert_equal(decrawtx['version'], 0x80000000) @@ -477,6 +477,20 @@ class RawTransactionsTest(BitcoinTestFramework): decrawtx = self.nodes[0].decoderawtransaction(rawtx) assert_equal(decrawtx['version'], 0x7fffffff) + # Test the minimum transaction version number that fits in an unsigned 32-bit integer. + tx = CTransaction() + tx.nVersion = 0 + rawtx = tx.serialize().hex() + decrawtx = self.nodes[0].decoderawtransaction(rawtx) + assert_equal(decrawtx['version'], 0) + + # Test the maximum transaction version number that fits in an unsigned 32-bit integer. + tx = CTransaction() + tx.nVersion = 0xffffffff + rawtx = tx.serialize().hex() + decrawtx = self.nodes[0].decoderawtransaction(rawtx) + assert_equal(decrawtx['version'], 0xffffffff) + def raw_multisig_transaction_legacy_tests(self): self.log.info("Test raw multisig transactions (legacy)") # The traditional multisig workflow does not work with descriptor wallets so these are legacy only. diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 4e496a9275..db793233b8 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -582,7 +582,7 @@ class CTransaction: self.wit = copy.deepcopy(tx.wit) def deserialize(self, f): - self.nVersion = int.from_bytes(f.read(4), "little", signed=True) + self.nVersion = int.from_bytes(f.read(4), "little") self.vin = deser_vector(f, CTxIn) flags = 0 if len(self.vin) == 0: @@ -605,7 +605,7 @@ class CTransaction: def serialize_without_witness(self): r = b"" - r += self.nVersion.to_bytes(4, "little", signed=True) + r += self.nVersion.to_bytes(4, "little") r += ser_vector(self.vin) r += ser_vector(self.vout) r += self.nLockTime.to_bytes(4, "little") @@ -617,7 +617,7 @@ class CTransaction: if not self.wit.is_null(): flags |= 1 r = b"" - r += self.nVersion.to_bytes(4, "little", signed=True) + r += self.nVersion.to_bytes(4, "little") if flags: dummy = [] r += ser_vector(dummy) diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py index ab3dc2ffb1..8489e2937d 100644 --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -738,7 +738,7 @@ def SegwitV0SignatureMsg(script, txTo, inIdx, hashtype, amount): hashOutputs = uint256_from_str(hash256(serialize_outputs)) ss = bytes() - ss += txTo.nVersion.to_bytes(4, "little", signed=True) + ss += txTo.nVersion.to_bytes(4, "little") ss += ser_uint256(hashPrevouts) ss += ser_uint256(hashSequence) ss += txTo.vin[inIdx].prevout.serialize() @@ -817,7 +817,7 @@ def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index = 0, scriptpat in_type = hash_type & SIGHASH_ANYONECANPAY spk = spent_utxos[input_index].scriptPubKey ss = bytes([0, hash_type]) # epoch, hash_type - ss += txTo.nVersion.to_bytes(4, "little", signed=True) + ss += txTo.nVersion.to_bytes(4, "little") ss += txTo.nLockTime.to_bytes(4, "little") if in_type != SIGHASH_ANYONECANPAY: ss += BIP341_sha_prevouts(txTo) |