|
| 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 () |
0 commit comments