test: Add functional tests for named argument parsing

This commit is contained in:
zaidmstrr
2025-06-29 00:19:22 +05:30
parent 694f04e2bd
commit f53dbbc505
3 changed files with 82 additions and 0 deletions

View File

@@ -94,8 +94,30 @@ class TestBitcoinCli(BitcoinTestFramework):
assert re.match(rf"^{re.escape(self.config['environment']['CLIENT_NAME'])} client.+services nwl2?$", det[0])
assert not any(line.startswith("Local services:") for line in det)
def test_echojson_positional_equals(self):
"""Test JSON parameter parsing containing '=' with -named echojson"""
self.log.info("Test JSON parameter parsing containing '=' is handled correctly with -named")
# This should be treated as a positional JSON argument, not as a named
result = self.nodes[0].cli("-named", "echojson", '["key=value"]').send_cli()
assert_equal(result, [["key=value"]])
result = self.nodes[0].cli("-named", "echojson", '["key=value", "another=test"]').send_cli()
assert_equal(result, [["key=value", "another=test"]])
result = self.nodes[0].cli("-named", "echojson", '["data=test"]', "42").send_cli()
expected = [["data=test"], 42]
assert_equal(result, expected)
# This should be treated as a named parameter, as arg0 and arg1 are valid parameter names
result = self.nodes[0].cli("-named", "echojson", 'arg0=["data=test"]', 'arg1=42').send_cli()
expected = [["data=test"], 42]
assert_equal(result, expected)
def run_test(self):
"""Main test logic"""
self.test_echojson_positional_equals()
self.generate(self.nodes[0], BLOCKS)
self.log.info("Compare responses from getblockchaininfo RPC and `bitcoin-cli getblockchaininfo`")