mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge #14023: Remove accounts rpcs
bb08423d5ca866d4a139a3b57ff110d818d08b32 [doc] Add release notes for 'account' API removal (John Newbery) 1f4b865e57b4567270b1586bb1f348ab9106485d [wallet] Re-sort wallet RPC commands (John Newbery) f0dc850bf698f7377797d7d68365d4fc79b0221c [wallet] Remove wallet account RPCs (John Newbery) c410f415758913c933ad6c71cf50227cc85aa385 [tests] Remove wallet accounts test (John Newbery) Pull request description: This is the first part of #13825. It simply removes the RPC methods and tests. #13825 touches lots of files and will require frequent rebasing. Breaking it down for easier reviewing and fewer rebases. Tree-SHA512: d29af8e7a035e4484e6b9bb56cb86592be0ec112d8ba4ce19c15d15366ff3086e89e99fca26b90c9d66f6d3e06894486d0f29948df0bb7dcb1e2c49c6887a85a
This commit is contained in:
parent
5afaeb24cb
commit
b00e1b6331
8
doc/release-notes-14023.md
Normal file
8
doc/release-notes-14023.md
Normal file
@ -0,0 +1,8 @@
|
||||
Accout API removed
|
||||
------------------
|
||||
|
||||
The 'account' API was deprecated in v0.17 and has been fully removed in v0.18.
|
||||
The 'label' API was introduced in v0.17 as a replacement for accounts.
|
||||
|
||||
See the release notes from v0.17 for a full description of the changes from the
|
||||
'account' API to the 'label' API.
|
@ -196,7 +196,6 @@ BITCOIN_TESTS =\
|
||||
if ENABLE_WALLET
|
||||
BITCOIN_TESTS += \
|
||||
wallet/test/coinjoin_tests.cpp \
|
||||
wallet/test/accounting_tests.cpp \
|
||||
wallet/test/db_tests.cpp \
|
||||
wallet/test/psbt_wallet_tests.cpp \
|
||||
wallet/test/wallet_tests.cpp \
|
||||
|
@ -44,8 +44,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "settxfee", 0, "amount" },
|
||||
{ "getreceivedbyaddress", 1, "minconf" },
|
||||
{ "getreceivedbyaddress", 2, "addlocked" },
|
||||
{ "getreceivedbyaccount", 1, "minconf" },
|
||||
{ "getreceivedbyaccount", 2, "addlocked" },
|
||||
{ "getreceivedbylabel", 1, "minconf" },
|
||||
{ "getreceivedbylabel", 2, "addlocked" },
|
||||
{ "listaddressbalances", 0, "minamount" },
|
||||
@ -53,10 +51,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "listreceivedbyaddress", 1, "addlocked" },
|
||||
{ "listreceivedbyaddress", 2, "include_empty" },
|
||||
{ "listreceivedbyaddress", 3, "include_watchonly" },
|
||||
{ "listreceivedbyaccount", 0, "minconf" },
|
||||
{ "listreceivedbyaccount", 1, "addlocked" },
|
||||
{ "listreceivedbyaccount", 2, "include_empty" },
|
||||
{ "listreceivedbyaccount", 3, "include_watchonly" },
|
||||
{ "listreceivedbylabel", 0, "minconf" },
|
||||
{ "listreceivedbylabel", 1, "addlocked" },
|
||||
{ "listreceivedbylabel", 2, "include_empty" },
|
||||
@ -72,17 +66,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "waitforblockheight", 1, "timeout" },
|
||||
{ "waitforblock", 1, "timeout" },
|
||||
{ "waitfornewblock", 0, "timeout" },
|
||||
{ "move", 2, "amount" },
|
||||
{ "move", 3, "minconf" },
|
||||
{ "sendfrom", 2, "amount" },
|
||||
{ "sendfrom", 3, "minconf" },
|
||||
{ "sendfrom", 4, "addlocked" },
|
||||
{ "listtransactions", 1, "count" },
|
||||
{ "listtransactions", 2, "skip" },
|
||||
{ "listtransactions", 3, "include_watchonly" },
|
||||
{ "listaccounts", 0, "minconf" },
|
||||
{ "listaccounts", 1, "addlocked" },
|
||||
{ "listaccounts", 2, "include_watchonly" },
|
||||
{ "walletpassphrase", 1, "timeout" },
|
||||
{ "walletpassphrase", 2, "mixingonly" },
|
||||
{ "getblocktemplate", 0, "template_request" },
|
||||
|
@ -1353,7 +1353,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
||||
" \"keys\": [\"<key>\", ... ] , (array, optional) Array of strings giving private keys whose corresponding public keys must occur in the output or redeemscript\n"
|
||||
" \"internal\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be treated as not incoming payments aka change\n"
|
||||
" \"watchonly\": <true> , (boolean, optional, default: false) Stating whether matching outputs should be considered watched even when they're not spendable, only allowed if keys are empty\n"
|
||||
" \"label\": <label> , (string, optional, default: '') Label to assign to the address (aka account name, for now), only allowed with internal=false\n"
|
||||
" \"label\": <label> , (string, optional, default: '') Label to assign to the address, only allowed with internal=false\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
" ]\n"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,137 +0,0 @@
|
||||
// Copyright (c) 2012-2015 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <wallet/wallet.h>
|
||||
#include <validation.h> // for cs_main because of AddToWallet
|
||||
|
||||
#include <wallet/test/wallet_test_fixture.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(accounting_tests, WalletTestingSetup)
|
||||
|
||||
static void
|
||||
GetResults(CWallet& wallet, std::map<CAmount, CAccountingEntry>& results)
|
||||
{
|
||||
std::list<CAccountingEntry> aes;
|
||||
|
||||
results.clear();
|
||||
BOOST_CHECK(wallet.ReorderTransactions() == DBErrors::LOAD_OK);
|
||||
wallet.ListAccountCreditDebit("", aes);
|
||||
for (CAccountingEntry& ae : aes)
|
||||
{
|
||||
results[ae.nOrderPos] = ae;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(acc_orderupgrade)
|
||||
{
|
||||
std::vector<CWalletTx*> vpwtx;
|
||||
CWalletTx wtx(nullptr /* pwallet */, MakeTransactionRef());
|
||||
CAccountingEntry ae;
|
||||
std::map<CAmount, CAccountingEntry> results;
|
||||
|
||||
LOCK2(cs_main, m_wallet.cs_wallet);
|
||||
|
||||
ae.strAccount = "";
|
||||
ae.nCreditDebit = 1;
|
||||
ae.nTime = 1333333333;
|
||||
ae.strOtherAccount = "b";
|
||||
ae.strComment = "";
|
||||
m_wallet.AddAccountingEntry(ae);
|
||||
|
||||
wtx.mapValue["comment"] = "z";
|
||||
m_wallet.AddToWallet(wtx);
|
||||
vpwtx.push_back(&m_wallet.mapWallet.at(wtx.GetHash()));
|
||||
vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
|
||||
vpwtx[0]->nOrderPos = -1;
|
||||
|
||||
ae.nTime = 1333333336;
|
||||
ae.strOtherAccount = "c";
|
||||
m_wallet.AddAccountingEntry(ae);
|
||||
|
||||
GetResults(m_wallet, results);
|
||||
|
||||
BOOST_CHECK(m_wallet.nOrderPosNext == 3);
|
||||
BOOST_CHECK(2 == results.size());
|
||||
BOOST_CHECK(results[0].nTime == 1333333333);
|
||||
BOOST_CHECK(results[0].strComment.empty());
|
||||
BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
|
||||
BOOST_CHECK(results[2].nTime == 1333333336);
|
||||
BOOST_CHECK(results[2].strOtherAccount == "c");
|
||||
|
||||
|
||||
ae.nTime = 1333333330;
|
||||
ae.strOtherAccount = "d";
|
||||
ae.nOrderPos = m_wallet.IncOrderPosNext();
|
||||
m_wallet.AddAccountingEntry(ae);
|
||||
|
||||
GetResults(m_wallet, results);
|
||||
|
||||
BOOST_CHECK(results.size() == 3);
|
||||
BOOST_CHECK(m_wallet.nOrderPosNext == 4);
|
||||
BOOST_CHECK(results[0].nTime == 1333333333);
|
||||
BOOST_CHECK(1 == vpwtx[0]->nOrderPos);
|
||||
BOOST_CHECK(results[2].nTime == 1333333336);
|
||||
BOOST_CHECK(results[3].nTime == 1333333330);
|
||||
BOOST_CHECK(results[3].strComment.empty());
|
||||
|
||||
|
||||
wtx.mapValue["comment"] = "y";
|
||||
{
|
||||
CMutableTransaction tx(*wtx.tx);
|
||||
++tx.nLockTime; // Just to change the hash :)
|
||||
wtx.SetTx(MakeTransactionRef(std::move(tx)));
|
||||
}
|
||||
m_wallet.AddToWallet(wtx);
|
||||
vpwtx.push_back(&m_wallet.mapWallet.at(wtx.GetHash()));
|
||||
vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
|
||||
|
||||
wtx.mapValue["comment"] = "x";
|
||||
{
|
||||
CMutableTransaction tx(*wtx.tx);
|
||||
++tx.nLockTime; // Just to change the hash :)
|
||||
wtx.SetTx(MakeTransactionRef(std::move(tx)));
|
||||
}
|
||||
m_wallet.AddToWallet(wtx);
|
||||
vpwtx.push_back(&m_wallet.mapWallet.at(wtx.GetHash()));
|
||||
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
|
||||
vpwtx[2]->nOrderPos = -1;
|
||||
|
||||
GetResults(m_wallet, results);
|
||||
|
||||
BOOST_CHECK(results.size() == 3);
|
||||
BOOST_CHECK(m_wallet.nOrderPosNext == 6);
|
||||
BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
|
||||
BOOST_CHECK(results[1].nTime == 1333333333);
|
||||
BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
|
||||
BOOST_CHECK(results[3].nTime == 1333333336);
|
||||
BOOST_CHECK(results[4].nTime == 1333333330);
|
||||
BOOST_CHECK(results[4].strComment.empty());
|
||||
BOOST_CHECK(5 == vpwtx[1]->nOrderPos);
|
||||
|
||||
|
||||
ae.nTime = 1333333334;
|
||||
ae.strOtherAccount = "e";
|
||||
ae.nOrderPos = -1;
|
||||
m_wallet.AddAccountingEntry(ae);
|
||||
|
||||
GetResults(m_wallet, results);
|
||||
|
||||
BOOST_CHECK(results.size() == 4);
|
||||
BOOST_CHECK(m_wallet.nOrderPosNext == 7);
|
||||
BOOST_CHECK(0 == vpwtx[2]->nOrderPos);
|
||||
BOOST_CHECK(results[1].nTime == 1333333333);
|
||||
BOOST_CHECK(2 == vpwtx[0]->nOrderPos);
|
||||
BOOST_CHECK(results[3].nTime == 1333333336);
|
||||
BOOST_CHECK(results[3].strComment.empty());
|
||||
BOOST_CHECK(results[4].nTime == 1333333330);
|
||||
BOOST_CHECK(results[4].strComment.empty());
|
||||
BOOST_CHECK(results[5].nTime == 1333333334);
|
||||
BOOST_CHECK(6 == vpwtx[1]->nOrderPos);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
@ -309,7 +309,7 @@ public:
|
||||
* serialized in the wallet database:
|
||||
*
|
||||
* "comment", "to" - comment strings provided to sendtoaddress,
|
||||
* sendfrom, sendmany wallet RPCs
|
||||
* and sendmany wallet RPCs
|
||||
* "replaces_txid" - txid (as HexStr) of transaction replaced by
|
||||
* bumpfee on transaction created by bumpfee
|
||||
* "replaced_by_txid" - txid (as HexStr) of transaction created by
|
||||
|
@ -4,13 +4,12 @@
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test deprecation of RPC calls."""
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_raises_rpc_error
|
||||
|
||||
class DeprecatedRpcTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = True
|
||||
self.extra_args = [[], ["-deprecatedrpc=validateaddress", "-deprecatedrpc=accounts"]]
|
||||
self.extra_args = [[], ["-deprecatedrpc=validateaddress"]]
|
||||
|
||||
def run_test(self):
|
||||
# This test should be used to verify correct behaviour of deprecated
|
||||
@ -21,82 +20,5 @@ class DeprecatedRpcTest(BitcoinTestFramework):
|
||||
# self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
|
||||
pass
|
||||
|
||||
self.log.info("Test accounts deprecation")
|
||||
# The following account RPC methods are deprecated:
|
||||
# - getaccount
|
||||
# - getaccountaddress
|
||||
# - getaddressesbyaccount
|
||||
# - getreceivedbyaccount
|
||||
# - listaccouts
|
||||
# - listreceivedbyaccount
|
||||
# - move
|
||||
# - setaccount
|
||||
#
|
||||
# The following 'label' RPC methods are usable both with and without the
|
||||
# -deprecatedrpc=accounts switch enabled.
|
||||
# - getaddressesbylabel
|
||||
# - getreceivedbylabel
|
||||
# - listlabels
|
||||
# - listreceivedbylabel
|
||||
# - setlabel
|
||||
#
|
||||
address0 = self.nodes[0].getnewaddress()
|
||||
self.nodes[0].generatetoaddress(101, address0)
|
||||
self.sync_all()
|
||||
address1 = self.nodes[1].getnewaddress()
|
||||
self.nodes[1].generatetoaddress(101, address1)
|
||||
|
||||
self.log.info("- getaccount")
|
||||
assert_raises_rpc_error(-32, "getaccount is deprecated", self.nodes[0].getaccount, address0)
|
||||
self.nodes[1].getaccount(address1)
|
||||
|
||||
self.log.info("- setaccount")
|
||||
assert_raises_rpc_error(-32, "setaccount is deprecated", self.nodes[0].setaccount, address0, "label0")
|
||||
self.nodes[1].setaccount(address1, "label1")
|
||||
|
||||
self.log.info("- setlabel")
|
||||
self.nodes[0].setlabel(address0, "label0")
|
||||
self.nodes[1].setlabel(address1, "label1")
|
||||
|
||||
self.log.info("- getaccountaddress")
|
||||
assert_raises_rpc_error(-32, "getaccountaddress is deprecated", self.nodes[0].getaccountaddress, "label0")
|
||||
self.nodes[1].getaccountaddress("label1")
|
||||
|
||||
self.log.info("- getaddressesbyaccount")
|
||||
assert_raises_rpc_error(-32, "getaddressesbyaccount is deprecated", self.nodes[0].getaddressesbyaccount, "label0")
|
||||
self.nodes[1].getaddressesbyaccount("label1")
|
||||
|
||||
self.log.info("- getaddressesbylabel")
|
||||
self.nodes[0].getaddressesbylabel("label0")
|
||||
self.nodes[1].getaddressesbylabel("label1")
|
||||
|
||||
self.log.info("- getreceivedbyaccount")
|
||||
assert_raises_rpc_error(-32, "getreceivedbyaccount is deprecated", self.nodes[0].getreceivedbyaccount, "label0")
|
||||
self.nodes[1].getreceivedbyaccount("label1")
|
||||
|
||||
self.log.info("- getreceivedbylabel")
|
||||
self.nodes[0].getreceivedbylabel("label0")
|
||||
self.nodes[1].getreceivedbylabel("label1")
|
||||
|
||||
self.log.info("- listaccounts")
|
||||
assert_raises_rpc_error(-32, "listaccounts is deprecated", self.nodes[0].listaccounts)
|
||||
self.nodes[1].listaccounts()
|
||||
|
||||
self.log.info("- listlabels")
|
||||
self.nodes[0].listlabels()
|
||||
self.nodes[1].listlabels()
|
||||
|
||||
self.log.info("- listreceivedbyaccount")
|
||||
assert_raises_rpc_error(-32, "listreceivedbyaccount is deprecated", self.nodes[0].listreceivedbyaccount)
|
||||
self.nodes[1].listreceivedbyaccount()
|
||||
|
||||
self.log.info("- listreceivedbylabel")
|
||||
self.nodes[0].listreceivedbylabel()
|
||||
self.nodes[1].listreceivedbylabel()
|
||||
|
||||
self.log.info("- move")
|
||||
assert_raises_rpc_error(-32, "move is deprecated", self.nodes[0].move, "label0", "label0b", 10)
|
||||
self.nodes[1].move("label1", "label1b", 10)
|
||||
|
||||
if __name__ == '__main__':
|
||||
DeprecatedRpcTest().main()
|
||||
|
@ -5,15 +5,9 @@
|
||||
"""Test label RPCs.
|
||||
|
||||
RPCs tested are:
|
||||
- getaccountaddress
|
||||
- getaddressesbyaccount/getaddressesbylabel
|
||||
- getaddressesbylabel
|
||||
- listaddressgroupings
|
||||
- setlabel
|
||||
- sendfrom (with account arguments)
|
||||
- move (with account arguments)
|
||||
|
||||
Run the test twice - once using the accounts API and once using the labels API.
|
||||
The accounts API test can be removed in V0.18.
|
||||
"""
|
||||
from collections import defaultdict
|
||||
|
||||
@ -23,19 +17,11 @@ from test_framework.util import assert_equal, assert_raises_rpc_error
|
||||
class WalletLabelsTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
self.extra_args = [['-deprecatedrpc=accounts', "-paytxfee=0.0001"], ["-paytxfee=0.0001"]]
|
||||
self.num_nodes = 1
|
||||
|
||||
def run_test(self):
|
||||
"""Run the test twice - once using the accounts API and once using the labels API."""
|
||||
self.log.info("Test accounts API")
|
||||
self.nodes[0].setnetworkactive(False)
|
||||
self._run_subtest(True, self.nodes[0])
|
||||
self.log.info("Test labels API")
|
||||
self._run_subtest(False, self.nodes[1])
|
||||
|
||||
def _run_subtest(self, accounts_api, node):
|
||||
# Check that there's no UTXO on any of the nodes
|
||||
# Check that there's no UTXO on the node
|
||||
node = self.nodes[0]
|
||||
assert_equal(len(node.listunspent()), 0)
|
||||
|
||||
# Note each time we call generate, all generated coins go into
|
||||
@ -58,19 +44,14 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||
linked_addresses.add(address_group[0][0])
|
||||
|
||||
# send 500 from each address to a third address not in this wallet
|
||||
# There's some fee that will come back to us when the miner reward
|
||||
# matures.
|
||||
common_address = "yd5KMREs3GLMe6mTJYr3YrH1juwNwrFCfB"
|
||||
txid = node.sendmany(
|
||||
fromaccount="",
|
||||
node.sendmany(
|
||||
amounts={common_address: 1000},
|
||||
minconf=1,
|
||||
addlocked=False,
|
||||
comment="",
|
||||
subtractfeefrom=[common_address],
|
||||
)
|
||||
tx_details = node.gettransaction(txid)
|
||||
fee = -tx_details['details'][0]['fee']
|
||||
# there should be 1 address group, with the previously
|
||||
# unlinked addresses now linked (they both have 0 balance)
|
||||
address_groups = node.listaddressgroupings()
|
||||
@ -84,17 +65,12 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||
# we want to reset so that the "" label has what's expected.
|
||||
# otherwise we're off by exactly the fee amount as that's mined
|
||||
# and matures in the next 100 blocks
|
||||
if accounts_api:
|
||||
node.sendfrom("", common_address, fee)
|
||||
amount_to_send = 1.0
|
||||
|
||||
# Create labels and make sure subsequent label API calls
|
||||
# recognize the label/address associations.
|
||||
labels = [Label(name, accounts_api) for name in ("a", "b", "c", "d", "e")]
|
||||
labels = [Label(name) for name in ("a", "b", "c", "d", "e")]
|
||||
for label in labels:
|
||||
if accounts_api:
|
||||
address = node.getaccountaddress(label.name)
|
||||
else:
|
||||
address = node.getnewaddress(label.name)
|
||||
label.add_receive_address(address)
|
||||
label.verify(node)
|
||||
@ -102,13 +78,8 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||
# Check all labels are returned by listlabels.
|
||||
assert_equal(node.listlabels(), [label.name for label in labels])
|
||||
|
||||
# Send a transaction to each label, and make sure this forces
|
||||
# getaccountaddress to generate a new receiving address.
|
||||
# Send a transaction to each label.
|
||||
for label in labels:
|
||||
if accounts_api:
|
||||
node.sendtoaddress(label.receive_address, amount_to_send)
|
||||
label.add_receive_address(node.getaccountaddress(label.name))
|
||||
else:
|
||||
node.sendtoaddress(label.addresses[0], amount_to_send)
|
||||
label.verify(node)
|
||||
|
||||
@ -119,32 +90,17 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||
node.getreceivedbyaddress(label.addresses[0]), amount_to_send)
|
||||
assert_equal(node.getreceivedbylabel(label.name), amount_to_send)
|
||||
|
||||
# Check that sendfrom label reduces listaccounts balances.
|
||||
for i, label in enumerate(labels):
|
||||
to_label = labels[(i + 1) % len(labels)]
|
||||
if accounts_api:
|
||||
node.sendfrom(label.name, to_label.receive_address, amount_to_send)
|
||||
else:
|
||||
node.sendtoaddress(to_label.addresses[0], amount_to_send)
|
||||
node.generate(1)
|
||||
for label in labels:
|
||||
if accounts_api:
|
||||
address = node.getaccountaddress(label.name)
|
||||
else:
|
||||
address = node.getnewaddress(label.name)
|
||||
label.add_receive_address(address)
|
||||
label.verify(node)
|
||||
assert_equal(node.getreceivedbylabel(label.name), 2)
|
||||
if accounts_api:
|
||||
node.move(label.name, "", node.getbalance(label.name))
|
||||
label.verify(node)
|
||||
node.generate(101)
|
||||
expected_account_balances = {"": 52000}
|
||||
for label in labels:
|
||||
expected_account_balances[label.name] = 0
|
||||
if accounts_api:
|
||||
assert_equal(node.listaccounts(), expected_account_balances)
|
||||
assert_equal(node.getbalance(""), 52000)
|
||||
|
||||
# Check that setlabel can assign a label to a new unused address.
|
||||
for label in labels:
|
||||
@ -152,9 +108,6 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||
node.setlabel(address, label.name)
|
||||
label.add_address(address)
|
||||
label.verify(node)
|
||||
if accounts_api:
|
||||
assert address not in node.getaddressesbyaccount("")
|
||||
else:
|
||||
assert_raises_rpc_error(-11, "No addresses with label", node.getaddressesbylabel, "")
|
||||
|
||||
# Check that addmultisigaddress can assign labels.
|
||||
@ -166,35 +119,20 @@ class WalletLabelsTest(BitcoinTestFramework):
|
||||
label.add_address(multisig_address)
|
||||
label.purpose[multisig_address] = "send"
|
||||
label.verify(node)
|
||||
if accounts_api:
|
||||
node.sendfrom("", multisig_address, 50)
|
||||
node.generate(101)
|
||||
if accounts_api:
|
||||
for label in labels:
|
||||
assert_equal(node.getbalance(label.name), 50)
|
||||
|
||||
# Check that setlabel can change the label of an address from a
|
||||
# different label.
|
||||
change_label(node, labels[0].addresses[0], labels[0], labels[1], accounts_api)
|
||||
change_label(node, labels[0].addresses[0], labels[0], labels[1])
|
||||
|
||||
# Check that setlabel can set the label of an address already
|
||||
# in the label. This is a no-op.
|
||||
change_label(node, labels[2].addresses[0], labels[2], labels[2], accounts_api)
|
||||
|
||||
if accounts_api:
|
||||
# Check that setaccount can change the label of an address which
|
||||
# is the receiving address of a different label.
|
||||
change_label(node, labels[0].receive_address, labels[0], labels[1], accounts_api)
|
||||
|
||||
# Check that setaccount can set the label of an address which is
|
||||
# already the receiving address of the label. This is a no-op.
|
||||
change_label(node, labels[2].receive_address, labels[2], labels[2], accounts_api)
|
||||
change_label(node, labels[2].addresses[0], labels[2], labels[2])
|
||||
|
||||
class Label:
|
||||
def __init__(self, name, accounts_api):
|
||||
def __init__(self, name):
|
||||
# Label name
|
||||
self.name = name
|
||||
self.accounts_api = accounts_api
|
||||
# Current receiving address associated with this label.
|
||||
self.receive_address = None
|
||||
# List of all addresses assigned with this label
|
||||
@ -208,56 +146,31 @@ class Label:
|
||||
|
||||
def add_receive_address(self, address):
|
||||
self.add_address(address)
|
||||
if self.accounts_api:
|
||||
self.receive_address = address
|
||||
|
||||
def verify(self, node):
|
||||
if self.receive_address is not None:
|
||||
assert self.receive_address in self.addresses
|
||||
if self.accounts_api:
|
||||
assert_equal(node.getaccountaddress(self.name), self.receive_address)
|
||||
|
||||
for address in self.addresses:
|
||||
assert_equal(
|
||||
node.getaddressinfo(address)['labels'][0],
|
||||
{"name": self.name,
|
||||
"purpose": self.purpose[address]})
|
||||
if self.accounts_api:
|
||||
assert_equal(node.getaccount(address), self.name)
|
||||
else:
|
||||
assert_equal(node.getaddressinfo(address)['label'], self.name)
|
||||
|
||||
assert_equal(
|
||||
node.getaddressesbylabel(self.name),
|
||||
{address: {"purpose": self.purpose[address]} for address in self.addresses})
|
||||
if self.accounts_api:
|
||||
assert_equal(set(node.getaddressesbyaccount(self.name)), set(self.addresses))
|
||||
|
||||
|
||||
def change_label(node, address, old_label, new_label, accounts_api):
|
||||
def change_label(node, address, old_label, new_label):
|
||||
assert_equal(address in old_label.addresses, True)
|
||||
if accounts_api:
|
||||
node.setaccount(address, new_label.name)
|
||||
else:
|
||||
node.setlabel(address, new_label.name)
|
||||
|
||||
old_label.addresses.remove(address)
|
||||
new_label.add_address(address)
|
||||
|
||||
# Calling setaccount on an address which was previously the receiving
|
||||
# address of a different account should reset the receiving address of
|
||||
# the old account, causing getaccountaddress to return a brand new
|
||||
# address.
|
||||
if accounts_api:
|
||||
if old_label.name != new_label.name and address == old_label.receive_address:
|
||||
new_address = node.getaccountaddress(old_label.name)
|
||||
assert_equal(new_address not in old_label.addresses, True)
|
||||
assert_equal(new_address not in new_label.addresses, True)
|
||||
old_label.add_receive_address(new_address)
|
||||
|
||||
old_label.verify(node)
|
||||
new_label.verify(node)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletLabelsTest().main()
|
||||
|
Loading…
Reference in New Issue
Block a user