Dash Core  0.12.2.1
P2P Digital Currency
fundrawtransaction-hd.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 # Copyright (c) 2014-2015 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 from test_framework.test_framework import BitcoinTestFramework
7 from test_framework.util import *
8 
9 # Create one-input, one-output, no-fee transaction:
11 
12  def setup_chain(self):
13  print("Initializing test directory "+self.options.tmpdir)
14  initialize_chain_clean(self.options.tmpdir, 4)
15 
16  def setup_network(self, split=False):
17  self.nodes = start_nodes(4, self.options.tmpdir, [['-usehd=1'], ['-usehd=1'], ['-usehd=1'], ['-usehd=1']])
18 
19  connect_nodes_bi(self.nodes,0,1)
20  connect_nodes_bi(self.nodes,1,2)
21  connect_nodes_bi(self.nodes,0,2)
22  connect_nodes_bi(self.nodes,0,3)
23 
24  self.is_network_split=False
25  self.sync_all()
26 
27  def run_test(self):
28  print "Mining blocks..."
29 
30  min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
31  # This test is not meant to test fee estimation and we'd like
32  # to be sure all txs are sent at a consistent desired feerate
33  for node in self.nodes:
34  node.settxfee(min_relay_tx_fee)
35 
36  # if the fee's positive delta is higher than this value tests will fail,
37  # neg. delta always fail the tests.
38  # The size of the signature of every input may be at most 2 bytes larger
39  # than a minimum sized signature.
40 
41  # = 2 bytes * minRelayTxFeePerByte
42  feeTolerance = 2 * min_relay_tx_fee/1000
43 
44  self.nodes[2].generate(1)
45  self.sync_all()
46  self.nodes[0].generate(121)
47  self.sync_all()
48 
49  watchonly_address = self.nodes[0].getnewaddress()
50  watchonly_pubkey = self.nodes[0].validateaddress(watchonly_address)["pubkey"]
51  watchonly_amount = Decimal(2000)
52  self.nodes[3].importpubkey(watchonly_pubkey, "", True)
53  watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, watchonly_amount)
54  self.nodes[0].sendtoaddress(self.nodes[3].getnewaddress(), watchonly_amount / 10)
55 
56  self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 15)
57  self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
58  self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 50)
59 
60  self.sync_all()
61  self.nodes[0].generate(1)
62  self.sync_all()
63 
64 
67  inputs = [ ]
68  outputs = { self.nodes[0].getnewaddress() : 10 }
69  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
70  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
71  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
72  fee = rawtxfund['fee']
73  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
74  assert(len(dec_tx['vin']) > 0) #test if we have enought inputs
75 
76 
79  inputs = [ ]
80  outputs = { self.nodes[0].getnewaddress() : 22 }
81  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
82  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
83 
84  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
85  fee = rawtxfund['fee']
86  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
87  assert(len(dec_tx['vin']) > 0) #test if we have enough inputs
88 
89 
92  inputs = [ ]
93  outputs = { self.nodes[0].getnewaddress() : 26 }
94  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
95  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
96 
97  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
98  fee = rawtxfund['fee']
99  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
100  assert(len(dec_tx['vin']) > 0)
101  assert_equal(dec_tx['vin'][0]['scriptSig']['hex'], '')
102 
103 
104 
107  inputs = [ ]
108  outputs = { self.nodes[0].getnewaddress() : 26, self.nodes[1].getnewaddress() : 25 }
109  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
110  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
111 
112  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
113  fee = rawtxfund['fee']
114  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
115  totalOut = 0
116  for out in dec_tx['vout']:
117  totalOut += out['value']
118 
119  assert(len(dec_tx['vin']) > 0)
120  assert_equal(dec_tx['vin'][0]['scriptSig']['hex'], '')
121 
122 
123 
126  utx = False
127  listunspent = self.nodes[2].listunspent()
128  for aUtx in listunspent:
129  if aUtx['amount'] == 50:
130  utx = aUtx
131  break
132 
133  assert(utx!=False)
134 
135  inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
136  outputs = { self.nodes[0].getnewaddress() : 10 }
137  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
138  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
139  assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
140 
141  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
142  fee = rawtxfund['fee']
143  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
144  totalOut = 0
145  for out in dec_tx['vout']:
146  totalOut += out['value']
147 
148  assert_equal(fee + totalOut, utx['amount']) #compare vin total and totalout+fee
149 
150 
151 
154  utx = False
155  listunspent = self.nodes[2].listunspent()
156  for aUtx in listunspent:
157  if aUtx['amount'] == 50:
158  utx = aUtx
159  break
160 
161  assert(utx!=False)
162 
163  inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
164  outputs = { self.nodes[0].getnewaddress() : Decimal(50) - fee - feeTolerance }
165  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
166  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
167  assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
168 
169  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
170  fee = rawtxfund['fee']
171  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
172  totalOut = 0
173  for out in dec_tx['vout']:
174  totalOut += out['value']
175 
176  assert_equal(rawtxfund['changepos'], -1)
177  assert_equal(fee + totalOut, utx['amount']) #compare vin total and totalout+fee
178 
179 
180 
183  utx = False
184  listunspent = self.nodes[2].listunspent()
185  for aUtx in listunspent:
186  if aUtx['amount'] == 10:
187  utx = aUtx
188  break
189 
190  assert(utx!=False)
191 
192  inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']}]
193  outputs = { self.nodes[0].getnewaddress() : 10 }
194  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
195 
196  # 4-byte version + 1-byte vin count + 36-byte prevout then script_len
197  rawtx = rawtx[:82] + "0100" + rawtx[84:]
198 
199  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
200  assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
201  assert_equal("00", dec_tx['vin'][0]['scriptSig']['hex'])
202 
203  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
204  fee = rawtxfund['fee']
205  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
206  totalOut = 0
207  matchingOuts = 0
208  for i, out in enumerate(dec_tx['vout']):
209  totalOut += out['value']
210  if out['scriptPubKey']['addresses'][0] in outputs:
211  matchingOuts+=1
212  else:
213  assert_equal(i, rawtxfund['changepos'])
214 
215  assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
216  assert_equal("00", dec_tx['vin'][0]['scriptSig']['hex'])
217 
218  assert_equal(matchingOuts, 1)
219  assert_equal(len(dec_tx['vout']), 2)
220 
221 
222 
225  utx = False
226  utx2 = False
227  listunspent = self.nodes[2].listunspent()
228  for aUtx in listunspent:
229  if aUtx['amount'] == 10:
230  utx = aUtx
231  if aUtx['amount'] == 50:
232  utx2 = aUtx
233 
234 
235  assert(utx!=False)
236 
237  inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
238  outputs = { self.nodes[0].getnewaddress() : 60 }
239  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
240  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
241  assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
242 
243  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
244  fee = rawtxfund['fee']
245  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
246  totalOut = 0
247  matchingOuts = 0
248  for out in dec_tx['vout']:
249  totalOut += out['value']
250  if out['scriptPubKey']['addresses'][0] in outputs:
251  matchingOuts+=1
252 
253  assert_equal(matchingOuts, 1)
254  assert_equal(len(dec_tx['vout']), 2)
255 
256  matchingIns = 0
257  for vinOut in dec_tx['vin']:
258  for vinIn in inputs:
259  if vinIn['txid'] == vinOut['txid']:
260  matchingIns+=1
261 
262  assert_equal(matchingIns, 2) #we now must see two vins identical to vins given as params
263 
264 
267  utx = False
268  utx2 = False
269  listunspent = self.nodes[2].listunspent()
270  for aUtx in listunspent:
271  if aUtx['amount'] == 10:
272  utx = aUtx
273  if aUtx['amount'] == 50:
274  utx2 = aUtx
275 
276 
277  assert(utx!=False)
278 
279  inputs = [ {'txid' : utx['txid'], 'vout' : utx['vout']},{'txid' : utx2['txid'], 'vout' : utx2['vout']} ]
280  outputs = { self.nodes[0].getnewaddress() : 60, self.nodes[0].getnewaddress() : 10 }
281  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
282  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
283  assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
284 
285  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
286  fee = rawtxfund['fee']
287  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
288  totalOut = 0
289  matchingOuts = 0
290  for out in dec_tx['vout']:
291  totalOut += out['value']
292  if out['scriptPubKey']['addresses'][0] in outputs:
293  matchingOuts+=1
294 
295  assert_equal(matchingOuts, 2)
296  assert_equal(len(dec_tx['vout']), 3)
297 
298 
301  listunspent = self.nodes[2].listunspent()
302  inputs = [ {'txid' : "1c7f966dab21119bac53213a2bc7532bff1fa844c124fd750a7d0b1332440bd1", 'vout' : 0} ] #invalid vin!
303  outputs = { self.nodes[0].getnewaddress() : 10}
304  rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
305  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
306 
307  try:
308  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
309  raise AssertionError("Spent more than available")
310  except JSONRPCException as e:
311  assert("Insufficient" in e.error['message'])
312 
313 
314 
316  inputs = []
317  outputs = {self.nodes[1].getnewaddress():11}
318  rawTx = self.nodes[0].createrawtransaction(inputs, outputs)
319  fundedTx = self.nodes[0].fundrawtransaction(rawTx)
320 
321  #create same transaction over sendtoaddress
322  txId = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 11)
323  signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
324 
325  #compare fee
326  feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
327  assert(feeDelta >= 0 and feeDelta <= feeTolerance)
328 
329 
330 
332  inputs = []
333  outputs = {self.nodes[1].getnewaddress():11,self.nodes[1].getnewaddress():12,self.nodes[1].getnewaddress():1,self.nodes[1].getnewaddress():13,self.nodes[1].getnewaddress():2,self.nodes[1].getnewaddress():3}
334  rawTx = self.nodes[0].createrawtransaction(inputs, outputs)
335  fundedTx = self.nodes[0].fundrawtransaction(rawTx)
336  #create same transaction over sendtoaddress
337  txId = self.nodes[0].sendmany("", outputs)
338  signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
339 
340  #compare fee
341  feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
342  assert(feeDelta >= 0 and feeDelta <= feeTolerance)
343 
344 
345 
346 
348 
349  # create 2of2 addr
350  addr1 = self.nodes[1].getnewaddress()
351  addr2 = self.nodes[1].getnewaddress()
352 
353  addr1Obj = self.nodes[1].validateaddress(addr1)
354  addr2Obj = self.nodes[1].validateaddress(addr2)
355 
356  mSigObj = self.nodes[1].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
357 
358  inputs = []
359  outputs = {mSigObj:11}
360  rawTx = self.nodes[0].createrawtransaction(inputs, outputs)
361  fundedTx = self.nodes[0].fundrawtransaction(rawTx)
362 
363  #create same transaction over sendtoaddress
364  txId = self.nodes[0].sendtoaddress(mSigObj, 11)
365  signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
366 
367  #compare fee
368  feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
369  assert(feeDelta >= 0 and feeDelta <= feeTolerance)
370 
371 
372 
373 
375 
376  # create 4of5 addr
377  addr1 = self.nodes[1].getnewaddress()
378  addr2 = self.nodes[1].getnewaddress()
379  addr3 = self.nodes[1].getnewaddress()
380  addr4 = self.nodes[1].getnewaddress()
381  addr5 = self.nodes[1].getnewaddress()
382 
383  addr1Obj = self.nodes[1].validateaddress(addr1)
384  addr2Obj = self.nodes[1].validateaddress(addr2)
385  addr3Obj = self.nodes[1].validateaddress(addr3)
386  addr4Obj = self.nodes[1].validateaddress(addr4)
387  addr5Obj = self.nodes[1].validateaddress(addr5)
388 
389  mSigObj = self.nodes[1].addmultisigaddress(4, [addr1Obj['pubkey'], addr2Obj['pubkey'], addr3Obj['pubkey'], addr4Obj['pubkey'], addr5Obj['pubkey']])
390 
391  inputs = []
392  outputs = {mSigObj:11}
393  rawTx = self.nodes[0].createrawtransaction(inputs, outputs)
394  fundedTx = self.nodes[0].fundrawtransaction(rawTx)
395 
396  #create same transaction over sendtoaddress
397  txId = self.nodes[0].sendtoaddress(mSigObj, 11)
398  signedFee = self.nodes[0].getrawmempool(True)[txId]['fee']
399 
400  #compare fee
401  feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
402  assert(feeDelta >= 0 and feeDelta <= feeTolerance)
403 
404 
405 
406 
408 
409  # create 2of2 addr
410  addr1 = self.nodes[2].getnewaddress()
411  addr2 = self.nodes[2].getnewaddress()
412 
413  addr1Obj = self.nodes[2].validateaddress(addr1)
414  addr2Obj = self.nodes[2].validateaddress(addr2)
415 
416  mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr2Obj['pubkey']])
417 
418 
419  # send 12 DASH to msig addr
420  txId = self.nodes[0].sendtoaddress(mSigObj, 12)
421  self.sync_all()
422  self.nodes[1].generate(1)
423  self.sync_all()
424 
425  oldBalance = self.nodes[1].getbalance()
426  inputs = []
427  outputs = {self.nodes[1].getnewaddress():11}
428  rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
429  fundedTx = self.nodes[2].fundrawtransaction(rawTx)
430 
431  signedTx = self.nodes[2].signrawtransaction(fundedTx['hex'])
432  txId = self.nodes[2].sendrawtransaction(signedTx['hex'])
433  self.sync_all()
434  self.nodes[1].generate(1)
435  self.sync_all()
436 
437  # make sure funds are received at node1
438  assert_equal(oldBalance+Decimal('11.0000000'), self.nodes[1].getbalance())
439 
440 
442  self.nodes[1].encryptwallet("test")
443  self.nodes.pop(1)
444  stop_nodes(self.nodes)
446 
447  self.nodes = start_nodes(4, self.options.tmpdir, [['-usehd=1'], ['-usehd=1'], ['-usehd=1'], ['-usehd=1']])
448  # This test is not meant to test fee estimation and we'd like
449  # to be sure all txs are sent at a consistent desired feerate
450  for node in self.nodes:
451  node.settxfee(min_relay_tx_fee)
452 
453  connect_nodes_bi(self.nodes,0,1)
454  connect_nodes_bi(self.nodes,1,2)
455  connect_nodes_bi(self.nodes,0,2)
456  connect_nodes_bi(self.nodes,0,3)
457  self.is_network_split=False
458  self.sync_all()
459 
460  # drain the keypool
461  self.nodes[1].getnewaddress()
462  self.nodes[1].getrawchangeaddress()
463  inputs = []
464  outputs = {self.nodes[0].getnewaddress():1.1}
465  rawTx = self.nodes[1].createrawtransaction(inputs, outputs)
466  # fund a transaction that requires a new key for the change output
467  # creating the key must be impossible because the wallet is locked
468  try:
469  fundedTx = self.nodes[1].fundrawtransaction(rawTx)
470  raise AssertionError("Wallet unlocked without passphrase")
471  except JSONRPCException as e:
472  assert('Keypool ran out' in e.error['message'])
473 
474  #refill the keypool
475  self.nodes[1].walletpassphrase("test", 100)
476  self.nodes[1].keypoolrefill(2) #need to refill the keypool to get an internal change address
477  self.nodes[1].walletlock()
478 
479  try:
480  self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 12)
481  raise AssertionError("Wallet unlocked without passphrase")
482  except JSONRPCException as e:
483  assert('walletpassphrase' in e.error['message'])
484 
485  oldBalance = self.nodes[0].getbalance()
486 
487  inputs = []
488  outputs = {self.nodes[0].getnewaddress():11}
489  rawTx = self.nodes[1].createrawtransaction(inputs, outputs)
490  fundedTx = self.nodes[1].fundrawtransaction(rawTx)
491 
492  #now we need to unlock
493  self.nodes[1].walletpassphrase("test", 100)
494  signedTx = self.nodes[1].signrawtransaction(fundedTx['hex'])
495  txId = self.nodes[1].sendrawtransaction(signedTx['hex'])
496  self.sync_all()
497  self.nodes[1].generate(1)
498  self.sync_all()
499 
500  # make sure funds are received at node1
501  assert_equal(oldBalance+Decimal('511.0000000'), self.nodes[0].getbalance())
502 
503 
504 
507 
508  #empty node1, send some small coins from node0 to node1
509  self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True)
510  self.sync_all()
511  self.nodes[0].generate(1)
512  self.sync_all()
513 
514  for i in range(0,20):
515  self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
516  self.sync_all()
517  self.nodes[0].generate(1)
518  self.sync_all()
519 
520  #fund a tx with ~20 small inputs
521  inputs = []
522  outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04}
523  rawTx = self.nodes[1].createrawtransaction(inputs, outputs)
524  fundedTx = self.nodes[1].fundrawtransaction(rawTx)
525 
526  #create same transaction over sendtoaddress
527  txId = self.nodes[1].sendmany("", outputs)
528  signedFee = self.nodes[1].getrawmempool(True)[txId]['fee']
529 
530  #compare fee
531  feeDelta = Decimal(fundedTx['fee']) - Decimal(signedFee)
532  assert(feeDelta >= 0 and feeDelta <= feeTolerance*19) #~19 inputs
533 
534 
535 
538 
539  #again, empty node1, send some small coins from node0 to node1
540  self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True)
541  self.sync_all()
542  self.nodes[0].generate(1)
543  self.sync_all()
544 
545  for i in range(0,20):
546  self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
547  self.sync_all()
548  self.nodes[0].generate(1)
549  self.sync_all()
550 
551  #fund a tx with ~20 small inputs
552  oldBalance = self.nodes[0].getbalance()
553 
554  inputs = []
555  outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04}
556  rawTx = self.nodes[1].createrawtransaction(inputs, outputs)
557  fundedTx = self.nodes[1].fundrawtransaction(rawTx)
558  fundedAndSignedTx = self.nodes[1].signrawtransaction(fundedTx['hex'])
559  txId = self.nodes[1].sendrawtransaction(fundedAndSignedTx['hex'])
560  self.sync_all()
561  self.nodes[0].generate(1)
562  self.sync_all()
563  assert_equal(oldBalance+Decimal('500.19000000'), self.nodes[0].getbalance()) #0.19+block reward
564 
565 
568 
569  rawtx = "0100000000010000000000000000066a047465737400000000"
570  dec_tx = self.nodes[2].decoderawtransaction(rawtx)
571 
572  assert_equal(len(dec_tx['vin']), 0)
573  assert_equal(len(dec_tx['vout']), 1)
574 
575  rawtxfund = self.nodes[2].fundrawtransaction(rawtx)
576  dec_tx = self.nodes[2].decoderawtransaction(rawtxfund['hex'])
577 
578  assert_greater_than(len(dec_tx['vin']), 0) # at least one vin
579  assert_equal(len(dec_tx['vout']), 2) # one change output added
580 
581 
582 
585 
586  inputs = []
587  outputs = {self.nodes[2].getnewaddress() : watchonly_amount / 2}
588  rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
589 
590  result = self.nodes[3].fundrawtransaction(rawtx, True)
591  res_dec = self.nodes[0].decoderawtransaction(result["hex"])
592  assert_equal(len(res_dec["vin"]), 1)
593  assert_equal(res_dec["vin"][0]["txid"], watchonly_txid)
594 
595  assert("fee" in result.keys())
596  assert_greater_than(result["changepos"], -1)
597 
598 
601 
602  inputs = []
603  outputs = {self.nodes[2].getnewaddress() : watchonly_amount}
604  rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
605 
606  result = self.nodes[3].fundrawtransaction(rawtx, True)
607  res_dec = self.nodes[0].decoderawtransaction(result["hex"])
608  assert_equal(len(res_dec["vin"]), 2)
609  assert(res_dec["vin"][0]["txid"] == watchonly_txid or res_dec["vin"][1]["txid"] == watchonly_txid)
610 
611  assert_greater_than(result["fee"], 0)
612  assert_greater_than(result["changepos"], -1)
613  assert_equal(result["fee"] + res_dec["vout"][result["changepos"]]["value"], watchonly_amount / 10)
614 
615  signedtx = self.nodes[3].signrawtransaction(result["hex"])
616  assert(not signedtx["complete"])
617  signedtx = self.nodes[0].signrawtransaction(signedtx["hex"])
618  assert(signedtx["complete"])
619  self.nodes[0].sendrawtransaction(signedtx["hex"])
620 
621 
622 if __name__ == '__main__':
def wait_bitcoinds()
Definition: util.py:337
UniValue getrawchangeaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:224
UniValue addmultisigaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1151
UniValue walletpassphrase(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2007
UniValue importpubkey(const UniValue &params, bool fHelp)
Definition: rpcdump.cpp:247
UniValue keypoolrefill(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1963
UniValue validateaddress(const UniValue &params, bool fHelp)
Definition: misc.cpp:270
def assert_greater_than(thing1, thing2)
Definition: util.py:465
UniValue getbalance(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:792
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
Definition: util.py:305
UniValue sendmany(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:1024
UniValue listunspent(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2533
UniValue sendtoaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:409
UniValue getnewaddress(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:113
def initialize_chain_clean(test_dir, num_nodes)
Definition: util.py:252
UniValue signrawtransaction(const UniValue &params, bool fHelp)
UniValue createrawtransaction(const UniValue &params, bool fHelp)
UniValue decoderawtransaction(const UniValue &params, bool fHelp)
UniValue encryptwallet(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2159
def stop_nodes(nodes)
Definition: util.py:328
UniValue generate(const UniValue &params, bool fHelp)
Definition: mining.cpp:122
UniValue sendrawtransaction(const UniValue &params, bool fHelp)
UniValue getrawmempool(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:234
UniValue getnetworkinfo(const UniValue &params, bool fHelp)
Definition: net.cpp:392
def assert_equal(thing1, thing2)
Definition: util.py:461
def connect_nodes_bi(nodes, a, b)
Definition: util.py:351
UniValue walletlock(const UniValue &params, bool fHelp)
Definition: rpcwallet.cpp:2120