Skip to content

Commit 661e8df

Browse files
author
MarcoFalke
committed
Merge #18653: test: add coverage for bitcoin-cli -rpcwait
c28c7b8 test: add -getinfo "unlocked_until" and "headers" coverage (Jon Atack) bb13f46 test: verify cli.getwalletinfo in wallet section (Jon Atack) becc8b9 test: verify bitcoin-cli -version with node stopped (Jon Atack) 727b67e test: add coverage for bitcoin-cli -rpcwait (Jon Atack) Pull request description: and other coverage improvements in `interface-bitcoin_cli.py` ACKs for top commit: kristapsk: ACK c28c7b8 Tree-SHA512: c3ac73b673872cba05496e3f9debc2c4dfa4291c6426bf0be9bb0242035613b25c0aecebb39abb14a1d87b13e1d28a5f34b21d4b77d93de56c679a8be92bbe82
2 parents 79b0459 + c28c7b8 commit 661e8df

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

test/functional/interface_bitcoin_cli.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ def run_test(self):
2525
"""Main test logic"""
2626
self.nodes[0].generate(BLOCKS)
2727

28-
cli_response = self.nodes[0].cli("-version").send_cli()
29-
assert "{} RPC client version".format(self.config['environment']['PACKAGE_NAME']) in cli_response
30-
31-
self.log.info("Compare responses from getwalletinfo RPC and `bitcoin-cli getwalletinfo`")
32-
if self.is_wallet_compiled():
33-
cli_response = self.nodes[0].cli.getwalletinfo()
34-
rpc_response = self.nodes[0].getwalletinfo()
35-
assert_equal(cli_response, rpc_response)
36-
3728
self.log.info("Compare responses from getblockchaininfo RPC and `bitcoin-cli getblockchaininfo`")
3829
cli_response = self.nodes[0].cli.getblockchaininfo()
3930
rpc_response = self.nodes[0].getblockchaininfo()
@@ -55,31 +46,50 @@ def run_test(self):
5546
self.log.info("Test connecting with non-existing RPC cookie file")
5647
assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli('-rpccookiefile=does-not-exist', '-rpcpassword=').echo)
5748

58-
self.log.info("Make sure that -getinfo with arguments fails")
49+
self.log.info("Test -getinfo with arguments fails")
5950
assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help)
6051

61-
self.log.info("Test that -getinfo returns the expected network and blockchain info")
52+
self.log.info("Test -getinfo returns expected network and blockchain info")
53+
if self.is_wallet_compiled():
54+
self.nodes[0].encryptwallet(password)
6255
cli_get_info = self.nodes[0].cli('-getinfo').send_cli()
6356
network_info = self.nodes[0].getnetworkinfo()
6457
blockchain_info = self.nodes[0].getblockchaininfo()
65-
6658
assert_equal(cli_get_info['version'], network_info['version'])
6759
assert_equal(cli_get_info['blocks'], blockchain_info['blocks'])
60+
assert_equal(cli_get_info['headers'], blockchain_info['headers'])
6861
assert_equal(cli_get_info['timeoffset'], network_info['timeoffset'])
6962
assert_equal(cli_get_info['connections'], network_info['connections'])
7063
assert_equal(cli_get_info['proxy'], network_info['networks'][0]['proxy'])
7164
assert_equal(cli_get_info['difficulty'], blockchain_info['difficulty'])
7265
assert_equal(cli_get_info['chain'], blockchain_info['chain'])
66+
7367
if self.is_wallet_compiled():
74-
self.log.info("Test that -getinfo returns the expected wallet info")
68+
self.log.info("Test -getinfo and bitcoin-cli getwalletinfo return expected wallet info")
7569
assert_equal(cli_get_info['balance'], BALANCE)
7670
wallet_info = self.nodes[0].getwalletinfo()
7771
assert_equal(cli_get_info['keypoolsize'], wallet_info['keypoolsize'])
72+
assert_equal(cli_get_info['unlocked_until'], wallet_info['unlocked_until'])
7873
assert_equal(cli_get_info['paytxfee'], wallet_info['paytxfee'])
7974
assert_equal(cli_get_info['relayfee'], network_info['relayfee'])
80-
# unlocked_until is not tested because the wallet is not encrypted
75+
assert_equal(self.nodes[0].cli.getwalletinfo(), wallet_info)
8176
else:
82-
self.log.info("*** Wallet not compiled; -getinfo wallet tests skipped")
77+
self.log.info("*** Wallet not compiled; cli getwalletinfo and -getinfo wallet tests skipped")
78+
79+
self.stop_node(0)
80+
81+
self.log.info("Test -version with node stopped")
82+
cli_response = self.nodes[0].cli("-version").send_cli()
83+
assert "{} RPC client version".format(self.config['environment']['PACKAGE_NAME']) in cli_response
84+
85+
self.log.info("Test -rpcwait option waits for RPC connection instead of failing")
86+
# Start node without RPC connection.
87+
self.nodes[0].start()
88+
# Verify failure without -rpcwait.
89+
assert_raises_process_error(1, "Could not connect to the server", self.nodes[0].cli('getblockcount').echo)
90+
# Verify success using -rpcwait.
91+
assert_equal(BLOCKS, self.nodes[0].cli('-rpcwait', 'getblockcount').send_cli())
92+
self.nodes[0].wait_for_rpc_connection()
8393

8494

8595
if __name__ == '__main__':

0 commit comments

Comments
 (0)