aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_bip68_sequence.py
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-06-16 00:32:18 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-06-21 14:30:03 +0200
commita79396fe5f8f81c78cf84117a87074c6ff6c9d95 (patch)
tree6d5a3a187d6968bd1c5236f1b20bb5ba7759628e /test/functional/feature_bip68_sequence.py
parent2ce7b47958c4a10ba20dc86c011d71cda4b070a5 (diff)
downloadbitcoin-a79396fe5f8f81c78cf84117a87074c6ff6c9d95.tar.xz
test: remove `ToHex` helper, use .serialize().hex() instead
Diffstat (limited to 'test/functional/feature_bip68_sequence.py')
-rwxr-xr-xtest/functional/feature_bip68_sequence.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py
index 2b2341fb03..e44ce9b57d 100755
--- a/test/functional/feature_bip68_sequence.py
+++ b/test/functional/feature_bip68_sequence.py
@@ -17,7 +17,6 @@ from test_framework.messages import (
CTransaction,
CTxIn,
CTxOut,
- ToHex,
tx_from_hex,
)
from test_framework.test_framework import BitcoinTestFramework
@@ -101,7 +100,7 @@ class BIP68Test(BitcoinTestFramework):
tx1.vin = [CTxIn(COutPoint(int(utxo["txid"], 16), utxo["vout"]), nSequence=sequence_value)]
tx1.vout = [CTxOut(value, DUMMY_P2WPKH_SCRIPT)]
- tx1_signed = self.nodes[0].signrawtransactionwithwallet(ToHex(tx1))["hex"]
+ tx1_signed = self.nodes[0].signrawtransactionwithwallet(tx1.serialize().hex())["hex"]
tx1_id = self.nodes[0].sendrawtransaction(tx1_signed)
tx1_id = int(tx1_id, 16)
@@ -114,13 +113,13 @@ class BIP68Test(BitcoinTestFramework):
tx2.vout = [CTxOut(int(value - self.relayfee * COIN), DUMMY_P2WPKH_SCRIPT)]
tx2.rehash()
- assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx2))
+ assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, tx2.serialize().hex())
# Setting the version back down to 1 should disable the sequence lock,
# so this should be accepted.
tx2.nVersion = 1
- self.nodes[0].sendrawtransaction(ToHex(tx2))
+ self.nodes[0].sendrawtransaction(tx2.serialize().hex())
# Calculate the median time past of a prior block ("confirmations" before
# the current tip).
@@ -205,9 +204,9 @@ class BIP68Test(BitcoinTestFramework):
tx.vin.append(CTxIn(COutPoint(int(utxos[j]["txid"], 16), utxos[j]["vout"]), nSequence=sequence_value))
value += utxos[j]["amount"]*COIN
# Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output
- tx_size = len(ToHex(tx))//2 + 120*num_inputs + 50
+ tx_size = len(tx.serialize().hex())//2 + 120*num_inputs + 50
tx.vout.append(CTxOut(int(value-self.relayfee*tx_size*COIN/1000), DUMMY_P2WPKH_SCRIPT))
- rawtx = self.nodes[0].signrawtransactionwithwallet(ToHex(tx))["hex"]
+ rawtx = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())["hex"]
if (using_sequence_locks and not should_pass):
# This transaction should be rejected
@@ -236,7 +235,7 @@ class BIP68Test(BitcoinTestFramework):
tx2.nVersion = 2
tx2.vin = [CTxIn(COutPoint(tx1.sha256, 0), nSequence=0)]
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), DUMMY_P2WPKH_SCRIPT)]
- tx2_raw = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))["hex"]
+ tx2_raw = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())["hex"]
tx2 = tx_from_hex(tx2_raw)
tx2.rehash()
@@ -258,10 +257,10 @@ class BIP68Test(BitcoinTestFramework):
if (orig_tx.hash in node.getrawmempool()):
# sendrawtransaction should fail if the tx is in the mempool
- assert_raises_rpc_error(-26, NOT_FINAL_ERROR, node.sendrawtransaction, ToHex(tx))
+ assert_raises_rpc_error(-26, NOT_FINAL_ERROR, node.sendrawtransaction, tx.serialize().hex())
else:
# sendrawtransaction should succeed if the tx is not in the mempool
- node.sendrawtransaction(ToHex(tx))
+ node.sendrawtransaction(tx.serialize().hex())
return tx
@@ -311,7 +310,7 @@ class BIP68Test(BitcoinTestFramework):
utxos = self.nodes[0].listunspent()
tx5.vin.append(CTxIn(COutPoint(int(utxos[0]["txid"], 16), utxos[0]["vout"]), nSequence=1))
tx5.vout[0].nValue += int(utxos[0]["amount"]*COIN)
- raw_tx5 = self.nodes[0].signrawtransactionwithwallet(ToHex(tx5))["hex"]
+ raw_tx5 = self.nodes[0].signrawtransactionwithwallet(tx5.serialize().hex())["hex"]
assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, raw_tx5)
@@ -337,7 +336,7 @@ class BIP68Test(BitcoinTestFramework):
block.rehash()
block.solve()
tip = block.sha256
- assert_equal(None if i == 1 else 'inconclusive', self.nodes[0].submitblock(ToHex(block)))
+ assert_equal(None if i == 1 else 'inconclusive', self.nodes[0].submitblock(block.serialize().hex()))
tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
tmpl['previousblockhash'] = '%x' % tip
tmpl['transactions'] = []
@@ -370,11 +369,11 @@ class BIP68Test(BitcoinTestFramework):
tx2.vout = [CTxOut(int(tx1.vout[0].nValue - self.relayfee*COIN), DUMMY_P2WPKH_SCRIPT)]
# sign tx2
- tx2_raw = self.nodes[0].signrawtransactionwithwallet(ToHex(tx2))["hex"]
+ tx2_raw = self.nodes[0].signrawtransactionwithwallet(tx2.serialize().hex())["hex"]
tx2 = tx_from_hex(tx2_raw)
tx2.rehash()
- self.nodes[0].sendrawtransaction(ToHex(tx2))
+ self.nodes[0].sendrawtransaction(tx2.serialize().hex())
# Now make an invalid spend of tx2 according to BIP68
sequence_value = 100 # 100 block relative locktime
@@ -385,7 +384,7 @@ class BIP68Test(BitcoinTestFramework):
tx3.vout = [CTxOut(int(tx2.vout[0].nValue - self.relayfee * COIN), DUMMY_P2WPKH_SCRIPT)]
tx3.rehash()
- assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, ToHex(tx3))
+ assert_raises_rpc_error(-26, NOT_FINAL_ERROR, self.nodes[0].sendrawtransaction, tx3.serialize().hex())
# make a block that violates bip68; ensure that the tip updates
block = create_block(tmpl=self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS))
@@ -418,7 +417,7 @@ class BIP68Test(BitcoinTestFramework):
rawtxfund = self.nodes[1].fundrawtransaction(rawtx)['hex']
tx = tx_from_hex(rawtxfund)
tx.nVersion = 2
- tx_signed = self.nodes[1].signrawtransactionwithwallet(ToHex(tx))["hex"]
+ tx_signed = self.nodes[1].signrawtransactionwithwallet(tx.serialize().hex())["hex"]
self.nodes[1].sendrawtransaction(tx_signed)
if __name__ == '__main__':