28
28
)
29
29
30
30
31
+ TXID = "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000"
32
+
33
+
31
34
class multidict (dict ):
32
35
"""Dictionary that allows duplicate keys.
33
36
@@ -96,24 +99,23 @@ def run_test(self):
96
99
assert_raises_rpc_error (- 1 , "createrawtransaction" , self .nodes [0 ].createrawtransaction , [], {}, 0 , False , 'foo' )
97
100
98
101
# Test `createrawtransaction` invalid `inputs`
99
- txid = '1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000'
100
102
assert_raises_rpc_error (- 3 , "Expected type array" , self .nodes [0 ].createrawtransaction , 'foo' , {})
101
103
assert_raises_rpc_error (- 1 , "JSON value is not an object as expected" , self .nodes [0 ].createrawtransaction , ['foo' ], {})
102
104
assert_raises_rpc_error (- 1 , "JSON value is not a string as expected" , self .nodes [0 ].createrawtransaction , [{}], {})
103
105
assert_raises_rpc_error (- 8 , "txid must be of length 64 (not 3, for 'foo')" , self .nodes [0 ].createrawtransaction , [{'txid' : 'foo' }], {})
104
106
assert_raises_rpc_error (- 8 , "txid must be hexadecimal string (not 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844')" , self .nodes [0 ].createrawtransaction , [{'txid' : 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844' }], {})
105
- assert_raises_rpc_error (- 8 , "Invalid parameter, missing vout key" , self .nodes [0 ].createrawtransaction , [{'txid' : txid }], {})
106
- assert_raises_rpc_error (- 8 , "Invalid parameter, missing vout key" , self .nodes [0 ].createrawtransaction , [{'txid' : txid , 'vout' : 'foo' }], {})
107
- assert_raises_rpc_error (- 8 , "Invalid parameter, vout cannot be negative" , self .nodes [0 ].createrawtransaction , [{'txid' : txid , 'vout' : - 1 }], {})
107
+ assert_raises_rpc_error (- 8 , "Invalid parameter, missing vout key" , self .nodes [0 ].createrawtransaction , [{'txid' : TXID }], {})
108
+ assert_raises_rpc_error (- 8 , "Invalid parameter, missing vout key" , self .nodes [0 ].createrawtransaction , [{'txid' : TXID , 'vout' : 'foo' }], {})
109
+ assert_raises_rpc_error (- 8 , "Invalid parameter, vout cannot be negative" , self .nodes [0 ].createrawtransaction , [{'txid' : TXID , 'vout' : - 1 }], {})
108
110
# sequence number out of range
109
111
for invalid_seq in [- 1 , 4294967296 ]:
110
- inputs = [{'txid' : txid , 'vout' : 1 , 'sequence' : invalid_seq }]
112
+ inputs = [{'txid' : TXID , 'vout' : 1 , 'sequence' : invalid_seq }]
111
113
outputs = {self .nodes [0 ].getnewaddress (): 1 }
112
114
assert_raises_rpc_error (- 8 , 'Invalid parameter, sequence number is out of range' ,
113
115
self .nodes [0 ].createrawtransaction , inputs , outputs )
114
116
# with valid sequence number
115
117
for valid_seq in [1000 , 4294967294 ]:
116
- inputs = [{'txid' : txid , 'vout' : 1 , 'sequence' : valid_seq }]
118
+ inputs = [{'txid' : TXID , 'vout' : 1 , 'sequence' : valid_seq }]
117
119
outputs = {self .nodes [0 ].getnewaddress (): 1 }
118
120
rawtx = self .nodes [0 ].createrawtransaction (inputs , outputs )
119
121
decrawtx = self .nodes [0 ].decoderawtransaction (rawtx )
@@ -146,25 +148,25 @@ def run_test(self):
146
148
147
149
self .log .info ('Check that createrawtransaction accepts an array and object as outputs' )
148
150
# One output
149
- tx = tx_from_hex (self .nodes [2 ].createrawtransaction (inputs = [{'txid' : txid , 'vout' : 9 }], outputs = {address : 99 }))
151
+ tx = tx_from_hex (self .nodes [2 ].createrawtransaction (inputs = [{'txid' : TXID , 'vout' : 9 }], outputs = {address : 99 }))
150
152
assert_equal (len (tx .vout ), 1 )
151
153
assert_equal (
152
154
tx .serialize ().hex (),
153
- self .nodes [2 ].createrawtransaction (inputs = [{'txid' : txid , 'vout' : 9 }], outputs = [{address : 99 }]),
155
+ self .nodes [2 ].createrawtransaction (inputs = [{'txid' : TXID , 'vout' : 9 }], outputs = [{address : 99 }]),
154
156
)
155
157
# Two outputs
156
- tx = tx_from_hex (self .nodes [2 ].createrawtransaction (inputs = [{'txid' : txid , 'vout' : 9 }], outputs = OrderedDict ([(address , 99 ), (address2 , 99 )])))
158
+ tx = tx_from_hex (self .nodes [2 ].createrawtransaction (inputs = [{'txid' : TXID , 'vout' : 9 }], outputs = OrderedDict ([(address , 99 ), (address2 , 99 )])))
157
159
assert_equal (len (tx .vout ), 2 )
158
160
assert_equal (
159
161
tx .serialize ().hex (),
160
- self .nodes [2 ].createrawtransaction (inputs = [{'txid' : txid , 'vout' : 9 }], outputs = [{address : 99 }, {address2 : 99 }]),
162
+ self .nodes [2 ].createrawtransaction (inputs = [{'txid' : TXID , 'vout' : 9 }], outputs = [{address : 99 }, {address2 : 99 }]),
161
163
)
162
164
# Multiple mixed outputs
163
- tx = tx_from_hex (self .nodes [2 ].createrawtransaction (inputs = [{'txid' : txid , 'vout' : 9 }], outputs = multidict ([(address , 99 ), (address2 , 99 ), ('data' , '99' )])))
165
+ tx = tx_from_hex (self .nodes [2 ].createrawtransaction (inputs = [{'txid' : TXID , 'vout' : 9 }], outputs = multidict ([(address , 99 ), (address2 , 99 ), ('data' , '99' )])))
164
166
assert_equal (len (tx .vout ), 3 )
165
167
assert_equal (
166
168
tx .serialize ().hex (),
167
- self .nodes [2 ].createrawtransaction (inputs = [{'txid' : txid , 'vout' : 9 }], outputs = [{address : 99 }, {address2 : 99 }, {'data' : '99' }]),
169
+ self .nodes [2 ].createrawtransaction (inputs = [{'txid' : TXID , 'vout' : 9 }], outputs = [{address : 99 }, {address2 : 99 }, {'data' : '99' }]),
168
170
)
169
171
170
172
for type in ["bech32" , "p2sh-segwit" , "legacy" ]:
@@ -175,11 +177,11 @@ def run_test(self):
175
177
self .log .info ('sendrawtransaction with missing prevtx info (%s)' % (type ))
176
178
177
179
# Test `signrawtransactionwithwallet` invalid `prevtxs`
178
- inputs = [ {'txid' : txid , 'vout' : 3 , 'sequence' : 1000 }]
180
+ inputs = [ {'txid' : TXID , 'vout' : 3 , 'sequence' : 1000 }]
179
181
outputs = { self .nodes [0 ].getnewaddress () : 1 }
180
182
rawtx = self .nodes [0 ].createrawtransaction (inputs , outputs )
181
183
182
- prevtx = dict (txid = txid , scriptPubKey = pubkey , vout = 3 , amount = 1 )
184
+ prevtx = dict (txid = TXID , scriptPubKey = pubkey , vout = 3 , amount = 1 )
183
185
succ = self .nodes [0 ].signrawtransactionwithwallet (rawtx , [prevtx ])
184
186
assert succ ["complete" ]
185
187
if type == "legacy" :
@@ -190,15 +192,15 @@ def run_test(self):
190
192
if type != "legacy" :
191
193
assert_raises_rpc_error (- 3 , "Missing amount" , self .nodes [0 ].signrawtransactionwithwallet , rawtx , [
192
194
{
193
- "txid" : txid ,
195
+ "txid" : TXID ,
194
196
"scriptPubKey" : pubkey ,
195
197
"vout" : 3 ,
196
198
}
197
199
])
198
200
199
201
assert_raises_rpc_error (- 3 , "Missing vout" , self .nodes [0 ].signrawtransactionwithwallet , rawtx , [
200
202
{
201
- "txid" : txid ,
203
+ "txid" : TXID ,
202
204
"scriptPubKey" : pubkey ,
203
205
"amount" : 1 ,
204
206
}
@@ -212,7 +214,7 @@ def run_test(self):
212
214
])
213
215
assert_raises_rpc_error (- 3 , "Missing scriptPubKey" , self .nodes [0 ].signrawtransactionwithwallet , rawtx , [
214
216
{
215
- "txid" : txid ,
217
+ "txid" : TXID ,
216
218
"vout" : 3 ,
217
219
"amount" : 1
218
220
}
@@ -223,7 +225,7 @@ def run_test(self):
223
225
#########################################
224
226
225
227
self .log .info ('sendrawtransaction with missing input' )
226
- inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000" , 'vout' : 1 }] # won't exists
228
+ inputs = [{'txid' : TXID , 'vout' : 1 }] # won't exist
227
229
outputs = { self .nodes [0 ].getnewaddress () : 4.998 }
228
230
rawtx = self .nodes [2 ].createrawtransaction (inputs , outputs )
229
231
rawtx = self .nodes [2 ].signrawtransactionwithwallet (rawtx )
0 commit comments