Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_basic.py
Show All 19 Lines | from test_framework.util import ( | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
class WalletTest(BitcoinTestFramework): | class WalletTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 4 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [['-deprecatedrpc=accounts']] * 4 | |||||
def setup_network(self): | def setup_network(self): | ||||
self.add_nodes(4, self.extra_args) | self.add_nodes(4) | ||||
self.start_node(0) | self.start_node(0) | ||||
self.start_node(1) | self.start_node(1) | ||||
self.start_node(2) | self.start_node(2) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
connect_nodes_bi(self.nodes[1], self.nodes[2]) | connect_nodes_bi(self.nodes[1], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[2]) | connect_nodes_bi(self.nodes[0], self.nodes[2]) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert_equal(len(node0utxos), 2) | assert_equal(len(node0utxos), 2) | ||||
# create both transactions | # create both transactions | ||||
txns_to_send = [] | txns_to_send = [] | ||||
for utxo in node0utxos: | for utxo in node0utxos: | ||||
inputs = [] | inputs = [] | ||||
outputs = {} | outputs = {} | ||||
inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) | inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) | ||||
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - 3 | outputs[self.nodes[2].getnewaddress()] = utxo["amount"] - 3 | ||||
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) | raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
txns_to_send.append( | txns_to_send.append( | ||||
self.nodes[0].signrawtransactionwithwallet(raw_tx)) | self.nodes[0].signrawtransactionwithwallet(raw_tx)) | ||||
# Have node 1 (miner) send the transactions | # Have node 1 (miner) send the transactions | ||||
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True) | self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True) | ||||
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True) | self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True) | ||||
# Have node1 mine a block to confirm transactions: | # Have node1 mine a block to confirm transactions: | ||||
self.nodes[1].generate(1) | self.nodes[1].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
assert_equal(self.nodes[0].getbalance(), 0) | assert_equal(self.nodes[0].getbalance(), 0) | ||||
assert_equal(self.nodes[2].getbalance(), 94) | assert_equal(self.nodes[2].getbalance(), 94) | ||||
assert_equal(self.nodes[2].getbalance("from1"), 94 - 21) | |||||
# Verify that a spent output cannot be locked anymore | # Verify that a spent output cannot be locked anymore | ||||
spent_0 = {"txid": node0utxos[0]["txid"], | spent_0 = {"txid": node0utxos[0]["txid"], | ||||
"vout": node0utxos[0]["vout"]} | "vout": node0utxos[0]["vout"]} | ||||
assert_raises_rpc_error(-8, "Invalid parameter, expected unspent output", | assert_raises_rpc_error(-8, "Invalid parameter, expected unspent output", | ||||
self.nodes[0].lockunspent, False, [spent_0]) | self.nodes[0].lockunspent, False, [spent_0]) | ||||
# Send 10 BCH normal | # Send 10 BCH normal | ||||
Show All 14 Lines | def run_test(self): | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
node_2_bal -= Decimal('10') | node_2_bal -= Decimal('10') | ||||
assert_equal(self.nodes[2].getbalance(), node_2_bal) | assert_equal(self.nodes[2].getbalance(), node_2_bal) | ||||
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal( | node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal( | ||||
'20'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) | '20'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) | ||||
# Sendmany 10 BCH | # Sendmany 10 BCH | ||||
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", []) | txid = self.nodes[2].sendmany('', {address: 10}, 0, "", []) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
node_0_bal += Decimal('10') | node_0_bal += Decimal('10') | ||||
ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ||||
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance( | node_2_bal = self.check_fee_amount(self.nodes[2].getbalance( | ||||
), node_2_bal - Decimal('10'), fee_per_byte, ctx.billable_size()) | ), node_2_bal - Decimal('10'), fee_per_byte, ctx.billable_size()) | ||||
assert_equal(self.nodes[0].getbalance(), node_0_bal) | assert_equal(self.nodes[0].getbalance(), node_0_bal) | ||||
# Sendmany 10 BCH with subtract fee from amount | # Sendmany 10 BCH with subtract fee from amount | ||||
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [address]) | txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address]) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
node_2_bal -= Decimal('10') | node_2_bal -= Decimal('10') | ||||
assert_equal(self.nodes[2].getbalance(), node_2_bal) | assert_equal(self.nodes[2].getbalance(), node_2_bal) | ||||
ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ||||
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance( | node_0_bal = self.check_fee_amount(self.nodes[0].getbalance( | ||||
), node_0_bal + Decimal('10'), fee_per_byte, ctx.billable_size()) | ), node_0_bal + Decimal('10'), fee_per_byte, ctx.billable_size()) | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
balance_nodes = [self.nodes[i].getbalance() for i in range(3)] | balance_nodes = [self.nodes[i].getbalance() for i in range(3)] | ||||
block_count = self.nodes[0].getblockcount() | block_count = self.nodes[0].getblockcount() | ||||
# Check modes: | # Check modes: | ||||
# - True: unicode escaped as \u.... | # - True: unicode escaped as \u.... | ||||
# - False: unicode directly as UTF-8 | # - False: unicode directly as UTF-8 | ||||
for mode in [True, False]: | for mode in [True, False]: | ||||
self.nodes[0].ensure_ascii = mode | self.nodes[0].rpc.ensure_ascii = mode | ||||
# unicode check: Basic Multilingual Plane, Supplementary Plane respectively | # unicode check: Basic Multilingual Plane, Supplementary Plane respectively | ||||
for s in [u'рыба', u'𝅘𝅥𝅯']: | for label in [u'рыба', u'𝅘𝅥𝅯']: | ||||
addr = self.nodes[0].getaccountaddress(s) | addr = self.nodes[0].getnewaddress() | ||||
label = self.nodes[0].getaccount(addr) | self.nodes[0].setlabel(addr, label) | ||||
assert_equal(label, s) | assert_equal(self.nodes[0].getaddressinfo( | ||||
assert s in self.nodes[0].listaccounts().keys() | addr)['label'], label) | ||||
self.nodes[0].ensure_ascii = True # restore to default | assert(label in self.nodes[0].listlabels()) | ||||
# restore to default | |||||
self.nodes[0].rpc.ensure_ascii = True | |||||
# maintenance tests | # maintenance tests | ||||
maintenance = [ | maintenance = [ | ||||
'-rescan', | '-rescan', | ||||
'-reindex', | '-reindex', | ||||
'-zapwallettxes=1', | '-zapwallettxes=1', | ||||
'-zapwallettxes=2', | '-zapwallettxes=2', | ||||
# disabled until issue is fixed: https://github.com/bitcoin/bitcoin/issues/7463 | # disabled until issue is fixed: https://github.com/bitcoin/bitcoin/issues/7463 | ||||
# '-salvagewallet', | # '-salvagewallet', | ||||
] | ] | ||||
chainlimit = 6 | chainlimit = 6 | ||||
for m in maintenance: | for m in maintenance: | ||||
self.log.info("check " + m) | self.log.info("check " + m) | ||||
self.stop_nodes() | self.stop_nodes() | ||||
# set lower ancestor limit for later | # set lower ancestor limit for later | ||||
self.start_node(0, [m, "-deprecatedrpc=accounts", | self.start_node(0, [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
"-limitancestorcount=" + str(chainlimit)]) | self.start_node(1, [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
self.start_node(1, [m, "-deprecatedrpc=accounts", | self.start_node(2, [m, "-limitancestorcount=" + str(chainlimit)]) | ||||
"-limitancestorcount=" + str(chainlimit)]) | |||||
self.start_node(2, [m, "-deprecatedrpc=accounts", | |||||
"-limitancestorcount=" + str(chainlimit)]) | |||||
if m == '-reindex': | if m == '-reindex': | ||||
# reindex will leave rpc warm up "early"; Wait for it to finish | # reindex will leave rpc warm up "early"; Wait for it to finish | ||||
wait_until(lambda: [block_count] * 3 == | wait_until(lambda: [block_count] * 3 == | ||||
[self.nodes[i].getblockcount() for i in range(3)]) | [self.nodes[i].getblockcount() for i in range(3)]) | ||||
assert_equal(balance_nodes, [ | assert_equal(balance_nodes, [ | ||||
self.nodes[i].getbalance() for i in range(3)]) | self.nodes[i].getbalance() for i in range(3)]) | ||||
# Exercise listsinceblock with the last two blocks | # Exercise listsinceblock with the last two blocks | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
for tx in self.nodes[0].listtransactions()] | for tx in self.nodes[0].listtransactions()] | ||||
self.nodes[0].abandontransaction(extra_txid) | self.nodes[0].abandontransaction(extra_txid) | ||||
total_txs = len(self.nodes[0].listtransactions("*", 99999)) | total_txs = len(self.nodes[0].listtransactions("*", 99999)) | ||||
# Try with walletrejectlongchains | # Try with walletrejectlongchains | ||||
# Double chain limit but require combining inputs, so we pass SelectCoinsMinConf | # Double chain limit but require combining inputs, so we pass SelectCoinsMinConf | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node(0, extra_args=[ | self.start_node(0, extra_args=[ | ||||
"-deprecatedrpc=accounts", "-walletrejectlongchains", "-limitancestorcount=" + str(2 * chainlimit)]) | "-walletrejectlongchains", "-limitancestorcount=" + str(2 * chainlimit)]) | ||||
# wait for loadmempool | # wait for loadmempool | ||||
timeout = 10 | timeout = 10 | ||||
while (timeout > 0 and len(self.nodes[0].getrawmempool()) < chainlimit * 2): | while (timeout > 0 and len(self.nodes[0].getrawmempool()) < chainlimit * 2): | ||||
time.sleep(0.5) | time.sleep(0.5) | ||||
timeout -= 0.5 | timeout -= 0.5 | ||||
assert_equal(len(self.nodes[0].getrawmempool()), chainlimit * 2) | assert_equal(len(self.nodes[0].getrawmempool()), chainlimit * 2) | ||||
Show All 25 Lines |