|
| 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.blocktools import COINBASE_MATURITY |
| 8 | +from test_framework.test_framework import BitcoinTestFramework |
| 9 | +from test_framework.util import ( |
| 10 | + assert_equal, |
| 11 | +) |
| 12 | + |
| 13 | +class WalletTest(BitcoinTestFramework): |
| 14 | + def set_test_params(self): |
| 15 | + self.setup_clean_chain = True |
| 16 | + self.num_nodes = 3 |
| 17 | + self.extra_args = [[ |
| 18 | + "-blindedaddresses=1", |
| 19 | + "-initialfreecoins=2100000000000000", |
| 20 | + "-con_blocksubsidy=0", |
| 21 | + "-con_connect_genesis_outputs=1", |
| 22 | + "-txindex=1", |
| 23 | + "-minrelaytxfee=0", |
| 24 | + "-blockmintxfee=0", |
| 25 | + "-mintxfee=0", |
| 26 | + ]] * self.num_nodes |
| 27 | + self.extra_args[0].append("-anyonecanspendaremine=1") |
| 28 | + |
| 29 | + def skip_test_if_missing_module(self): |
| 30 | + self.skip_if_no_wallet() |
| 31 | + |
| 32 | + def run_test(self): |
| 33 | + self.generate(self.nodes[0], COINBASE_MATURITY + 1) |
| 34 | + self.sync_all() |
| 35 | + |
| 36 | + self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10) |
| 37 | + self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 20) |
| 38 | + self.generate(self.nodes[0], 1) |
| 39 | + assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 102) |
| 40 | + assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('20999969.99900900')}) |
| 41 | + assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('10.00000000')}) |
| 42 | + assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('20.00000000')}) |
| 43 | + |
| 44 | + addr = self.nodes[1].getnewaddress() |
| 45 | + txid = self.nodes[0].sendtoaddress(addr, 1, None, None, None, None, None, None, None, None, None, 0, False) |
| 46 | + tx = self.nodes[0].gettransaction(txid) |
| 47 | + assert_equal(tx["fee"]["bitcoin"], 0) |
| 48 | + hex = self.nodes[0].getrawtransaction(txid) |
| 49 | + self.generate(self.nodes[0], 1) |
| 50 | + assert_equal(self.nodes[0].getblockchaininfo()["blocks"], 103) |
| 51 | + |
| 52 | + decoded = self.nodes[0].decoderawtransaction(hex) |
| 53 | + bitcoin = "b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23" |
| 54 | + assert_equal(decoded["fee"][bitcoin], 0) |
| 55 | + assert_equal(self.nodes[0].getbalance(), {'bitcoin': Decimal('20999968.99900900')}) |
| 56 | + assert_equal(self.nodes[1].getbalance(), {'bitcoin': Decimal('11.00000000')}) |
| 57 | + assert_equal(self.nodes[2].getbalance(), {'bitcoin': Decimal('20.00000000')}) |
| 58 | + |
| 59 | +if __name__ == '__main__': |
| 60 | + WalletTest().main() |
0 commit comments