Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2019 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Tests runCommandParseJSON via the runcommand regtest RPC.""" | ||
|
||
import os | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import assert_equal, assert_raises_rpc_error | ||
|
||
class RunCommandInterfaceTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
self.setup_clean_chain = True | ||
|
||
def test_runcommand(self): | ||
self.log.info("Testing runcommand...") | ||
command_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks/command.py') | ||
|
||
res = self.nodes[0].runcommand(command_path + " --success") | ||
assert_equal(res, {"success": True}) | ||
|
||
res = self.nodes[0].runcommand(command_path + " --fail") | ||
assert_equal(res, {"success": False, "error": "reason"}) | ||
|
||
assert_raises_rpc_error(-1, "a", self.nodes[0].runcommand, command_path + " --invalid") | ||
|
||
def run_test(self): | ||
self.test_runcommand() | ||
|
||
if __name__ == '__main__': | ||
RunCommandInterfaceTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2019 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
import argparse | ||
import json | ||
import sys | ||
|
||
def command(args): | ||
if args.invalid: | ||
sys.stdout.write("{") | ||
elif args.success: | ||
sys.stdout.write(json.dumps({"success": True})) | ||
elif args.fail: | ||
sys.stdout.write(json.dumps({"success": False, "error": "reason"})) | ||
else: | ||
raise RuntimeError("Missing arguments") | ||
|
||
|
||
parser = argparse.ArgumentParser(prog='./mock_command.py', description='Test runCommandParseJSON() via runcommand RPC') | ||
parser.add_argument('--success', action='store_true', help='Respond with {success: true}') | ||
parser.add_argument('--fail', action='store_true', help='Respond with {success: false, error: "reason"}') | ||
parser.add_argument('--invalid', action='store_true', help='Return malformed JSON') | ||
parser.set_defaults(func=command) | ||
|
||
if len(sys.argv) == 1: | ||
args = parser.parse_args(['-h']) | ||
exit() | ||
|
||
args = parser.parse_args() | ||
args.func(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters