Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_listsinceblock.py
Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | def test_double_spend(self): | ||||
# share utxo between nodes[1] and nodes[2] | # share utxo between nodes[1] and nodes[2] | ||||
utxos = self.nodes[2].listunspent() | utxos = self.nodes[2].listunspent() | ||||
utxo = utxos[0] | utxo = utxos[0] | ||||
privkey = self.nodes[2].dumpprivkey(utxo['address']) | privkey = self.nodes[2].dumpprivkey(utxo['address']) | ||||
self.nodes[1].importprivkey(privkey) | self.nodes[1].importprivkey(privkey) | ||||
# send from nodes[1] using utxo to nodes[0] | # send from nodes[1] using utxo to nodes[0] | ||||
change = '{:.8f}'.format(float(utxo['amount']) - 1.0003) | change = '{:.8f}'.format(float(utxo['amount']) - 1.0003) | ||||
recipientDict = { | recipient_dict = { | ||||
self.nodes[0].getnewaddress(): 1, | self.nodes[0].getnewaddress(): 1, | ||||
self.nodes[1].getnewaddress(): change, | self.nodes[1].getnewaddress(): change, | ||||
} | } | ||||
utxoDicts = [{ | utxo_dicts = [{ | ||||
'txid': utxo['txid'], | 'txid': utxo['txid'], | ||||
'vout': utxo['vout'], | 'vout': utxo['vout'], | ||||
}] | }] | ||||
txid1 = self.nodes[1].sendrawtransaction( | txid1 = self.nodes[1].sendrawtransaction( | ||||
self.nodes[1].signrawtransactionwithwallet( | self.nodes[1].signrawtransactionwithwallet( | ||||
self.nodes[1].createrawtransaction(utxoDicts, recipientDict))['hex']) | self.nodes[1].createrawtransaction(utxo_dicts, recipient_dict))['hex']) | ||||
# send from nodes[2] using utxo to nodes[3] | # send from nodes[2] using utxo to nodes[3] | ||||
recipientDict2 = { | recipient_dict2 = { | ||||
self.nodes[3].getnewaddress(): 1, | self.nodes[3].getnewaddress(): 1, | ||||
self.nodes[2].getnewaddress(): change, | self.nodes[2].getnewaddress(): change, | ||||
} | } | ||||
self.nodes[2].sendrawtransaction( | self.nodes[2].sendrawtransaction( | ||||
self.nodes[2].signrawtransactionwithwallet( | self.nodes[2].signrawtransactionwithwallet( | ||||
self.nodes[2].createrawtransaction(utxoDicts, recipientDict2))['hex']) | self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict2))['hex']) | ||||
# generate on both sides | # generate on both sides | ||||
lastblockhash = self.nodes[1].generate(3)[2] | lastblockhash = self.nodes[1].generate(3)[2] | ||||
self.nodes[2].generate(4) | self.nodes[2].generate(4) | ||||
self.join_network() | self.join_network() | ||||
self.sync_all() | self.sync_all() | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def test_double_send(self): | ||||
# Split network into two | # Split network into two | ||||
self.split_network() | self.split_network() | ||||
# create and sign a transaction | # create and sign a transaction | ||||
utxos = self.nodes[2].listunspent() | utxos = self.nodes[2].listunspent() | ||||
utxo = utxos[0] | utxo = utxos[0] | ||||
change = '{:.8f}'.format(float(utxo['amount']) - 1.0003) | change = '{:.8f}'.format(float(utxo['amount']) - 1.0003) | ||||
recipientDict = { | recipient_dict = { | ||||
self.nodes[0].getnewaddress(): 1, | self.nodes[0].getnewaddress(): 1, | ||||
self.nodes[2].getnewaddress(): change, | self.nodes[2].getnewaddress(): change, | ||||
} | } | ||||
utxoDicts = [{ | utxo_dicts = [{ | ||||
'txid': utxo['txid'], | 'txid': utxo['txid'], | ||||
'vout': utxo['vout'], | 'vout': utxo['vout'], | ||||
}] | }] | ||||
signedtxres = self.nodes[2].signrawtransactionwithwallet( | signedtxres = self.nodes[2].signrawtransactionwithwallet( | ||||
self.nodes[2].createrawtransaction(utxoDicts, recipientDict)) | self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict)) | ||||
assert signedtxres['complete'] | assert signedtxres['complete'] | ||||
signedtx = signedtxres['hex'] | signedtx = signedtxres['hex'] | ||||
# send from nodes[1]; this will end up in aa1 | # send from nodes[1]; this will end up in aa1 | ||||
txid1 = self.nodes[1].sendrawtransaction(signedtx) | txid1 = self.nodes[1].sendrawtransaction(signedtx) | ||||
# generate bb1-bb2 on right side | # generate bb1-bb2 on right side | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |