Skip to content

Commit 5df0877

Browse files
committed
test: update and harden interface_bitcoin_cli tests
- no longer depend on the deprecated balance field of getwalletinfo - test blockcount and balance against non-default, non-zero expected values
1 parent 7501977 commit 5df0877

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test/functional/interface_bitcoin_cli.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
from test_framework.test_framework import BitcoinTestFramework
77
from test_framework.util import assert_equal, assert_raises_process_error, get_auth_cookie
88

9+
# The block reward of coinbaseoutput.nValue (50) BTC/block matures after
10+
# COINBASE_MATURITY (100) blocks. Therefore, after mining 101 blocks we expect
11+
# node 0 to have a balance of (BLOCKS - COINBASE_MATURITY) * 50 BTC/block.
12+
BLOCKS = 101
13+
BALANCE = (BLOCKS - 100) * 50
14+
915
class TestBitcoinCli(BitcoinTestFramework):
1016

1117
def set_test_params(self):
@@ -17,6 +23,7 @@ def skip_test_if_missing_module(self):
1723

1824
def run_test(self):
1925
"""Main test logic"""
26+
self.nodes[0].generate(BLOCKS)
2027

2128
cli_response = self.nodes[0].cli("-version").send_cli()
2229
assert "{} RPC client version".format(self.config['environment']['PACKAGE_NAME']) in cli_response
@@ -35,7 +42,7 @@ def run_test(self):
3542
user, password = get_auth_cookie(self.nodes[0].datadir, self.chain)
3643

3744
self.log.info("Test -stdinrpcpass option")
38-
assert_equal(0, self.nodes[0].cli('-rpcuser=%s' % user, '-stdinrpcpass', input=password).getblockcount())
45+
assert_equal(BLOCKS, self.nodes[0].cli('-rpcuser=%s' % user, '-stdinrpcpass', input=password).getblockcount())
3946
assert_raises_process_error(1, "Incorrect rpcuser or rpcpassword", self.nodes[0].cli('-rpcuser=%s' % user, '-stdinrpcpass', input="foo").echo)
4047

4148
self.log.info("Test -stdin and -stdinrpcpass")
@@ -51,10 +58,8 @@ def run_test(self):
5158
self.log.info("Make sure that -getinfo with arguments fails")
5259
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
5360

54-
self.log.info("Compare responses from `bitcoin-cli -getinfo` and the RPCs data is retrieved from.")
61+
self.log.info("Test that -getinfo returns the expected network and blockchain info")
5562
cli_get_info = self.nodes[0].cli('-getinfo').send_cli()
56-
if self.is_wallet_compiled():
57-
wallet_info = self.nodes[0].getwalletinfo()
5863
network_info = self.nodes[0].getnetworkinfo()
5964
blockchain_info = self.nodes[0].getblockchaininfo()
6065

@@ -66,11 +71,15 @@ def run_test(self):
6671
assert_equal(cli_get_info['difficulty'], blockchain_info['difficulty'])
6772
assert_equal(cli_get_info['chain'], blockchain_info['chain'])
6873
if self.is_wallet_compiled():
69-
assert_equal(cli_get_info['balance'], wallet_info['balance'])
74+
self.log.info("Test that -getinfo returns the expected wallet info")
75+
assert_equal(cli_get_info['balance'], BALANCE)
76+
wallet_info = self.nodes[0].getwalletinfo()
7077
assert_equal(cli_get_info['keypoolsize'], wallet_info['keypoolsize'])
7178
assert_equal(cli_get_info['paytxfee'], wallet_info['paytxfee'])
7279
assert_equal(cli_get_info['relayfee'], network_info['relayfee'])
7380
# unlocked_until is not tested because the wallet is not encrypted
81+
else:
82+
self.log.info("*** Wallet not compiled; -getinfo wallet tests skipped")
7483

7584

7685
if __name__ == '__main__':

0 commit comments

Comments
 (0)