Skip to content

Commit 21857d2

Browse files
committed
Merge #8450: [Test] Replace rpc_wallet_tests.cpp with python RPC unit tests
9578333 Remove rpc_wallet_tests.cpp (Patrick Strateman) 25400c4 Account wallet feature RPC tests. (Patrick Strateman)
2 parents f12d2b5 + 9578333 commit 21857d2

File tree

4 files changed

+96
-231
lines changed

4 files changed

+96
-231
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
'walletbackup.py',
105105
'bip68-112-113-p2p.py',
106106
'wallet.py',
107+
'wallet-accounts.py',
107108
'wallet-hd.py',
108109
'wallet-dump.py',
109110
'listtransactions.py',

qa/rpc-tests/wallet-accounts.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2016 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import (
8+
start_nodes,
9+
start_node,
10+
assert_equal,
11+
connect_nodes_bi,
12+
)
13+
14+
15+
class WalletAccountsTest(BitcoinTestFramework):
16+
17+
def __init__(self):
18+
super().__init__()
19+
self.setup_clean_chain = True
20+
self.num_nodes = 1
21+
self.node_args = [[]]
22+
23+
def setup_network(self):
24+
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.node_args)
25+
self.is_network_split = False
26+
27+
def run_test (self):
28+
node = self.nodes[0]
29+
# Check that there's no UTXO on any of the nodes
30+
assert_equal(len(node.listunspent()), 0)
31+
32+
node.generate(101)
33+
34+
assert_equal(node.getbalance(), 50)
35+
36+
accounts = ["a","b","c","d","e"]
37+
amount_to_send = 1.0
38+
account_addresses = dict()
39+
for account in accounts:
40+
address = node.getaccountaddress(account)
41+
account_addresses[account] = address
42+
43+
node.getnewaddress(account)
44+
assert_equal(node.getaccount(address), account)
45+
assert(address in node.getaddressesbyaccount(account))
46+
47+
node.sendfrom("", address, amount_to_send)
48+
49+
node.generate(1)
50+
51+
for i in range(len(accounts)):
52+
from_account = accounts[i]
53+
to_account = accounts[(i+1)%len(accounts)]
54+
to_address = account_addresses[to_account]
55+
node.sendfrom(from_account, to_address, amount_to_send)
56+
57+
node.generate(1)
58+
59+
for account in accounts:
60+
address = node.getaccountaddress(account)
61+
assert(address != account_addresses[account])
62+
assert_equal(node.getreceivedbyaccount(account), 2)
63+
node.move(account, "", node.getbalance(account))
64+
65+
node.generate(101)
66+
67+
expected_account_balances = {"": 5200}
68+
for account in accounts:
69+
expected_account_balances[account] = 0
70+
71+
assert_equal(node.listaccounts(), expected_account_balances)
72+
73+
assert_equal(node.getbalance(""), 5200)
74+
75+
for account in accounts:
76+
address = node.getaccountaddress("")
77+
node.setaccount(address, account)
78+
assert(address in node.getaddressesbyaccount(account))
79+
assert(address not in node.getaddressesbyaccount(""))
80+
81+
for account in accounts:
82+
addresses = []
83+
for x in range(10):
84+
addresses.append(node.getnewaddress())
85+
multisig_address = node.addmultisigaddress(5, addresses, account)
86+
node.sendfrom("", multisig_address, 50)
87+
88+
node.generate(101)
89+
90+
for account in accounts:
91+
assert_equal(node.getbalance(account), 50)
92+
93+
if __name__ == '__main__':
94+
WalletAccountsTest().main ()

src/Makefile.test.include

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ BITCOIN_TESTS += \
9797
wallet/test/wallet_test_fixture.h \
9898
wallet/test/accounting_tests.cpp \
9999
wallet/test/wallet_tests.cpp \
100-
wallet/test/crypto_tests.cpp \
101-
wallet/test/rpc_wallet_tests.cpp
100+
wallet/test/crypto_tests.cpp
102101
endif
103102

104103
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)

src/wallet/test/rpc_wallet_tests.cpp

Lines changed: 0 additions & 229 deletions
This file was deleted.

0 commit comments

Comments
 (0)