|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2017-2020 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 | +from decimal import Decimal |
| 6 | + |
| 7 | +from test_framework.test_framework import BitcoinTestFramework |
| 8 | +from test_framework.util import ( |
| 9 | + assert_equal, |
| 10 | +) |
| 11 | + |
| 12 | +class WalletTest(BitcoinTestFramework): |
| 13 | + def set_test_params(self): |
| 14 | + self.num_nodes = 3 |
| 15 | + self.extra_args = [[ |
| 16 | + "-blindedaddresses=1", |
| 17 | + "-minrelaytxfee=0", |
| 18 | + "-blockmintxfee=0", |
| 19 | + "-mintxfee=0", |
| 20 | + ]] * self.num_nodes |
| 21 | + |
| 22 | + def skip_test_if_missing_module(self): |
| 23 | + self.skip_if_no_wallet() |
| 24 | + |
| 25 | + def run_test(self): |
| 26 | + # initial state when setup_clean_chain is False |
| 27 | + assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('1250')}) |
| 28 | + assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('1250')}) |
| 29 | + assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('1250')}) |
| 30 | + assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 200) |
| 31 | + |
| 32 | + self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10) |
| 33 | + self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 20) |
| 34 | + self.generate(self.nodes[0], 1) |
| 35 | + assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 201) |
| 36 | + assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('1269.99897200')}) |
| 37 | + assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('1260')}) |
| 38 | + assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('1270')}) |
| 39 | + |
| 40 | + # send a zero fee_rate transaction, which should not add a fee output |
| 41 | + addr = self.nodes[1].getnewaddress() |
| 42 | + txid = self.nodes[0].sendtoaddress(address=addr, amount=1, fee_rate=0) |
| 43 | + tx = self.nodes[0].getrawtransaction(txid, 2) |
| 44 | + # there should be no fees |
| 45 | + assert "bitcoin" not in tx["fee"] |
| 46 | + assert_equal(tx["fee"], {}) |
| 47 | + # and no fee output |
| 48 | + assert_equal(len(tx["vout"]),2) |
| 49 | + for output in tx["vout"]: |
| 50 | + assert output["scriptPubKey"]["type"] != "fee" |
| 51 | + |
| 52 | + self.generate(self.nodes[0], 1) |
| 53 | + assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 202) |
| 54 | + |
| 55 | + assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('1318.99897200')}) |
| 56 | + assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('1261')}) |
| 57 | + assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('1270')}) |
| 58 | + |
| 59 | +if __name__ == '__main__': |
| 60 | + WalletTest().main() |
0 commit comments