2016-05-06 11:23:48 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
2014-11-19 21:55:40 +01:00
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2019-01-07 10:55:35 +01:00
|
|
|
"""Test the wallet."""
|
2015-05-02 12:53:35 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import *
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2017-04-29 14:47:00 +02:00
|
|
|
class WalletTest(BitcoinTestFramework):
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2015-09-21 12:49:13 +02:00
|
|
|
def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
|
|
|
|
"""Return curr_balance after asserting the fee was in range"""
|
|
|
|
fee = balance_with_fee - curr_balance
|
2016-06-14 08:23:31 +02:00
|
|
|
assert_fee_amount(fee, tx_size, fee_per_byte * 1000)
|
2015-09-21 12:49:13 +02:00
|
|
|
return curr_balance
|
|
|
|
|
2016-05-20 15:16:51 +02:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
self.num_nodes = 4
|
2016-09-19 15:44:38 +02:00
|
|
|
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2017-05-02 20:02:55 +02:00
|
|
|
def setup_network(self):
|
2018-01-11 14:47:10 +01:00
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir, self.extra_args[:3], redirect_stderr=True)
|
2014-11-19 21:55:40 +01:00
|
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
|
|
connect_nodes_bi(self.nodes,1,2)
|
|
|
|
connect_nodes_bi(self.nodes,0,2)
|
|
|
|
self.sync_all()
|
|
|
|
|
2017-04-29 14:47:00 +02:00
|
|
|
def run_test(self):
|
2016-04-19 13:22:11 +02:00
|
|
|
|
|
|
|
# Check that there's no UTXO on none of the nodes
|
|
|
|
assert_equal(len(self.nodes[0].listunspent()), 0)
|
|
|
|
assert_equal(len(self.nodes[1].listunspent()), 0)
|
|
|
|
assert_equal(len(self.nodes[2].listunspent()), 0)
|
|
|
|
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("Mining blocks...")
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[0].generate(1)
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2014-12-25 08:57:16 +01:00
|
|
|
walletinfo = self.nodes[0].getwalletinfo()
|
2016-03-06 16:14:39 +01:00
|
|
|
assert_equal(walletinfo['immature_balance'], 500)
|
2014-12-25 08:57:16 +01:00
|
|
|
assert_equal(walletinfo['balance'], 0)
|
|
|
|
|
2014-11-19 21:55:40 +01:00
|
|
|
self.sync_all()
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[1].generate(101)
|
2014-11-19 21:55:40 +01:00
|
|
|
self.sync_all()
|
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
assert_equal(self.nodes[0].getbalance(), 500)
|
|
|
|
assert_equal(self.nodes[1].getbalance(), 500)
|
2014-11-19 21:55:40 +01:00
|
|
|
assert_equal(self.nodes[2].getbalance(), 0)
|
|
|
|
|
2016-04-19 13:22:11 +02:00
|
|
|
# Check that only first and second nodes have UTXOs
|
2017-04-29 14:47:00 +02:00
|
|
|
utxos = self.nodes[0].listunspent()
|
|
|
|
assert_equal(len(utxos), 1)
|
2016-04-19 13:22:11 +02:00
|
|
|
assert_equal(len(self.nodes[1].listunspent()), 1)
|
|
|
|
assert_equal(len(self.nodes[2].listunspent()), 0)
|
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
# Send 210 DASH from 0 to 2 using sendtoaddress call.
|
2014-11-19 21:55:40 +01:00
|
|
|
# Second transaction will be child of first, and will require a fee
|
2016-03-06 16:14:39 +01:00
|
|
|
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 110)
|
2017-04-29 14:47:00 +02:00
|
|
|
mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 100)
|
|
|
|
|
|
|
|
self.log.info("test gettxout")
|
|
|
|
# utxo spent in mempool should be visible if you exclude mempool
|
|
|
|
# but invisible if you include mempool
|
|
|
|
confirmed_txid, confirmed_index = utxos[0]["txid"], utxos[0]["vout"]
|
|
|
|
txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, False)
|
|
|
|
assert_equal(txout['value'], 500)
|
|
|
|
txout = self.nodes[0].gettxout(confirmed_txid, confirmed_index, True)
|
|
|
|
assert txout is None
|
|
|
|
# new utxo from mempool should be invisible if you exclude mempool
|
|
|
|
# but visible if you include mempool
|
|
|
|
txout = self.nodes[0].gettxout(mempool_txid, 0, False)
|
|
|
|
assert txout is None
|
|
|
|
txout1 = self.nodes[0].gettxout(mempool_txid, 0, True)
|
|
|
|
txout2 = self.nodes[0].gettxout(mempool_txid, 1, True)
|
|
|
|
# note the mempool tx will have randomly assigned indices
|
|
|
|
# but 10 will go to node2 and the rest will go to node0
|
|
|
|
balance = self.nodes[0].getbalance()
|
|
|
|
assert_equal(set([txout1['value'], txout2['value']]), set([100, balance]))
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2014-12-25 08:57:16 +01:00
|
|
|
walletinfo = self.nodes[0].getwalletinfo()
|
|
|
|
assert_equal(walletinfo['immature_balance'], 0)
|
|
|
|
|
2015-04-28 16:48:28 +02:00
|
|
|
# Have node0 mine a block, thus it will collect its own fee.
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[0].generate(1)
|
2014-11-19 21:55:40 +01:00
|
|
|
self.sync_all()
|
|
|
|
|
2016-03-06 18:30:51 +01:00
|
|
|
# Exercise locking of unspent outputs
|
|
|
|
unspent_0 = self.nodes[2].listunspent()[0]
|
|
|
|
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
|
|
|
|
self.nodes[2].lockunspent(False, [unspent_0])
|
2017-03-16 11:57:09 +01:00
|
|
|
assert_raises_jsonrpc(-4, "Insufficient funds", self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 200)
|
2016-03-06 18:30:51 +01:00
|
|
|
assert_equal([unspent_0], self.nodes[2].listlockunspent())
|
|
|
|
self.nodes[2].lockunspent(True, [unspent_0])
|
|
|
|
assert_equal(len(self.nodes[2].listlockunspent()), 0)
|
|
|
|
|
2014-11-19 21:55:40 +01:00
|
|
|
# Have node1 generate 100 blocks (so node0 can recover the fee)
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[1].generate(100)
|
2014-11-19 21:55:40 +01:00
|
|
|
self.sync_all()
|
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
# node0 should end up with 1000 DASH in block rewards plus fees, but
|
|
|
|
# minus the 210 plus fees sent to node2
|
|
|
|
assert_equal(self.nodes[0].getbalance(), 1000-210)
|
|
|
|
assert_equal(self.nodes[2].getbalance(), 210)
|
2014-11-19 21:55:40 +01:00
|
|
|
|
|
|
|
# Node0 should have two unspent outputs.
|
2015-07-14 21:13:16 +02:00
|
|
|
# Create a couple of transactions to send them to node2, submit them through
|
|
|
|
# node1, and make sure both node0 and node2 pick them up properly:
|
2014-11-19 21:55:40 +01:00
|
|
|
node0utxos = self.nodes[0].listunspent(1)
|
|
|
|
assert_equal(len(node0utxos), 2)
|
|
|
|
|
2019-03-15 07:18:16 +01:00
|
|
|
fee_per_input = Decimal('0.00001')
|
|
|
|
totalfee = 0
|
2014-11-19 21:55:40 +01:00
|
|
|
# create both transactions
|
|
|
|
txns_to_send = []
|
2015-07-14 21:13:16 +02:00
|
|
|
for utxo in node0utxos:
|
2014-11-19 21:55:40 +01:00
|
|
|
inputs = []
|
|
|
|
outputs = {}
|
|
|
|
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
|
2019-03-15 07:18:16 +01:00
|
|
|
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - fee_per_input
|
2014-11-19 21:55:40 +01:00
|
|
|
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
|
|
|
|
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))
|
2019-03-15 07:18:16 +01:00
|
|
|
totalfee += fee_per_input
|
2014-11-19 21:55:40 +01:00
|
|
|
|
|
|
|
# Have node 1 (miner) send the transactions
|
2019-03-15 07:18:16 +01:00
|
|
|
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"])
|
|
|
|
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"])
|
2014-11-19 21:55:40 +01:00
|
|
|
|
|
|
|
# Have node1 mine a block to confirm transactions:
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[1].generate(1)
|
2014-11-19 21:55:40 +01:00
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
assert_equal(self.nodes[0].getbalance(), 0)
|
2019-03-15 07:18:16 +01:00
|
|
|
assert_equal(self.nodes[2].getbalance(), 1000 - totalfee)
|
|
|
|
assert_equal(self.nodes[2].getbalance("from1"), 1000 - 210 - totalfee)
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
# Send 100 DASH normal
|
2014-07-23 14:34:36 +02:00
|
|
|
address = self.nodes[0].getnewaddress("test")
|
2017-12-07 10:43:23 +01:00
|
|
|
fee_per_byte = Decimal('0.00001') / 1000
|
2015-09-21 12:49:13 +02:00
|
|
|
self.nodes[2].settxfee(fee_per_byte * 1000)
|
2016-03-06 16:14:39 +01:00
|
|
|
txid = self.nodes[2].sendtoaddress(address, 100, "", "", False)
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2014-07-23 14:34:36 +02:00
|
|
|
self.sync_all()
|
2019-03-15 07:18:16 +01:00
|
|
|
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('900') - totalfee, fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
2016-03-06 16:14:39 +01:00
|
|
|
assert_equal(self.nodes[0].getbalance(), Decimal('100'))
|
2014-07-23 14:34:36 +02:00
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
# Send 100 DASH with subtract fee from amount
|
|
|
|
txid = self.nodes[2].sendtoaddress(address, 100, "", "", True)
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2014-07-23 14:34:36 +02:00
|
|
|
self.sync_all()
|
2016-03-06 16:14:39 +01:00
|
|
|
node_2_bal -= Decimal('100')
|
2015-09-21 12:49:13 +02:00
|
|
|
assert_equal(self.nodes[2].getbalance(), node_2_bal)
|
2016-03-06 16:14:39 +01:00
|
|
|
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('200'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
2014-11-19 21:55:40 +01:00
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
# Sendmany 100 DASH
|
2017-09-20 22:34:54 +02:00
|
|
|
txid = self.nodes[2].sendmany('from1', {address: 100}, 0, False, "", [])
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2015-03-05 14:59:19 +01:00
|
|
|
self.sync_all()
|
2016-03-06 16:14:39 +01:00
|
|
|
node_0_bal += Decimal('100')
|
|
|
|
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('100'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
2015-09-21 12:49:13 +02:00
|
|
|
assert_equal(self.nodes[0].getbalance(), node_0_bal)
|
2015-03-05 14:59:19 +01:00
|
|
|
|
2016-03-06 16:14:39 +01:00
|
|
|
# Sendmany 100 DASH with subtract fee from amount
|
2017-09-20 22:34:54 +02:00
|
|
|
txid = self.nodes[2].sendmany('from1', {address: 100}, 0, False, "", [address])
|
2015-04-01 05:28:28 +02:00
|
|
|
self.nodes[2].generate(1)
|
2015-03-05 14:59:19 +01:00
|
|
|
self.sync_all()
|
2016-03-06 16:14:39 +01:00
|
|
|
node_2_bal -= Decimal('100')
|
2015-09-21 12:49:13 +02:00
|
|
|
assert_equal(self.nodes[2].getbalance(), node_2_bal)
|
2016-03-06 16:14:39 +01:00
|
|
|
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('100'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
|
2015-03-05 14:59:19 +01:00
|
|
|
|
2015-03-23 18:47:18 +01:00
|
|
|
# Test ResendWalletTransactions:
|
|
|
|
# Create a couple of transactions, then start up a fourth
|
|
|
|
# node (nodes[3]) and ask nodes[0] to rebroadcast.
|
|
|
|
# EXPECT: nodes[3] should have those transactions in its mempool.
|
|
|
|
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
|
|
|
|
txid2 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)
|
|
|
|
sync_mempools(self.nodes)
|
|
|
|
|
2018-01-11 14:47:10 +01:00
|
|
|
self.nodes.append(start_node(3, self.options.tmpdir, self.extra_args[3], redirect_stderr=True))
|
2015-03-23 18:47:18 +01:00
|
|
|
connect_nodes_bi(self.nodes, 0, 3)
|
|
|
|
sync_blocks(self.nodes)
|
|
|
|
|
|
|
|
relayed = self.nodes[0].resendwallettransactions()
|
2015-12-02 18:12:23 +01:00
|
|
|
assert_equal(set(relayed), {txid1, txid2})
|
2015-03-23 18:47:18 +01:00
|
|
|
sync_mempools(self.nodes)
|
|
|
|
|
|
|
|
assert(txid1 in self.nodes[3].getrawmempool())
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2016-03-06 18:30:51 +01:00
|
|
|
# Exercise balance rpcs
|
|
|
|
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], 1)
|
|
|
|
assert_equal(self.nodes[0].getunconfirmedbalance(), 1)
|
|
|
|
|
2015-04-21 10:27:35 +02:00
|
|
|
#check if we can list zero value tx as available coins
|
|
|
|
#1. create rawtx
|
2015-07-14 21:13:16 +02:00
|
|
|
#2. hex-changed one output to 0.0
|
2015-04-21 10:27:35 +02:00
|
|
|
#3. sign and send
|
|
|
|
#4. check if recipient (node0) can list the zero value tx
|
|
|
|
usp = self.nodes[1].listunspent()
|
|
|
|
inputs = [{"txid":usp[0]['txid'], "vout":usp[0]['vout']}]
|
2016-03-06 16:14:39 +01:00
|
|
|
outputs = {self.nodes[1].getnewaddress(): 499.998, self.nodes[0].getnewaddress(): 11.11}
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-21 10:27:35 +02:00
|
|
|
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32)
|
|
|
|
decRawTx = self.nodes[1].decoderawtransaction(rawTx)
|
|
|
|
signedRawTx = self.nodes[1].signrawtransaction(rawTx)
|
|
|
|
decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex'])
|
|
|
|
zeroValueTxid= decRawTx['txid']
|
|
|
|
sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex'])
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-21 10:27:35 +02:00
|
|
|
self.sync_all()
|
|
|
|
self.nodes[1].generate(1) #mine a block
|
|
|
|
self.sync_all()
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-21 10:27:35 +02:00
|
|
|
unspentTxs = self.nodes[0].listunspent() #zero value tx must be in listunspents output
|
|
|
|
found = False
|
|
|
|
for uTx in unspentTxs:
|
|
|
|
if uTx['txid'] == zeroValueTxid:
|
|
|
|
found = True
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(uTx['amount'], Decimal('0'))
|
2015-04-21 10:27:35 +02:00
|
|
|
assert(found)
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-01 11:56:52 +02:00
|
|
|
#do some -walletbroadcast tests
|
|
|
|
stop_nodes(self.nodes)
|
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir, [["-walletbroadcast=0"],["-walletbroadcast=0"],["-walletbroadcast=0"]])
|
|
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
|
|
connect_nodes_bi(self.nodes,1,2)
|
|
|
|
connect_nodes_bi(self.nodes,0,2)
|
|
|
|
self.sync_all()
|
2015-03-23 18:47:18 +01:00
|
|
|
|
2015-12-15 17:15:13 +01:00
|
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
|
2015-04-01 11:56:52 +02:00
|
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
2015-04-09 17:36:10 +02:00
|
|
|
self.nodes[1].generate(1) #mine a block, tx should not be in there
|
2015-04-01 11:56:52 +02:00
|
|
|
self.sync_all()
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(self.nodes[2].getbalance(), node_2_bal) #should not be changed because tx was not broadcasted
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-01 11:56:52 +02:00
|
|
|
#now broadcast from another node, mine a block, sync, and check the balance
|
|
|
|
self.nodes[1].sendrawtransaction(txObjNotBroadcasted['hex'])
|
2015-04-09 17:36:10 +02:00
|
|
|
self.nodes[1].generate(1)
|
2015-04-01 11:56:52 +02:00
|
|
|
self.sync_all()
|
2015-12-15 17:15:13 +01:00
|
|
|
node_2_bal += 2
|
2015-04-01 11:56:52 +02:00
|
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(self.nodes[2].getbalance(), node_2_bal)
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-01 11:56:52 +02:00
|
|
|
#create another tx
|
2015-12-15 17:15:13 +01:00
|
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-01 11:56:52 +02:00
|
|
|
#restart the nodes with -walletbroadcast=1
|
|
|
|
stop_nodes(self.nodes)
|
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir)
|
|
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
|
|
connect_nodes_bi(self.nodes,1,2)
|
|
|
|
connect_nodes_bi(self.nodes,0,2)
|
|
|
|
sync_blocks(self.nodes)
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-09 17:36:10 +02:00
|
|
|
self.nodes[0].generate(1)
|
2015-04-01 11:56:52 +02:00
|
|
|
sync_blocks(self.nodes)
|
2015-12-15 17:15:13 +01:00
|
|
|
node_2_bal += 2
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2015-04-01 11:56:52 +02:00
|
|
|
#tx should be added to balance because after restarting the nodes tx should be broadcastet
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(self.nodes[2].getbalance(), node_2_bal)
|
2015-07-14 21:13:16 +02:00
|
|
|
|
|
|
|
#send a tx with value in a string (PR#6380 +)
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
|
|
|
|
txObj = self.nodes[0].gettransaction(txId)
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(txObj['amount'], Decimal('-2'))
|
2015-07-14 21:13:16 +02:00
|
|
|
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "0.0001")
|
|
|
|
txObj = self.nodes[0].gettransaction(txId)
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(txObj['amount'], Decimal('-0.0001'))
|
2015-07-14 21:13:16 +02:00
|
|
|
|
|
|
|
#check if JSON parser can handle scientific notation in strings
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1e-4")
|
|
|
|
txObj = self.nodes[0].gettransaction(txId)
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(txObj['amount'], Decimal('-0.0001'))
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2017-03-16 11:57:09 +01:00
|
|
|
# This will raise an exception because the amount type is wrong
|
|
|
|
assert_raises_jsonrpc(-3, "Invalid amount", self.nodes[0].sendtoaddress, self.nodes[2].getnewaddress(), "1f-4")
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2017-03-16 11:57:09 +01:00
|
|
|
# This will raise an exception since generate does not accept a string
|
|
|
|
assert_raises_jsonrpc(-1, "not an integer", self.nodes[0].generate, "2")
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2016-04-19 13:22:11 +02:00
|
|
|
# Import address and private key to check correct behavior of spendable unspents
|
|
|
|
# 1. Send some coins to generate new UTXO
|
|
|
|
address_to_import = self.nodes[2].getnewaddress()
|
|
|
|
txid = self.nodes[0].sendtoaddress(address_to_import, 1)
|
|
|
|
self.nodes[0].generate(1)
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
# 2. Import address from node2 to node1
|
|
|
|
self.nodes[1].importaddress(address_to_import)
|
|
|
|
|
|
|
|
# 3. Validate that the imported address is watch-only on node1
|
|
|
|
assert(self.nodes[1].validateaddress(address_to_import)["iswatchonly"])
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2016-04-19 13:22:11 +02:00
|
|
|
# 4. Check that the unspents after import are not spendable
|
|
|
|
assert_array_result(self.nodes[1].listunspent(),
|
|
|
|
{"address": address_to_import},
|
|
|
|
{"spendable": False})
|
|
|
|
|
|
|
|
# 5. Import private key of the previously imported address on node1
|
|
|
|
priv_key = self.nodes[2].dumpprivkey(address_to_import)
|
|
|
|
self.nodes[1].importprivkey(priv_key)
|
|
|
|
|
|
|
|
# 6. Check that the unspents are now spendable on node1
|
|
|
|
assert_array_result(self.nodes[1].listunspent(),
|
|
|
|
{"address": address_to_import},
|
|
|
|
{"spendable": True})
|
2015-12-15 17:15:13 +01:00
|
|
|
|
2016-03-23 13:24:34 +01:00
|
|
|
# Mine a block from node0 to an address from node1
|
|
|
|
cbAddr = self.nodes[1].getnewaddress()
|
|
|
|
blkHash = self.nodes[0].generatetoaddress(1, cbAddr)[0]
|
|
|
|
cbTxId = self.nodes[0].getblock(blkHash)['tx'][0]
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
# Check that the txid and balance is found by node1
|
2016-04-06 14:12:21 +02:00
|
|
|
self.nodes[1].gettransaction(cbTxId)
|
2016-03-23 13:24:34 +01:00
|
|
|
|
2016-05-17 09:26:42 +02:00
|
|
|
# check if wallet or blockchain maintenance changes the balance
|
2015-12-15 17:15:13 +01:00
|
|
|
self.sync_all()
|
2016-03-06 18:30:51 +01:00
|
|
|
blocks = self.nodes[0].generate(2)
|
2015-12-15 17:15:13 +01:00
|
|
|
self.sync_all()
|
|
|
|
balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
|
2016-03-28 21:47:13 +02:00
|
|
|
block_count = self.nodes[0].getblockcount()
|
2015-12-15 17:15:13 +01:00
|
|
|
|
2016-04-28 15:18:01 +02:00
|
|
|
# Check modes:
|
|
|
|
# - True: unicode escaped as \u....
|
|
|
|
# - False: unicode directly as UTF-8
|
|
|
|
for mode in [True, False]:
|
|
|
|
self.nodes[0].ensure_ascii = mode
|
|
|
|
# unicode check: Basic Multilingual Plane, Supplementary Plane respectively
|
|
|
|
for s in [u'рыба', u'𝅘𝅥𝅯']:
|
|
|
|
addr = self.nodes[0].getaccountaddress(s)
|
|
|
|
label = self.nodes[0].getaccount(addr)
|
2018-02-08 06:43:50 +01:00
|
|
|
assert_equal(label, s)
|
2016-04-28 15:18:01 +02:00
|
|
|
assert(s in self.nodes[0].listaccounts().keys())
|
|
|
|
self.nodes[0].ensure_ascii = True # restore to default
|
|
|
|
|
|
|
|
# maintenance tests
|
2015-12-15 17:15:13 +01:00
|
|
|
maintenance = [
|
|
|
|
'-rescan',
|
|
|
|
'-reindex',
|
|
|
|
'-zapwallettxes=1',
|
|
|
|
'-zapwallettxes=2',
|
2016-05-17 09:26:42 +02:00
|
|
|
# disabled until issue is fixed: https://github.com/bitcoin/bitcoin/issues/7463
|
|
|
|
# '-salvagewallet',
|
2015-12-15 17:15:13 +01:00
|
|
|
]
|
2016-12-20 13:12:46 +01:00
|
|
|
chainlimit = 6
|
2015-12-15 17:15:13 +01:00
|
|
|
for m in maintenance:
|
2017-03-09 21:16:20 +01:00
|
|
|
self.log.info("check " + m)
|
2015-12-15 17:15:13 +01:00
|
|
|
stop_nodes(self.nodes)
|
2016-12-20 13:12:46 +01:00
|
|
|
# set lower ancestor limit for later
|
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir, [[m, "-limitancestorcount="+str(chainlimit)]] * 3)
|
2016-03-28 21:47:13 +02:00
|
|
|
while m == '-reindex' and [block_count] * 3 != [self.nodes[i].getblockcount() for i in range(3)]:
|
|
|
|
# reindex will leave rpc warm up "early"; Wait for it to finish
|
|
|
|
time.sleep(0.1)
|
2015-12-15 17:15:13 +01:00
|
|
|
assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)])
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2016-03-06 18:30:51 +01:00
|
|
|
# Exercise listsinceblock with the last two blocks
|
|
|
|
coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0])
|
|
|
|
assert_equal(coinbase_tx_1["lastblock"], blocks[1])
|
|
|
|
assert_equal(len(coinbase_tx_1["transactions"]), 1)
|
|
|
|
assert_equal(coinbase_tx_1["transactions"][0]["blockhash"], blocks[1])
|
|
|
|
assert_equal(len(self.nodes[0].listsinceblock(blocks[1])["transactions"]), 0)
|
2015-07-14 21:13:16 +02:00
|
|
|
|
2016-12-20 13:12:46 +01:00
|
|
|
# ==Check that wallet prefers to use coins that don't exceed mempool limits =====
|
|
|
|
|
|
|
|
# Get all non-zero utxos together
|
|
|
|
chain_addrs = [self.nodes[0].getnewaddress(), self.nodes[0].getnewaddress()]
|
|
|
|
singletxid = self.nodes[0].sendtoaddress(chain_addrs[0], self.nodes[0].getbalance(), "", "", True)
|
|
|
|
self.nodes[0].generate(1)
|
|
|
|
node0_balance = self.nodes[0].getbalance()
|
|
|
|
# Split into two chains
|
|
|
|
rawtx = self.nodes[0].createrawtransaction([{"txid":singletxid, "vout":0}], {chain_addrs[0]:node0_balance/2-Decimal('0.01'), chain_addrs[1]:node0_balance/2-Decimal('0.01')})
|
|
|
|
signedtx = self.nodes[0].signrawtransaction(rawtx)
|
|
|
|
singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"])
|
|
|
|
self.nodes[0].generate(1)
|
|
|
|
|
|
|
|
# Make a long chain of unconfirmed payments without hitting mempool limit
|
2017-01-04 20:48:14 +01:00
|
|
|
# Each tx we make leaves only one output of change on a chain 1 longer
|
|
|
|
# Since the amount to send is always much less than the outputs, we only ever need one output
|
|
|
|
# So we should be able to generate exactly chainlimit txs for each original output
|
|
|
|
sending_addr = self.nodes[1].getnewaddress()
|
2016-12-20 13:12:46 +01:00
|
|
|
txid_list = []
|
|
|
|
for i in range(chainlimit*2):
|
2017-01-04 20:48:14 +01:00
|
|
|
txid_list.append(self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001')))
|
2016-12-20 13:12:46 +01:00
|
|
|
assert_equal(self.nodes[0].getmempoolinfo()['size'], chainlimit*2)
|
|
|
|
assert_equal(len(txid_list), chainlimit*2)
|
|
|
|
|
2017-01-04 20:48:14 +01:00
|
|
|
# Without walletrejectlongchains, we will still generate a txid
|
|
|
|
# The tx will be stored in the wallet but not accepted to the mempool
|
|
|
|
extra_txid = self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001'))
|
|
|
|
assert(extra_txid not in self.nodes[0].getrawmempool())
|
|
|
|
assert(extra_txid in [tx["txid"] for tx in self.nodes[0].listtransactions()])
|
|
|
|
self.nodes[0].abandontransaction(extra_txid)
|
|
|
|
total_txs = len(self.nodes[0].listtransactions("*",99999))
|
|
|
|
|
|
|
|
# Try with walletrejectlongchains
|
|
|
|
# Double chain limit but require combining inputs, so we pass SelectCoinsMinConf
|
|
|
|
stop_node(self.nodes[0],0)
|
|
|
|
self.nodes[0] = start_node(0, self.options.tmpdir, ["-walletrejectlongchains", "-limitancestorcount="+str(2*chainlimit)])
|
|
|
|
|
|
|
|
# wait for loadmempool
|
|
|
|
timeout = 10
|
|
|
|
while (timeout > 0 and len(self.nodes[0].getrawmempool()) < chainlimit*2):
|
|
|
|
time.sleep(0.5)
|
|
|
|
timeout -= 0.5
|
|
|
|
assert_equal(len(self.nodes[0].getrawmempool()), chainlimit*2)
|
|
|
|
|
|
|
|
node0_balance = self.nodes[0].getbalance()
|
|
|
|
# With walletrejectlongchains we will not create the tx and store it in our wallet.
|
2017-03-16 11:57:09 +01:00
|
|
|
assert_raises_jsonrpc(-4, "Transaction has too long of a mempool chain", self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('0.01'))
|
2017-01-04 20:48:14 +01:00
|
|
|
|
|
|
|
# Verify nothing new in wallet
|
|
|
|
assert_equal(total_txs, len(self.nodes[0].listtransactions("*",99999)))
|
|
|
|
|
2014-11-19 21:55:40 +01:00
|
|
|
if __name__ == '__main__':
|
2016-05-17 09:26:42 +02:00
|
|
|
WalletTest().main()
|