19
19
NORMAL_GBT_REQUEST_PARAMS ,
20
20
add_witness_commitment ,
21
21
create_block ,
22
- create_transaction ,
23
22
)
24
- from test_framework .messages import CTransaction
23
+ from test_framework .messages import (
24
+ CTransaction ,
25
+ tx_from_hex ,
26
+ )
25
27
from test_framework .script import (
26
28
OP_0 ,
27
29
OP_TRUE ,
31
33
assert_equal ,
32
34
assert_raises_rpc_error ,
33
35
)
36
+ from test_framework .wallet import getnewdestination
37
+ from test_framework .key import ECKey
38
+ from test_framework .wallet_util import bytes_to_wif
34
39
35
40
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
36
41
@@ -55,22 +60,26 @@ def set_test_params(self):
55
60
'-par=1' , # Use only one script thread to get the exact reject reason for testing
56
61
]]
57
62
58
- def skip_test_if_missing_module (self ):
59
- self .skip_if_no_wallet ()
63
+ def create_transaction (self , * , txid , input_details = None , addr , amount , privkey ):
64
+ input = {"txid" : txid , "vout" : 0 }
65
+ output = {addr : amount }
66
+ rawtx = self .nodes [0 ].createrawtransaction ([input ], output )
67
+ # Details only needed for scripthash or witness spends
68
+ input = None if not input_details else [{** input , ** input_details }]
69
+ signedtx = self .nodes [0 ].signrawtransactionwithkey (rawtx , [privkey ], input )
70
+ return tx_from_hex (signedtx ["hex" ])
60
71
61
72
def run_test (self ):
62
- self .nodes [0 ].createwallet (wallet_name = 'wmulti' , disable_private_keys = True )
63
- wmulti = self .nodes [0 ].get_wallet_rpc ('wmulti' )
64
- w0 = self .nodes [0 ].get_wallet_rpc (self .default_wallet_name )
65
- self .address = w0 .getnewaddress ()
66
- self .pubkey = w0 .getaddressinfo (self .address )['pubkey' ]
67
- self .ms_address = wmulti .addmultisigaddress (1 , [self .pubkey ])['address' ]
68
- self .wit_address = w0 .getnewaddress (address_type = 'p2sh-segwit' )
69
- self .wit_ms_address = wmulti .addmultisigaddress (1 , [self .pubkey ], '' , 'p2sh-segwit' )['address' ]
70
- if not self .options .descriptors :
71
- # 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
72
- wmulti .importaddress (self .ms_address )
73
- wmulti .importaddress (self .wit_ms_address )
73
+ eckey = ECKey ()
74
+ eckey .generate ()
75
+ self .privkey = bytes_to_wif (eckey .get_bytes ())
76
+ self .pubkey = eckey .get_pubkey ().get_bytes ().hex ()
77
+ cms = self .nodes [0 ].createmultisig (1 , [self .pubkey ])
78
+ wms = self .nodes [0 ].createmultisig (1 , [self .pubkey ], 'p2sh-segwit' )
79
+ self .ms_address = cms ["address" ]
80
+ ms_unlock_details = {"scriptPubKey" : self .nodes [0 ].validateaddress (self .ms_address )["scriptPubKey" ],
81
+ "redeemScript" : cms ["redeemScript" ]}
82
+ self .wit_ms_address = wms ['address' ]
74
83
75
84
self .coinbase_blocks = self .generate (self .nodes [0 ], 2 ) # block height = 2
76
85
coinbase_txid = []
@@ -82,31 +91,43 @@ def run_test(self):
82
91
self .lastblocktime = int (time .time ()) + self .lastblockheight
83
92
84
93
self .log .info (f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{ COINBASE_MATURITY + 3 } ]" )
85
- test1txs = [create_transaction (self .nodes [0 ], coinbase_txid [0 ], self .ms_address , amount = 49 )]
94
+ test1txs = [self .create_transaction (txid = coinbase_txid [0 ], addr = self .ms_address , amount = 49 ,
95
+ privkey = self .nodes [0 ].get_deterministic_priv_key ().key )]
86
96
txid1 = self .nodes [0 ].sendrawtransaction (test1txs [0 ].serialize_with_witness ().hex (), 0 )
87
- test1txs .append (create_transaction (self .nodes [0 ], txid1 , self .ms_address , amount = 48 ))
97
+ test1txs .append (self .create_transaction (txid = txid1 , input_details = ms_unlock_details ,
98
+ addr = self .ms_address , amount = 48 ,
99
+ privkey = self .privkey ))
88
100
txid2 = self .nodes [0 ].sendrawtransaction (test1txs [1 ].serialize_with_witness ().hex (), 0 )
89
- test1txs .append (create_transaction (self .nodes [0 ], coinbase_txid [1 ], self .wit_ms_address , amount = 49 ))
101
+ test1txs .append (self .create_transaction (txid = coinbase_txid [1 ],
102
+ addr = self .wit_ms_address , amount = 49 ,
103
+ privkey = self .nodes [0 ].get_deterministic_priv_key ().key ))
90
104
txid3 = self .nodes [0 ].sendrawtransaction (test1txs [2 ].serialize_with_witness ().hex (), 0 )
91
105
self .block_submit (self .nodes [0 ], test1txs , accept = True )
92
106
93
107
self .log .info ("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation" )
94
- test2tx = create_transaction (self .nodes [0 ], txid2 , self .ms_address , amount = 47 )
108
+ test2tx = self .create_transaction (txid = txid2 , input_details = ms_unlock_details ,
109
+ addr = self .ms_address , amount = 47 ,
110
+ privkey = self .privkey )
95
111
invalidate_nulldummy_tx (test2tx )
96
112
assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test2tx .serialize_with_witness ().hex (), 0 )
97
113
98
114
self .log .info (f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{ COINBASE_MATURITY + 4 } ]" )
99
115
self .block_submit (self .nodes [0 ], [test2tx ], accept = True )
100
116
101
117
self .log .info ("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation" )
102
- test4tx = create_transaction (self .nodes [0 ], test2tx .hash , self .address , amount = 46 )
118
+ test4tx = self .create_transaction (txid = test2tx .hash , input_details = ms_unlock_details ,
119
+ addr = getnewdestination ()[2 ], amount = 46 ,
120
+ privkey = self .privkey )
103
121
test6txs = [CTransaction (test4tx )]
104
122
invalidate_nulldummy_tx (test4tx )
105
123
assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test4tx .serialize_with_witness ().hex (), 0 )
106
124
self .block_submit (self .nodes [0 ], [test4tx ], accept = False )
107
125
108
126
self .log .info ("Test 5: Non-NULLDUMMY P2WSH multisig transaction invalid after activation" )
109
- test5tx = create_transaction (self .nodes [0 ], txid3 , self .wit_address , amount = 48 )
127
+ test5tx = self .create_transaction (txid = txid3 , input_details = {"scriptPubKey" : test1txs [2 ].vout [0 ].scriptPubKey .hex (),
128
+ "amount" : 49 , "witnessScript" : wms ["redeemScript" ]},
129
+ addr = getnewdestination (address_type = 'p2sh-segwit' )[2 ], amount = 48 ,
130
+ privkey = self .privkey )
110
131
test6txs .append (CTransaction (test5tx ))
111
132
test5tx .wit .vtxinwit [0 ].scriptWitness .stack [0 ] = b'\x01 '
112
133
assert_raises_rpc_error (- 26 , NULLDUMMY_ERROR , self .nodes [0 ].sendrawtransaction , test5tx .serialize_with_witness ().hex (), 0 )
0 commit comments