Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_listsinceblock.py
Show All 31 Lines | def run_test(self): | ||||
self.test_no_blockhash() | self.test_no_blockhash() | ||||
self.test_invalid_blockhash() | self.test_invalid_blockhash() | ||||
self.test_reorg() | self.test_reorg() | ||||
self.test_double_spend() | self.test_double_spend() | ||||
self.test_double_send() | self.test_double_send() | ||||
def test_no_blockhash(self): | def test_no_blockhash(self): | ||||
self.log.info("Test no blockhash") | self.log.info("Test no blockhash") | ||||
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1) | txid = self.nodes[2].sendtoaddress( | ||||
self.nodes[0].getnewaddress(), 1000000) | |||||
blockhash, = self.nodes[2].generate(1) | blockhash, = self.nodes[2].generate(1) | ||||
blockheight = self.nodes[2].getblockheader(blockhash)['height'] | blockheight = self.nodes[2].getblockheader(blockhash)['height'] | ||||
self.sync_all() | self.sync_all() | ||||
txs = self.nodes[0].listtransactions() | txs = self.nodes[0].listtransactions() | ||||
assert_array_result(txs, {"txid": txid}, { | assert_array_result(txs, {"txid": txid}, { | ||||
"category": "receive", | "category": "receive", | ||||
"amount": 1, | "amount": 1000000, | ||||
"blockhash": blockhash, | "blockhash": blockhash, | ||||
"blockheight": blockheight, | "blockheight": blockheight, | ||||
"confirmations": 1, | "confirmations": 1, | ||||
}) | }) | ||||
assert_equal( | assert_equal( | ||||
self.nodes[0].listsinceblock(), | self.nodes[0].listsinceblock(), | ||||
{"lastblock": blockhash, | {"lastblock": blockhash, | ||||
"removed": [], | "removed": [], | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def test_reorg(self): | ||||
This test only checks that [tx0] is present. | This test only checks that [tx0] is present. | ||||
''' | ''' | ||||
self.log.info("Test reorg") | self.log.info("Test reorg") | ||||
# Split network into two | # Split network into two | ||||
self.split_network() | self.split_network() | ||||
# send to nodes[0] from nodes[2] | # send to nodes[0] from nodes[2] | ||||
senttx = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1) | senttx = self.nodes[2].sendtoaddress( | ||||
self.nodes[0].getnewaddress(), 1000000) | |||||
# generate on both sides | # generate on both sides | ||||
nodes1_last_blockhash = self.nodes[1].generate(6)[-1] | nodes1_last_blockhash = self.nodes[1].generate(6)[-1] | ||||
nodes2_first_blockhash = self.nodes[2].generate(7)[0] | nodes2_first_blockhash = self.nodes[2].generate(7)[0] | ||||
self.log.debug( | self.log.debug( | ||||
"nodes[1] last blockhash = {}".format(nodes1_last_blockhash)) | "nodes[1] last blockhash = {}".format(nodes1_last_blockhash)) | ||||
self.log.debug( | self.log.debug( | ||||
"nodes[2] first blockhash = {}".format(nodes2_first_blockhash)) | "nodes[2] first blockhash = {}".format(nodes2_first_blockhash)) | ||||
▲ Show 20 Lines • Show All 51 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 = '{:.2f}'.format(float(utxo['amount']) - 1000300.00) | ||||
recipient_dict = { | recipient_dict = { | ||||
self.nodes[0].getnewaddress(): 1, | self.nodes[0].getnewaddress(): 1000000, | ||||
self.nodes[1].getnewaddress(): change, | self.nodes[1].getnewaddress(): change, | ||||
} | } | ||||
utxo_dicts = [{ | 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(utxo_dicts, recipient_dict))['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] | ||||
recipient_dict2 = { | recipient_dict2 = { | ||||
self.nodes[3].getnewaddress(): 1, | self.nodes[3].getnewaddress(): 1000000, | ||||
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(utxo_dicts, recipient_dict2))['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] | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | def test_double_send(self): | ||||
self.sync_all() | self.sync_all() | ||||
# 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 = '{:.2f}'.format(float(utxo['amount']) - 1000300.00) | ||||
recipient_dict = { | recipient_dict = { | ||||
self.nodes[0].getnewaddress(): 1, | self.nodes[0].getnewaddress(): 1000000, | ||||
self.nodes[2].getnewaddress(): change, | self.nodes[2].getnewaddress(): change, | ||||
} | } | ||||
utxo_dicts = [{ | 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(utxo_dicts, recipient_dict)) | self.nodes[2].createrawtransaction(utxo_dicts, recipient_dict)) | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |