Main test logic
(self)
| 80 | self.skip_if_no_cli() |
| 81 | |
| 82 | def run_test(self): |
| 83 | """Main test logic""" |
| 84 | self.generate(self.nodes[0], BLOCKS) |
| 85 | |
| 86 | self.log.info("Compare responses from getblockchaininfo RPC and `elements-cli getblockchaininfo`") |
| 87 | cli_response = self.nodes[0].cli.getblockchaininfo() |
| 88 | rpc_response = self.nodes[0].getblockchaininfo() |
| 89 | assert_equal(cli_response, rpc_response) |
| 90 | |
| 91 | user, password = get_auth_cookie(self.nodes[0].datadir, self.chain) |
| 92 | |
| 93 | self.log.info("Test -stdinrpcpass option") |
| 94 | assert_equal(BLOCKS, self.nodes[0].cli(f'-rpcuser={user}', '-stdinrpcpass', input=password).getblockcount()) |
| 95 | assert_raises_process_error(1, 'Incorrect rpcuser or rpcpassword', self.nodes[0].cli(f'-rpcuser={user}', '-stdinrpcpass', input='foo').echo) |
| 96 | |
| 97 | self.log.info("Test -stdin and -stdinrpcpass") |
| 98 | assert_equal(['foo', 'bar'], self.nodes[0].cli(f'-rpcuser={user}', '-stdin', '-stdinrpcpass', input=f'{password}\nfoo\nbar').echo()) |
| 99 | assert_raises_process_error(1, 'Incorrect rpcuser or rpcpassword', self.nodes[0].cli(f'-rpcuser={user}', '-stdin', '-stdinrpcpass', input='foo').echo) |
| 100 | |
| 101 | self.log.info("Test connecting to a non-existing server") |
| 102 | assert_raises_process_error(1, "Could not connect to the server", self.nodes[0].cli('-rpcport=1').echo) |
| 103 | |
| 104 | self.log.info("Test connecting with non-existing RPC cookie file") |
| 105 | assert_raises_process_error(1, "Could not locate RPC credentials", self.nodes[0].cli('-rpccookiefile=does-not-exist', '-rpcpassword=').echo) |
| 106 | |
| 107 | self.log.info("Test -getinfo with arguments fails") |
| 108 | assert_raises_process_error(1, "-getinfo takes no arguments", self.nodes[0].cli('-getinfo').help) |
| 109 | |
| 110 | self.log.info("Test -getinfo with -color=never does not return ANSI escape codes") |
| 111 | assert "\u001b[0m" not in self.nodes[0].cli('-getinfo', '-color=never').send_cli() |
| 112 | |
| 113 | self.log.info("Test -getinfo with -color=always returns ANSI escape codes") |
| 114 | assert "\u001b[0m" in self.nodes[0].cli('-getinfo', '-color=always').send_cli() |
| 115 | |
| 116 | self.log.info("Test -getinfo with invalid value for -color option") |
| 117 | assert_raises_process_error(1, "Invalid value for -color option. Valid values: always, auto, never.", self.nodes[0].cli('-getinfo', '-color=foo').send_cli) |
| 118 | |
| 119 | self.log.info("Test -getinfo returns expected network and blockchain info") |
| 120 | if self.is_specified_wallet_compiled(): |
| 121 | self.nodes[0].encryptwallet(password) |
| 122 | cli_get_info_string = self.nodes[0].cli('-getinfo').send_cli() |
| 123 | cli_get_info = cli_get_info_string_to_dict(cli_get_info_string) |
| 124 | |
| 125 | network_info = self.nodes[0].getnetworkinfo() |
| 126 | blockchain_info = self.nodes[0].getblockchaininfo() |
| 127 | assert_equal(int(cli_get_info['Version']), network_info['version']) |
| 128 | assert_equal(cli_get_info['Verification progress'], "%.4f%%" % (blockchain_info['verificationprogress'] * 100)) |
| 129 | assert_equal(int(cli_get_info['Blocks']), blockchain_info['blocks']) |
| 130 | assert_equal(int(cli_get_info['Headers']), blockchain_info['headers']) |
| 131 | assert_equal(int(cli_get_info['Time offset (s)']), network_info['timeoffset']) |
| 132 | expected_network_info = f"in {network_info['connections_in']}, out {network_info['connections_out']}, total {network_info['connections']}" |
| 133 | assert_equal(cli_get_info["Network"], expected_network_info) |
| 134 | assert_equal(cli_get_info['Proxies'], network_info['networks'][0]['proxy']) |
| 135 | if (cli_get_info['Difficulty'] != "") or (blockchain_info.get('difficulty', None) is not None): |
| 136 | # These fields are missing for signed chains |
| 137 | assert_equal(Decimal(cli_get_info['Difficulty']), blockchain_info['difficulty']) |
| 138 | assert_equal(cli_get_info['Chain'], blockchain_info['chain']) |
| 139 |
nothing calls this directly
no test coverage detected