17
17
CTransaction ,
18
18
CTxIn ,
19
19
CTxOut ,
20
- ToHex ,
21
20
tx_from_hex ,
22
21
)
23
22
from test_framework .test_framework import BitcoinTestFramework
@@ -101,7 +100,7 @@ def test_disable_flag(self):
101
100
tx1 .vin = [CTxIn (COutPoint (int (utxo ["txid" ], 16 ), utxo ["vout" ]), nSequence = sequence_value )]
102
101
tx1 .vout = [CTxOut (value , DUMMY_P2WPKH_SCRIPT )]
103
102
104
- tx1_signed = self .nodes [0 ].signrawtransactionwithwallet (ToHex ( tx1 ))["hex" ]
103
+ tx1_signed = self .nodes [0 ].signrawtransactionwithwallet (tx1 . serialize (). hex ( ))["hex" ]
105
104
tx1_id = self .nodes [0 ].sendrawtransaction (tx1_signed )
106
105
tx1_id = int (tx1_id , 16 )
107
106
@@ -114,13 +113,13 @@ def test_disable_flag(self):
114
113
tx2 .vout = [CTxOut (int (value - self .relayfee * COIN ), DUMMY_P2WPKH_SCRIPT )]
115
114
tx2 .rehash ()
116
115
117
- assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , ToHex ( tx2 ))
116
+ assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , tx2 . serialize (). hex ( ))
118
117
119
118
# Setting the version back down to 1 should disable the sequence lock,
120
119
# so this should be accepted.
121
120
tx2 .nVersion = 1
122
121
123
- self .nodes [0 ].sendrawtransaction (ToHex ( tx2 ))
122
+ self .nodes [0 ].sendrawtransaction (tx2 . serialize (). hex ( ))
124
123
125
124
# Calculate the median time past of a prior block ("confirmations" before
126
125
# the current tip).
@@ -205,9 +204,9 @@ def test_sequence_lock_confirmed_inputs(self):
205
204
tx .vin .append (CTxIn (COutPoint (int (utxos [j ]["txid" ], 16 ), utxos [j ]["vout" ]), nSequence = sequence_value ))
206
205
value += utxos [j ]["amount" ]* COIN
207
206
# Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output
208
- tx_size = len (ToHex ( tx ))// 2 + 120 * num_inputs + 50
207
+ tx_size = len (tx . serialize (). hex ( ))// 2 + 120 * num_inputs + 50
209
208
tx .vout .append (CTxOut (int (value - self .relayfee * tx_size * COIN / 1000 ), DUMMY_P2WPKH_SCRIPT ))
210
- rawtx = self .nodes [0 ].signrawtransactionwithwallet (ToHex ( tx ))["hex" ]
209
+ rawtx = self .nodes [0 ].signrawtransactionwithwallet (tx . serialize (). hex ( ))["hex" ]
211
210
212
211
if (using_sequence_locks and not should_pass ):
213
212
# This transaction should be rejected
@@ -236,7 +235,7 @@ def test_sequence_lock_unconfirmed_inputs(self):
236
235
tx2 .nVersion = 2
237
236
tx2 .vin = [CTxIn (COutPoint (tx1 .sha256 , 0 ), nSequence = 0 )]
238
237
tx2 .vout = [CTxOut (int (tx1 .vout [0 ].nValue - self .relayfee * COIN ), DUMMY_P2WPKH_SCRIPT )]
239
- tx2_raw = self .nodes [0 ].signrawtransactionwithwallet (ToHex ( tx2 ))["hex" ]
238
+ tx2_raw = self .nodes [0 ].signrawtransactionwithwallet (tx2 . serialize (). hex ( ))["hex" ]
240
239
tx2 = tx_from_hex (tx2_raw )
241
240
tx2 .rehash ()
242
241
@@ -258,10 +257,10 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
258
257
259
258
if (orig_tx .hash in node .getrawmempool ()):
260
259
# sendrawtransaction should fail if the tx is in the mempool
261
- assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , node .sendrawtransaction , ToHex ( tx ))
260
+ assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , node .sendrawtransaction , tx . serialize (). hex ( ))
262
261
else :
263
262
# sendrawtransaction should succeed if the tx is not in the mempool
264
- node .sendrawtransaction (ToHex ( tx ))
263
+ node .sendrawtransaction (tx . serialize (). hex ( ))
265
264
266
265
return tx
267
266
@@ -311,7 +310,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
311
310
utxos = self .nodes [0 ].listunspent ()
312
311
tx5 .vin .append (CTxIn (COutPoint (int (utxos [0 ]["txid" ], 16 ), utxos [0 ]["vout" ]), nSequence = 1 ))
313
312
tx5 .vout [0 ].nValue += int (utxos [0 ]["amount" ]* COIN )
314
- raw_tx5 = self .nodes [0 ].signrawtransactionwithwallet (ToHex ( tx5 ))["hex" ]
313
+ raw_tx5 = self .nodes [0 ].signrawtransactionwithwallet (tx5 . serialize (). hex ( ))["hex" ]
315
314
316
315
assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , raw_tx5 )
317
316
@@ -337,7 +336,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
337
336
block .rehash ()
338
337
block .solve ()
339
338
tip = block .sha256
340
- assert_equal (None if i == 1 else 'inconclusive' , self .nodes [0 ].submitblock (ToHex ( block )))
339
+ assert_equal (None if i == 1 else 'inconclusive' , self .nodes [0 ].submitblock (block . serialize (). hex ( )))
341
340
tmpl = self .nodes [0 ].getblocktemplate (NORMAL_GBT_REQUEST_PARAMS )
342
341
tmpl ['previousblockhash' ] = '%x' % tip
343
342
tmpl ['transactions' ] = []
@@ -370,11 +369,11 @@ def test_bip68_not_consensus(self):
370
369
tx2 .vout = [CTxOut (int (tx1 .vout [0 ].nValue - self .relayfee * COIN ), DUMMY_P2WPKH_SCRIPT )]
371
370
372
371
# sign tx2
373
- tx2_raw = self .nodes [0 ].signrawtransactionwithwallet (ToHex ( tx2 ))["hex" ]
372
+ tx2_raw = self .nodes [0 ].signrawtransactionwithwallet (tx2 . serialize (). hex ( ))["hex" ]
374
373
tx2 = tx_from_hex (tx2_raw )
375
374
tx2 .rehash ()
376
375
377
- self .nodes [0 ].sendrawtransaction (ToHex ( tx2 ))
376
+ self .nodes [0 ].sendrawtransaction (tx2 . serialize (). hex ( ))
378
377
379
378
# Now make an invalid spend of tx2 according to BIP68
380
379
sequence_value = 100 # 100 block relative locktime
@@ -385,7 +384,7 @@ def test_bip68_not_consensus(self):
385
384
tx3 .vout = [CTxOut (int (tx2 .vout [0 ].nValue - self .relayfee * COIN ), DUMMY_P2WPKH_SCRIPT )]
386
385
tx3 .rehash ()
387
386
388
- assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , ToHex ( tx3 ))
387
+ assert_raises_rpc_error (- 26 , NOT_FINAL_ERROR , self .nodes [0 ].sendrawtransaction , tx3 . serialize (). hex ( ))
389
388
390
389
# make a block that violates bip68; ensure that the tip updates
391
390
block = create_block (tmpl = self .nodes [0 ].getblocktemplate (NORMAL_GBT_REQUEST_PARAMS ))
@@ -418,7 +417,7 @@ def test_version2_relay(self):
418
417
rawtxfund = self .nodes [1 ].fundrawtransaction (rawtx )['hex' ]
419
418
tx = tx_from_hex (rawtxfund )
420
419
tx .nVersion = 2
421
- tx_signed = self .nodes [1 ].signrawtransactionwithwallet (ToHex ( tx ))["hex" ]
420
+ tx_signed = self .nodes [1 ].signrawtransactionwithwallet (tx . serialize (). hex ( ))["hex" ]
422
421
self .nodes [1 ].sendrawtransaction (tx_signed )
423
422
424
423
if __name__ == '__main__' :
0 commit comments