|
48 | 48 | # The size of the blocks xor key |
49 | 49 | # from InitBlocksdirXorKey::xor_key.size() |
50 | 50 | NUM_XOR_BYTES = 8 |
51 | | -CLI_MAX_ARG_SIZE = 131071 # many systems have a 128kb limit per arg (MAX_ARG_STRLEN) |
| 51 | +# Many systems have a 128kB limit for a command size. Depending on the |
| 52 | +# platform, this limit may be larger or smaller. Moreover, when using the |
| 53 | +# 'bitcoin' command, it may internally insert more args, which must be |
| 54 | +# accounted for. There is no need to pick the largest possible value here |
| 55 | +# anyway and it should be fine to set it to 1kB in tests. |
| 56 | +TEST_CLI_MAX_ARG_SIZE = 1024 |
52 | 57 |
|
53 | 58 | # The null blocks key (all 0s) |
54 | 59 | NULL_BLK_XOR_KEY = bytes([0] * NUM_XOR_BYTES) |
@@ -951,10 +956,14 @@ def send_cli(self, clicommand=None, *args, **kwargs): |
951 | 956 | if clicommand is not None: |
952 | 957 | p_args += [clicommand] |
953 | 958 | p_args += pos_args + named_args |
954 | | - max_arg_size = max(len(arg) for arg in p_args) |
| 959 | + |
| 960 | + # TEST_CLI_MAX_ARG_SIZE is set low enough that checking the string |
| 961 | + # length is enough and encoding to bytes is not needed before |
| 962 | + # calculating the sum. |
| 963 | + sum_arg_size = sum(len(arg) for arg in p_args) |
955 | 964 | stdin_data = self.input |
956 | | - if max_arg_size > CLI_MAX_ARG_SIZE: |
957 | | - self.log.debug(f"Cli: Command size {max_arg_size} too large, using stdin") |
| 965 | + if sum_arg_size >= TEST_CLI_MAX_ARG_SIZE: |
| 966 | + self.log.debug(f"Cli: Command size {sum_arg_size} too large, using stdin") |
958 | 967 | rpc_args = "\n".join([arg for arg in p_args[base_arg_pos:]]) |
959 | 968 | if stdin_data is not None: |
960 | 969 | stdin_data += "\n" + rpc_args |
|
0 commit comments