@@ -78,9 +78,8 @@ def run_test(self):
78
78
self .sync_all ()
79
79
self .nodes [0 ].generate (COINBASE_MATURITY + 1 )
80
80
self .sync_all ()
81
- self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (),1.5 )
82
- self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (),1.0 )
83
- self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (),5.0 )
81
+ for amount in [1.5 , 1.0 , 5.0 ]:
82
+ self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), amount )
84
83
self .sync_all ()
85
84
self .nodes [0 ].generate (5 )
86
85
self .sync_all ()
@@ -192,7 +191,8 @@ def createrawtransaction_tests(self):
192
191
assert_raises_rpc_error (- 1 , "JSON value is not an object as expected" , self .nodes [0 ].createrawtransaction , ['foo' ], {})
193
192
assert_raises_rpc_error (- 1 , "JSON value is not a string as expected" , self .nodes [0 ].createrawtransaction , [{}], {})
194
193
assert_raises_rpc_error (- 8 , "txid must be of length 64 (not 3, for 'foo')" , self .nodes [0 ].createrawtransaction , [{'txid' : 'foo' }], {})
195
- assert_raises_rpc_error (- 8 , "txid must be hexadecimal string (not 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844')" , self .nodes [0 ].createrawtransaction , [{'txid' : 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844' }], {})
194
+ txid = "ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844"
195
+ assert_raises_rpc_error (- 8 , f"txid must be hexadecimal string (not '{ txid } ')" , self .nodes [0 ].createrawtransaction , [{'txid' : txid }], {})
196
196
assert_raises_rpc_error (- 8 , "Invalid parameter, missing vout key" , self .nodes [0 ].createrawtransaction , [{'txid' : TXID }], {})
197
197
assert_raises_rpc_error (- 8 , "Invalid parameter, missing vout key" , self .nodes [0 ].createrawtransaction , [{'txid' : TXID , 'vout' : 'foo' }], {})
198
198
assert_raises_rpc_error (- 8 , "Invalid parameter, vout cannot be negative" , self .nodes [0 ].createrawtransaction , [{'txid' : TXID , 'vout' : - 1 }], {})
@@ -264,9 +264,9 @@ def signrawtransactionwithwallet_tests(self):
264
264
addr = self .nodes [0 ].getnewaddress ("" , type )
265
265
addrinfo = self .nodes [0 ].getaddressinfo (addr )
266
266
pubkey = addrinfo ["scriptPubKey" ]
267
- inputs = [ {'txid' : TXID , 'vout' : 3 , 'sequence' : 1000 }]
268
- outputs = { self .nodes [0 ].getnewaddress () : 1 }
269
- rawtx = self .nodes [0 ].createrawtransaction (inputs , outputs )
267
+ inputs = [{'txid' : TXID , 'vout' : 3 , 'sequence' : 1000 }]
268
+ outputs = {self .nodes [0 ].getnewaddress (): 1 }
269
+ rawtx = self .nodes [0 ].createrawtransaction (inputs , outputs )
270
270
271
271
prevtx = dict (txid = TXID , scriptPubKey = pubkey , vout = 3 , amount = 1 )
272
272
succ = self .nodes [0 ].signrawtransactionwithwallet (rawtx , [prevtx ])
@@ -309,23 +309,25 @@ def signrawtransactionwithwallet_tests(self):
309
309
310
310
def sendrawtransaction_tests (self ):
311
311
self .log .info ("Test sendrawtransaction with missing input" )
312
- inputs = [{'txid' : TXID , 'vout' : 1 }] # won't exist
313
- outputs = { self .nodes [0 ].getnewaddress () : 4.998 }
314
- rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
315
- rawtx = self .nodes [2 ].signrawtransactionwithwallet (rawtx )
312
+ inputs = [{'txid' : TXID , 'vout' : 1 }] # won't exist
313
+ outputs = {self .nodes [0 ].getnewaddress (): 4.998 }
314
+ rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
315
+ rawtx = self .nodes [2 ].signrawtransactionwithwallet (rawtx )
316
316
assert_raises_rpc_error (- 25 , "bad-txns-inputs-missingorspent" , self .nodes [2 ].sendrawtransaction , rawtx ['hex' ])
317
317
318
318
def sendrawtransaction_testmempoolaccept_tests (self ):
319
319
self .log .info ("Test sendrawtransaction/testmempoolaccept with maxfeerate" )
320
+ fee_exceeds_max = "Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)"
321
+
320
322
# Test a transaction with a small fee.
321
323
txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 1.0 )
322
324
rawTx = self .nodes [0 ].getrawtransaction (txId , True )
323
325
vout = next (o for o in rawTx ['vout' ] if o ['value' ] == Decimal ('1.00000000' ))
324
326
325
327
self .sync_all ()
326
- inputs = [{ "txid" : txId , "vout" : vout ['n' ] }]
328
+ inputs = [{"txid" : txId , "vout" : vout ['n' ]}]
327
329
# Fee 10,000 satoshis, (1 - (10000 sat * 0.00000001 BTC/sat)) = 0.9999
328
- outputs = { self .nodes [0 ].getnewaddress () : Decimal ("0.99990000" ) }
330
+ outputs = {self .nodes [0 ].getnewaddress (): Decimal ("0.99990000" )}
329
331
rawTx = self .nodes [2 ].createrawtransaction (inputs , outputs )
330
332
rawTxSigned = self .nodes [2 ].signrawtransactionwithwallet (rawTx )
331
333
assert_equal (rawTxSigned ['complete' ], True )
@@ -335,7 +337,7 @@ def sendrawtransaction_testmempoolaccept_tests(self):
335
337
assert_equal (testres ['allowed' ], False )
336
338
assert_equal (testres ['reject-reason' ], 'max-fee-exceeded' )
337
339
# and sendrawtransaction should throw
338
- assert_raises_rpc_error (- 25 , 'Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)' , self .nodes [2 ].sendrawtransaction , rawTxSigned ['hex' ], 0.00001000 )
340
+ assert_raises_rpc_error (- 25 , fee_exceeds_max , self .nodes [2 ].sendrawtransaction , rawTxSigned ['hex' ], 0.00001000 )
339
341
# and the following calls should both succeed
340
342
testres = self .nodes [2 ].testmempoolaccept (rawtxs = [rawTxSigned ['hex' ]])[0 ]
341
343
assert_equal (testres ['allowed' ], True )
@@ -347,9 +349,9 @@ def sendrawtransaction_testmempoolaccept_tests(self):
347
349
vout = next (o for o in rawTx ['vout' ] if o ['value' ] == Decimal ('1.00000000' ))
348
350
349
351
self .sync_all ()
350
- inputs = [{ "txid" : txId , "vout" : vout ['n' ] }]
352
+ inputs = [{"txid" : txId , "vout" : vout ['n' ]}]
351
353
# Fee 2,000,000 satoshis, (1 - (2000000 sat * 0.00000001 BTC/sat)) = 0.98
352
- outputs = { self .nodes [0 ].getnewaddress () : Decimal ("0.98000000" ) }
354
+ outputs = {self .nodes [0 ].getnewaddress () : Decimal ("0.98000000" )}
353
355
rawTx = self .nodes [2 ].createrawtransaction (inputs , outputs )
354
356
rawTxSigned = self .nodes [2 ].signrawtransactionwithwallet (rawTx )
355
357
assert_equal (rawTxSigned ['complete' ], True )
@@ -359,7 +361,7 @@ def sendrawtransaction_testmempoolaccept_tests(self):
359
361
assert_equal (testres ['allowed' ], False )
360
362
assert_equal (testres ['reject-reason' ], 'max-fee-exceeded' )
361
363
# and sendrawtransaction should throw
362
- assert_raises_rpc_error (- 25 , 'Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)' , self .nodes [2 ].sendrawtransaction , rawTxSigned ['hex' ])
364
+ assert_raises_rpc_error (- 25 , fee_exceeds_max , self .nodes [2 ].sendrawtransaction , rawTxSigned ['hex' ])
363
365
# and the following calls should both succeed
364
366
testres = self .nodes [2 ].testmempoolaccept (rawtxs = [rawTxSigned ['hex' ]], maxfeerate = '0.20000000' )[0 ]
365
367
assert_equal (testres ['allowed' ], True )
@@ -378,20 +380,22 @@ def decoderawtransaction_tests(self):
378
380
self .log .info ("Test decoderawtransaction" )
379
381
# witness transaction
380
382
encrawtx = "010000000001010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f50500000000000102616100000000"
381
- decrawtx = self .nodes [0 ].decoderawtransaction (encrawtx , True ) # decode as witness transaction
383
+ decrawtx = self .nodes [0 ].decoderawtransaction (encrawtx , True ) # decode as witness transaction
382
384
assert_equal (decrawtx ['vout' ][0 ]['value' ], Decimal ('1.00000000' ))
383
385
assert_raises_rpc_error (- 22 , 'TX decode failed' , self .nodes [0 ].decoderawtransaction , encrawtx , False ) # force decode as non-witness transaction
384
386
# non-witness transaction
385
387
encrawtx = "01000000010000000000000072c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000ffffffff0100e1f505000000000000000000"
386
- decrawtx = self .nodes [0 ].decoderawtransaction (encrawtx , False ) # decode as non-witness transaction
388
+ decrawtx = self .nodes [0 ].decoderawtransaction (encrawtx , False ) # decode as non-witness transaction
387
389
assert_equal (decrawtx ['vout' ][0 ]['value' ], Decimal ('1.00000000' ))
388
390
# known ambiguous transaction in the chain (see https://github.com/bitcoin/bitcoin/issues/20579)
389
- encrawtx = "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff4b03c68708046ff8415c622f4254432e434f4d2ffabe6d6de1965d02c68f928e5b244ab1965115a36f56eb997633c7f690124bbf43644e23080000000ca3d3af6d005a65ff0200fd00000000ffffffff03f4c1fb4b0000000016001497cfc76442fe717f2a3f0cc9c175f7561b6619970000000000000000266a24aa21a9ed957d1036a80343e0d1b659497e1b48a38ebe876a056d45965fac4a85cda84e1900000000000000002952534b424c4f434b3a8e092581ab01986cbadc84f4b43f4fa4bb9e7a2e2a0caf9b7cf64d939028e22c0120000000000000000000000000000000000000000000000000000000000000000000000000"
391
+ coinbase = "03c68708046ff8415c622f4254432e434f4d2ffabe6d6de1965d02c68f928e5b244ab1965115a36f56eb997633c7f690124bbf43644e23080000000ca3d3af6d005a65ff0200fd00000000"
392
+ encrawtx = f"020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff4b{ coinbase } " \
393
+ "ffffffff03f4c1fb4b0000000016001497cfc76442fe717f2a3f0cc9c175f7561b6619970000000000000000266a24aa21a9ed957d1036a80343e0d1b659497e1b48a38ebe876a056d45965fac4a85cda84e1900000000000000002952534b424c4f434b3a8e092581ab01986cbadc84f4b43f4fa4bb9e7a2e2a0caf9b7cf64d939028e22c0120000000000000000000000000000000000000000000000000000000000000000000000000"
390
394
decrawtx = self .nodes [0 ].decoderawtransaction (encrawtx )
391
395
decrawtx_wit = self .nodes [0 ].decoderawtransaction (encrawtx , True )
392
- assert_raises_rpc_error (- 22 , 'TX decode failed' , self .nodes [0 ].decoderawtransaction , encrawtx , False ) # fails to decode as non-witness transaction
393
- assert_equal (decrawtx , decrawtx_wit ) # the witness interpretation should be chosen
394
- assert_equal (decrawtx ['vin' ][0 ]['coinbase' ], "03c68708046ff8415c622f4254432e434f4d2ffabe6d6de1965d02c68f928e5b244ab1965115a36f56eb997633c7f690124bbf43644e23080000000ca3d3af6d005a65ff0200fd00000000" )
396
+ assert_raises_rpc_error (- 22 , 'TX decode failed' , self .nodes [0 ].decoderawtransaction , encrawtx , False ) # fails to decode as non-witness transaction
397
+ assert_equal (decrawtx , decrawtx_wit ) # the witness interpretation should be chosen
398
+ assert_equal (decrawtx ['vin' ][0 ]['coinbase' ], coinbase )
395
399
396
400
def transaction_version_number_tests (self ):
397
401
self .log .info ("Test transaction version numbers" )
@@ -415,6 +419,7 @@ def raw_multisig_transaction_legacy_tests(self):
415
419
self .log .info ("Test raw multisig transactions (legacy)" )
416
420
# The traditional multisig workflow does not work with descriptor wallets so these are legacy only.
417
421
# The multisig workflow with descriptor wallets uses PSBTs and is tested elsewhere, no need to do them here.
422
+
418
423
# 2of2 test
419
424
addr1 = self .nodes [2 ].getnewaddress ()
420
425
addr2 = self .nodes [2 ].getnewaddress ()
@@ -424,20 +429,23 @@ def raw_multisig_transaction_legacy_tests(self):
424
429
425
430
# Tests for createmultisig and addmultisigaddress
426
431
assert_raises_rpc_error (- 5 , "Invalid public key" , self .nodes [0 ].createmultisig , 1 , ["01020304" ])
427
- self .nodes [0 ].createmultisig (2 , [addr1Obj ['pubkey' ], addr2Obj ['pubkey' ]]) # createmultisig can only take public keys
428
- assert_raises_rpc_error (- 5 , "Invalid public key" , self .nodes [0 ].createmultisig , 2 , [addr1Obj ['pubkey' ], addr1 ]) # addmultisigaddress can take both pubkeys and addresses so long as they are in the wallet, which is tested here.
432
+ # createmultisig can only take public keys
433
+ self .nodes [0 ].createmultisig (2 , [addr1Obj ['pubkey' ], addr2Obj ['pubkey' ]])
434
+ # addmultisigaddress can take both pubkeys and addresses so long as they are in the wallet, which is tested here
435
+ assert_raises_rpc_error (- 5 , "Invalid public key" , self .nodes [0 ].createmultisig , 2 , [addr1Obj ['pubkey' ], addr1 ])
429
436
430
437
mSigObj = self .nodes [2 ].addmultisigaddress (2 , [addr1Obj ['pubkey' ], addr1 ])['address' ]
431
438
432
- #use balance deltas instead of absolute values
439
+ # use balance deltas instead of absolute values
433
440
bal = self .nodes [2 ].getbalance ()
434
441
435
442
# send 1.2 BTC to msig adr
436
443
txId = self .nodes [0 ].sendtoaddress (mSigObj , 1.2 )
437
444
self .sync_all ()
438
445
self .nodes [0 ].generate (1 )
439
446
self .sync_all ()
440
- assert_equal (self .nodes [2 ].getbalance (), bal + Decimal ('1.20000000' )) #node2 has both keys of the 2of2 ms addr., tx should affect the balance
447
+ # node2 has both keys of the 2of2 ms addr, tx should affect the balance
448
+ assert_equal (self .nodes [2 ].getbalance (), bal + Decimal ('1.20000000' ))
441
449
442
450
443
451
# 2of3 test from different nodes
@@ -459,29 +467,29 @@ def raw_multisig_transaction_legacy_tests(self):
459
467
self .nodes [0 ].generate (1 )
460
468
self .sync_all ()
461
469
462
- #THIS IS AN INCOMPLETE FEATURE
463
- #NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
464
- assert_equal (self .nodes [2 ].getbalance (), bal ) # for now, assume the funds of a 2of3 multisig tx are not marked as spendable
470
+ # THIS IS AN INCOMPLETE FEATURE
471
+ # NODE2 HAS TWO OF THREE KEYS AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
472
+ assert_equal (self .nodes [2 ].getbalance (), bal ) # for now, assume the funds of a 2of3 multisig tx are not marked as spendable
465
473
466
474
txDetails = self .nodes [0 ].gettransaction (txId , True )
467
475
rawTx = self .nodes [0 ].decoderawtransaction (txDetails ['hex' ])
468
476
vout = next (o for o in rawTx ['vout' ] if o ['value' ] == Decimal ('2.20000000' ))
469
477
470
478
bal = self .nodes [0 ].getbalance ()
471
- inputs = [{ "txid" : txId , "vout" : vout ['n' ], "scriptPubKey" : vout ['scriptPubKey' ]['hex' ], "amount" : vout ['value' ]}]
472
- outputs = { self .nodes [0 ].getnewaddress () : 2.19 }
479
+ inputs = [{"txid" : txId , "vout" : vout ['n' ], "scriptPubKey" : vout ['scriptPubKey' ]['hex' ], "amount" : vout ['value' ]}]
480
+ outputs = {self .nodes [0 ].getnewaddress (): 2.19 }
473
481
rawTx = self .nodes [2 ].createrawtransaction (inputs , outputs )
474
482
rawTxPartialSigned = self .nodes [1 ].signrawtransactionwithwallet (rawTx , inputs )
475
- assert_equal (rawTxPartialSigned ['complete' ], False ) # node1 only has one key, can't comp. sign the tx
483
+ assert_equal (rawTxPartialSigned ['complete' ], False ) # node1 only has one key, can't comp. sign the tx
476
484
477
485
rawTxSigned = self .nodes [2 ].signrawtransactionwithwallet (rawTx , inputs )
478
- assert_equal (rawTxSigned ['complete' ], True ) # node2 can sign the tx compl., own two of three keys
486
+ assert_equal (rawTxSigned ['complete' ], True ) # node2 can sign the tx compl., own two of three keys
479
487
self .nodes [2 ].sendrawtransaction (rawTxSigned ['hex' ])
480
488
rawTx = self .nodes [0 ].decoderawtransaction (rawTxSigned ['hex' ])
481
489
self .sync_all ()
482
490
self .nodes [0 ].generate (1 )
483
491
self .sync_all ()
484
- assert_equal (self .nodes [0 ].getbalance (), bal + Decimal ('50.00000000' )+ Decimal ('2.19000000' )) # block reward + tx
492
+ assert_equal (self .nodes [0 ].getbalance (), bal + Decimal ('50.00000000' ) + Decimal ('2.19000000' )) # block reward + tx
485
493
486
494
# 2of2 test for combining transactions
487
495
bal = self .nodes [2 ].getbalance ()
@@ -502,31 +510,31 @@ def raw_multisig_transaction_legacy_tests(self):
502
510
self .nodes [0 ].generate (1 )
503
511
self .sync_all ()
504
512
505
- assert_equal (self .nodes [2 ].getbalance (), bal ) # the funds of a 2of2 multisig tx should not be marked as spendable
513
+ assert_equal (self .nodes [2 ].getbalance (), bal ) # the funds of a 2of2 multisig tx should not be marked as spendable
506
514
507
515
txDetails = self .nodes [0 ].gettransaction (txId , True )
508
516
rawTx2 = self .nodes [0 ].decoderawtransaction (txDetails ['hex' ])
509
517
vout = next (o for o in rawTx2 ['vout' ] if o ['value' ] == Decimal ('2.20000000' ))
510
518
511
519
bal = self .nodes [0 ].getbalance ()
512
- inputs = [{ "txid" : txId , "vout" : vout ['n' ], "scriptPubKey" : vout ['scriptPubKey' ]['hex' ], "redeemScript" : mSigObjValid ['hex' ], "amount" : vout ['value' ]}]
513
- outputs = { self .nodes [0 ].getnewaddress () : 2.19 }
520
+ inputs = [{"txid" : txId , "vout" : vout ['n' ], "scriptPubKey" : vout ['scriptPubKey' ]['hex' ], "redeemScript" : mSigObjValid ['hex' ], "amount" : vout ['value' ]}]
521
+ outputs = {self .nodes [0 ].getnewaddress (): 2.19 }
514
522
rawTx2 = self .nodes [2 ].createrawtransaction (inputs , outputs )
515
523
rawTxPartialSigned1 = self .nodes [1 ].signrawtransactionwithwallet (rawTx2 , inputs )
516
524
self .log .debug (rawTxPartialSigned1 )
517
- assert_equal (rawTxPartialSigned1 ['complete' ], False ) # node1 only has one key, can't comp. sign the tx
525
+ assert_equal (rawTxPartialSigned1 ['complete' ], False ) # node1 only has one key, can't comp. sign the tx
518
526
519
527
rawTxPartialSigned2 = self .nodes [2 ].signrawtransactionwithwallet (rawTx2 , inputs )
520
528
self .log .debug (rawTxPartialSigned2 )
521
- assert_equal (rawTxPartialSigned2 ['complete' ], False ) # node2 only has one key, can't comp. sign the tx
529
+ assert_equal (rawTxPartialSigned2 ['complete' ], False ) # node2 only has one key, can't comp. sign the tx
522
530
rawTxComb = self .nodes [2 ].combinerawtransaction ([rawTxPartialSigned1 ['hex' ], rawTxPartialSigned2 ['hex' ]])
523
531
self .log .debug (rawTxComb )
524
532
self .nodes [2 ].sendrawtransaction (rawTxComb )
525
533
rawTx2 = self .nodes [0 ].decoderawtransaction (rawTxComb )
526
534
self .sync_all ()
527
535
self .nodes [0 ].generate (1 )
528
536
self .sync_all ()
529
- assert_equal (self .nodes [0 ].getbalance (), bal + Decimal ('50.00000000' )+ Decimal ('2.19000000' )) # block reward + tx
537
+ assert_equal (self .nodes [0 ].getbalance (), bal + Decimal ('50.00000000' ) + Decimal ('2.19000000' )) # block reward + tx
530
538
531
539
532
540
if __name__ == '__main__' :
0 commit comments