1717 COINBASE_MATURITY ,
1818 NORMAL_GBT_REQUEST_PARAMS ,
1919 create_block ,
20- create_transaction ,
2120)
22- from test_framework .messages import CTransaction
21+ from test_framework .messages import (
22+ CTransaction ,
23+ tx_from_hex ,
24+ )
2325from test_framework .script import (
2426 OP_0 ,
2527 OP_TRUE ,
2931 assert_equal ,
3032 assert_raises_rpc_error ,
3133)
34+ from test_framework .wallet import getnewdestination
35+ from test_framework .key import ECKey
36+ from test_framework .wallet_util import bytes_to_wif
3237
3338NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
3439
@@ -52,19 +57,24 @@ def set_test_params(self):
5257 '-par=1' , # Use only one script thread to get the exact reject reason for testing
5358 ]]
5459
55- def skip_test_if_missing_module (self ):
56- self .skip_if_no_wallet ()
60+ def create_transaction (self , * , txid , input_details = None , addr , amount , privkey ):
61+ input = {"txid" : txid , "vout" : 0 }
62+ output = {addr : amount }
63+ rawtx = self .nodes [0 ].createrawtransaction ([input ], output )
64+ # Details only needed for scripthash or witness spends
65+ input = None if not input_details else [{** input , ** input_details }]
66+ signedtx = self .nodes [0 ].signrawtransactionwithkey (rawtx , [privkey ], input )
67+ return tx_from_hex (signedtx ["hex" ])
5768
5869 def run_test (self ):
59- self .nodes [0 ].createwallet (wallet_name = 'wmulti' , disable_private_keys = True )
60- wmulti = self .nodes [0 ].get_wallet_rpc ('wmulti' )
61- w0 = self .nodes [0 ].get_wallet_rpc (self .default_wallet_name )
62- self .address = w0 .getnewaddress ()
63- self .pubkey = w0 .getaddressinfo (self .address )['pubkey' ]
64- self .ms_address = wmulti .addmultisigaddress (1 , [self .pubkey ])['address' ]
65- if not self .options .descriptors :
66- # Legacy wallets need to import these so that they are watched by the wallet. This is unnecessary (and does not need to be tested) for descriptor wallets
67- wmulti .importaddress (self .ms_address )
70+ eckey = ECKey ()
71+ eckey .generate ()
72+ self .privkey = bytes_to_wif (eckey .get_bytes ())
73+ self .pubkey = eckey .get_pubkey ().get_bytes ().hex ()
74+ cms = self .nodes [0 ].createmultisig (1 , [self .pubkey ])
75+ self .ms_address = cms ["address" ]
76+ ms_unlock_details = {"scriptPubKey" : self .nodes [0 ].validateaddress (self .ms_address )["scriptPubKey" ],
77+ "redeemScript" : cms ["redeemScript" ]}
6878
6979 self .coinbase_blocks = self .generate (self .nodes [0 ], 2 ) # block height = 2
7080 coinbase_txid = []
@@ -76,23 +86,30 @@ def run_test(self):
7686 self .lastblocktime = self .mocktime + self .lastblockheight
7787
7888 self .log .info (f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{ COINBASE_MATURITY + 3 } ]" )
79- test1txs = [create_transaction (self .nodes [0 ], coinbase_txid [0 ], self .ms_address , amount = 49 )]
89+ test1txs = [self .create_transaction (txid = coinbase_txid [0 ], addr = self .ms_address , amount = 49 ,
90+ privkey = self .nodes [0 ].get_deterministic_priv_key ().key )]
8091 txid1 = self .nodes [0 ].sendrawtransaction (test1txs [0 ].serialize ().hex (), 0 )
81- test1txs .append (create_transaction (self .nodes [0 ], txid1 , self .ms_address , amount = 48 ))
92+ test1txs .append (self .create_transaction (txid = txid1 , input_details = ms_unlock_details ,
93+ addr = self .ms_address , amount = 48 ,
94+ privkey = self .privkey ))
8295 txid2 = self .nodes [0 ].sendrawtransaction (test1txs [1 ].serialize ().hex (), 0 )
8396 self .block_submit (self .nodes [0 ], test1txs , accept = True )
8497
8598 self .log .info ("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation" )
86- test2tx = create_transaction (self .nodes [0 ], txid2 , self .ms_address , amount = 47 )
99+ test2tx = self .create_transaction (txid = txid2 , input_details = ms_unlock_details ,
100+ addr = self .ms_address , amount = 47 ,
101+ privkey = self .privkey )
87102 invalidate_nulldummy_tx (test2tx )
88103 assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test2tx .serialize ().hex (), 0 )
89104
90105 self .log .info (f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{ COINBASE_MATURITY + 4 } ]" )
91106 self .block_submit (self .nodes [0 ], [test2tx ], accept = True )
92107
93108 self .log .info ("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation" )
94- test4tx = create_transaction (self .nodes [0 ], test2tx .hash , self .address , amount = 46 )
95- test6txs = [CTransaction (test4tx )]
109+ test4tx = self .create_transaction (txid = test2tx .hash , input_details = ms_unlock_details ,
110+ addr = getnewdestination ()[2 ], amount = 46 ,
111+ privkey = self .privkey )
112+ test6txs = [CTransaction (test4tx )]
96113 invalidate_nulldummy_tx (test4tx )
97114 assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test4tx .serialize ().hex (), 0 )
98115 self .block_submit (self .nodes [0 ], [test4tx ], accept = False )
0 commit comments