Skip to content

Commit

Permalink
Merge bitcoin#13075: [tests] Remove 'account' API from wallet functio…
Browse files Browse the repository at this point in the history
…nal tests

5d53661 [tests] Remove 'account' API from wallet functional tests (John Newbery)

Pull request description:

  Next step in bitcoin#12952. Removes all usage of the 'account' API from the wallet functional tests, except:

  - rpc_deprecated.py (which specifically tests the `-deprecatedrpc=accounts` command line argument is working properly).
  - `wallet_labels.py` (which tests that both the 'label' and 'account' APIs work in V0.17).

  'account' API usage for both of those tests can be removed once V0.17 has been branched.

  Also excluded is:

  - `wallet_importprunedfunds.py` (which fails due to a bitcoind OOM error)

Tree-SHA512: 6701b32f83d2d47597ba093ded665d7aa630f7a9c759ff15e3e33a3e3bc7600e8d29cf4e72aed5f8f9f6769cc9b614c681951720eab1ed2473f5f8dec57e7a6f
  • Loading branch information
MarcoFalke authored and xdustinface committed Dec 18, 2020
1 parent 332259e commit 2bdbc5b
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 225 deletions.
32 changes: 16 additions & 16 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WalletTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = True
self.extra_args = [['-usehd={:d}'.format(i%2==0), '-deprecatedrpc=accounts'] for i in range(4)]
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]

def setup_network(self):
self.add_nodes(4, self.extra_args, stderr=sys.stdout)
Expand Down Expand Up @@ -146,7 +146,7 @@ def run_test(self):
inputs = []
outputs = {}
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - fee_per_input
outputs[self.nodes[2].getnewaddress()] = utxo["amount"] - fee_per_input
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
txns_to_send.append(self.nodes[0].signrawtransactionwithwallet(raw_tx))
totalfee += fee_per_input
Expand All @@ -161,7 +161,7 @@ def run_test(self):

assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 1000 - totalfee)
assert_equal(self.nodes[2].getbalance("from1"), 1000 - 210 - totalfee)
assert_equal(self.nodes[2].getbalance(), 1000 - 210 - totalfee)

# Verify that a spent output cannot be locked anymore
spent_0 = {"txid": node0utxos[0]["txid"], "vout": node0utxos[0]["vout"]}
Expand All @@ -186,15 +186,15 @@ def run_test(self):
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('200'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))

# Sendmany 100 DASH
txid = self.nodes[2].sendmany('from1', {address: 100}, 0, False, "", [])
txid = self.nodes[2].sendmany('', {address: 100}, 0, False, "", [])
self.nodes[2].generate(1)
self.sync_all(self.nodes[0:3])
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)))
assert_equal(self.nodes[0].getbalance(), node_0_bal)

# Sendmany 100 DASH with subtract fee from amount
txid = self.nodes[2].sendmany('from1', {address: 100}, 0, False, "", [address])
txid = self.nodes[2].sendmany('', {address: 100}, 0, False, "", [address])
self.nodes[2].generate(1)
self.sync_all(self.nodes[0:3])
node_2_bal -= Decimal('100')
Expand Down Expand Up @@ -362,14 +362,14 @@ def run_test(self):
# - True: unicode escaped as \u....
# - False: unicode directly as UTF-8
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
for s in [u'рыба', u'𝅘𝅥𝅯']:
addr = self.nodes[0].getaccountaddress(s)
label = self.nodes[0].getaccount(addr)
assert_equal(label, s)
assert(s in self.nodes[0].listaccounts().keys())
self.nodes[0].ensure_ascii = True # restore to default
for label in [u'рыба', u'𝅘𝅥𝅯']:
addr = self.nodes[0].getnewaddress()
self.nodes[0].setlabel(addr, label)
assert_equal(self.nodes[0].getaddressinfo(addr)['label'], label)
assert(label in self.nodes[0].listlabels())
self.nodes[0].rpc.ensure_ascii = True # restore to default

# maintenance tests
maintenance = [
Expand All @@ -385,9 +385,9 @@ def run_test(self):
self.log.info("check " + m)
self.stop_nodes()
# set lower ancestor limit for later
self.start_node(0, [m, "-deprecatedrpc=accounts", "-limitancestorcount="+str(chainlimit)])
self.start_node(1, [m, "-deprecatedrpc=accounts", "-limitancestorcount="+str(chainlimit)])
self.start_node(2, [m, "-deprecatedrpc=accounts", "-limitancestorcount="+str(chainlimit)])
self.start_node(0, [m, "-limitancestorcount=" + str(chainlimit)])
self.start_node(1, [m, "-limitancestorcount=" + str(chainlimit)])
self.start_node(2, [m, "-limitancestorcount=" + str(chainlimit)])
if m == '-reindex':
# reindex will leave rpc warm up "early"; Wait for it to finish
wait_until(lambda: [block_count] * 3 == [self.nodes[i].getblockcount() for i in range(3)])
Expand Down Expand Up @@ -435,7 +435,7 @@ def run_test(self):
# Try with walletrejectlongchains
# Double chain limit but require combining inputs, so we pass SelectCoinsMinConf
self.stop_node(0)
self.start_node(0, extra_args=["-deprecatedrpc=accounts", "-walletrejectlongchains", "-limitancestorcount="+str(2*chainlimit)])
self.start_node(0, extra_args=["-walletrejectlongchains", "-limitancestorcount=" + str(2 * chainlimit)])

# wait for loadmempool
timeout = 10
Expand Down
45 changes: 17 additions & 28 deletions test/functional/wallet_import_rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ def try_rpc(self, func, *args, **kwargs):

def do_import(self, timestamp):
"""Call one key import RPC."""
rescan = self.rescan == Rescan.yes

if self.call == Call.single:
if self.data == Data.address:
response = self.try_rpc(self.node.importaddress, self.address["address"], self.label,
self.rescan == Rescan.yes)
response = self.try_rpc(self.node.importaddress, address=self.address["address"], rescan=rescan)
elif self.data == Data.pub:
response = self.try_rpc(self.node.importpubkey, self.address["pubkey"], self.label,
self.rescan == Rescan.yes)
response = self.try_rpc(self.node.importpubkey, pubkey=self.address["pubkey"], rescan=rescan)
elif self.data == Data.priv:
response = self.try_rpc(self.node.importprivkey, self.key, self.label, self.rescan == Rescan.yes)
response = self.try_rpc(self.node.importprivkey, privkey=self.key, rescan=rescan)
assert_equal(response, None)

elif self.call == Call.multi:
Expand All @@ -63,40 +62,32 @@ def do_import(self, timestamp):
"timestamp": timestamp + TIMESTAMP_WINDOW + (1 if self.rescan == Rescan.late_timestamp else 0),
"pubkeys": [self.address["pubkey"]] if self.data == Data.pub else [],
"keys": [self.key] if self.data == Data.priv else [],
"label": self.label,
"watchonly": self.data != Data.priv
}], {"rescan": self.rescan in (Rescan.yes, Rescan.late_timestamp)})
assert_equal(response, [{"success": True}])

def check(self, txid=None, amount=None, confirmations=None):
"""Verify that getbalance/listtransactions return expected values."""
"""Verify that listreceivedbyaddress returns expected values."""

balance = self.node.getbalance(self.label, 0, False, True)
assert_equal(balance, self.expected_balance)

txs = self.node.listtransactions(self.label, 10000, 0, True)
assert_equal(len(txs), self.expected_txs)
addresses = self.node.listreceivedbyaddress(minconf=0, include_watchonly=True, address_filter=self.address['address'])
if self.expected_txs:
assert_equal(len(addresses[0]["txids"]), self.expected_txs)

if txid is not None:
tx, = [tx for tx in txs if tx["txid"] == txid]
assert_equal(tx["label"], self.label)
assert_equal(tx["address"], self.address["address"])
assert_equal(tx["amount"], amount)
assert_equal(tx["category"], "receive")
assert_equal(tx["label"], self.label)
assert_equal(tx["txid"], txid)
assert_equal(tx["confirmations"], confirmations)
assert_equal("trusted" not in tx, True)
address, = [ad for ad in addresses if txid in ad["txids"]]
assert_equal(address["address"], self.address["address"])
assert_equal(address["amount"], self.expected_balance)
assert_equal(address["confirmations"], confirmations)
# Verify the transaction is correctly marked watchonly depending on
# whether the transaction pays to an imported public key or
# imported private key. The test setup ensures that transaction
# inputs will not be from watchonly keys (important because
# involvesWatchonly will be true if either the transaction output
# or inputs are watchonly).
if self.data != Data.priv:
assert_equal(tx["involvesWatchonly"], True)
assert_equal(address["involvesWatchonly"], True)
else:
assert_equal("involvesWatchonly" not in tx, True)
assert_equal("involvesWatchonly" not in address, True)


# List of Variants for each way a key or address could be imported.
Expand All @@ -120,23 +111,21 @@ def set_test_params(self):
self.num_nodes = 2 + len(IMPORT_NODES)

def setup_network(self):
extra_args = [['-deprecatedrpc=accounts'] for _ in range(self.num_nodes)]
for i, import_node in enumerate(IMPORT_NODES, 2):
if import_node.prune:
# txindex is enabled by default in Dash and needs to be disabled for import-rescan.py
extra_args[i] += ["-prune=1", "-txindex=0", "-reindex"]

self.add_nodes(self.num_nodes, extra_args=extra_args, stderr=sys.stdout)
self.add_nodes(self.num_nodes, stderr=sys.stdout)
self.start_nodes()
for i in range(1, self.num_nodes):
connect_nodes(self.nodes[i], 0)

def run_test(self):
# Create one transaction on node 0 with a unique amount and label for
# Create one transaction on node 0 with a unique amount for
# each possible type of wallet import RPC.
for i, variant in enumerate(IMPORT_VARIANTS):
variant.label = "label {} {}".format(i, variant)
variant.address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress(variant.label))
variant.address = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())
variant.key = self.nodes[1].dumpprivkey(variant.address["address"])
variant.initial_amount = 10 - (i + 1) / 4.0
variant.initial_txid = self.nodes[0].sendtoaddress(variant.address["address"], variant.initial_amount)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_keypool_topup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
self.extra_args = [['-deprecatedrpc=accounts', '-usehd=0'], ['-deprecatedrpc=accounts', '-usehd=1', '-keypool=100', '-keypoolmin=20']]
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]
self.stderr = sys.stdout

def run_test(self):
Expand Down
11 changes: 6 additions & 5 deletions test/functional/wallet_listreceivedby.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class ReceivedByTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [['-deprecatedrpc=accounts']] * 2

def run_test(self):
# Generate block to get out of IBD
Expand Down Expand Up @@ -116,8 +115,9 @@ def run_test(self):
self.log.info("listreceivedbylabel + getreceivedbylabel Test")

# set pre-state
addrArr = self.nodes[1].getnewaddress()
label = self.nodes[1].getaccount(addrArr)
label = ''
address = self.nodes[1].getnewaddress()
assert_equal(self.nodes[1].getaddressinfo(address)['label'], label)
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0]
balance_by_label = self.nodes[1].getreceivedbylabel(label)

Expand Down Expand Up @@ -145,8 +145,9 @@ def run_test(self):
assert_equal(balance, balance_by_label + Decimal("0.1"))

# Create a new label named "mynewlabel" that has a 0 balance
self.nodes[1].getlabeladdress("mynewlabel", force=True)
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel(0, False, True) if r["label"] == "mynewlabel"][0]
address = self.nodes[1].getnewaddress()
self.nodes[1].setlabel(address, "mynewlabel")
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel(0, True) if r["label"] == "mynewlabel"][0]

# Test includeempty of listreceivedbylabel
assert_equal(received_by_label_json["amount"], Decimal("0.0"))
Expand Down
1 change: 0 additions & 1 deletion test/functional/wallet_listsinceblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ListSinceBlockTest (BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = True
self.extra_args = [['-deprecatedrpc=accounts']] * 4

def run_test(self):
self.nodes[2].generate(101)
Expand Down
97 changes: 0 additions & 97 deletions test/functional/wallet_listtransactions.py
Original file line number Diff line number Diff line change
@@ -1,97 +0,0 @@
#!/usr/bin/env python3
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the listtransactions API."""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import CTransaction
from io import BytesIO

def txFromHex(hexstring):
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(hexstring))
tx.deserialize(f)
return tx

class ListTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [['-deprecatedrpc=accounts']] * 2
self.set_cache_mocktime()

def run_test(self):
# Simple send, 0 to 1:
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()
assert_array_result(self.nodes[0].listtransactions(),
{"txid":txid},
{"category":"send","account":"","amount":Decimal("-0.1"),"confirmations":0})
assert_array_result(self.nodes[1].listtransactions(),
{"txid":txid},
{"category":"receive","account":"","amount":Decimal("0.1"),"confirmations":0})
# mine a block, confirmations should change:
self.nodes[0].generate(1)
self.sync_all()
assert_array_result(self.nodes[0].listtransactions(),
{"txid":txid},
{"category":"send","account":"","amount":Decimal("-0.1"),"confirmations":1})
assert_array_result(self.nodes[1].listtransactions(),
{"txid":txid},
{"category":"receive","account":"","amount":Decimal("0.1"),"confirmations":1})

# send-to-self:
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
assert_array_result(self.nodes[0].listtransactions(),
{"txid":txid, "category":"send"},
{"amount":Decimal("-0.2")})
assert_array_result(self.nodes[0].listtransactions(),
{"txid":txid, "category":"receive"},
{"amount":Decimal("0.2")})

# sendmany from node1: twice to self, twice to node2:
send_to = { self.nodes[0].getnewaddress() : 0.11,
self.nodes[1].getnewaddress() : 0.22,
self.nodes[0].getaccountaddress("from1") : 0.33,
self.nodes[1].getaccountaddress("toself") : 0.44 }
txid = self.nodes[1].sendmany("", send_to)
self.sync_all()
assert_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.11")},
{"txid":txid} )
assert_array_result(self.nodes[0].listtransactions(),
{"category":"receive","amount":Decimal("0.11")},
{"txid":txid} )
assert_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.22")},
{"txid":txid} )
assert_array_result(self.nodes[1].listtransactions(),
{"category":"receive","amount":Decimal("0.22")},
{"txid":txid} )
assert_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.33")},
{"txid":txid} )
assert_array_result(self.nodes[0].listtransactions(),
{"category":"receive","amount":Decimal("0.33")},
{"txid":txid, "account" : "from1"} )
assert_array_result(self.nodes[1].listtransactions(),
{"category":"send","amount":Decimal("-0.44")},
{"txid":txid, "account" : ""} )
assert_array_result(self.nodes[1].listtransactions(),
{"category":"receive","amount":Decimal("0.44")},
{"txid":txid, "account" : "toself"} )

pubkey = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['pubkey']
multisig = self.nodes[1].createmultisig(1, [pubkey])
self.nodes[0].importaddress(multisig["redeemScript"], "watchonly", False, True)
txid = self.nodes[1].sendtoaddress(multisig["address"], 0.1)
self.nodes[1].generate(1)
self.sync_all()
assert(len(self.nodes[0].listtransactions("watchonly", 100, 0, False)) == 0)
assert_array_result(self.nodes[0].listtransactions("watchonly", 100, 0, True),
{"category":"receive","amount":Decimal("0.1")},
{"txid":txid, "account" : "watchonly"} )

if __name__ == '__main__':
ListTransactionsTest().main()
Loading

0 comments on commit 2bdbc5b

Please sign in to comment.