From d8c3429bb60f630aad782f127a257f5ea6226640 Mon Sep 17 00:00:00 2001 From: Alberto Soutullo Date: Tue, 21 Feb 2023 20:46:23 +0100 Subject: [PATCH] Moved send json rpc to a new file --- src/call_protocols.star | 18 ++++++++++++++++++ src/system_variables.star | 1 + src/waku.star | 26 ++++---------------------- 3 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 src/call_protocols.star diff --git a/src/call_protocols.star b/src/call_protocols.star new file mode 100644 index 0000000..71462c0 --- /dev/null +++ b/src/call_protocols.star @@ -0,0 +1,18 @@ + + +def send_json_rpc(plan, service_name, port_id, method, params, extract={}): + recipe = PostHttpRequestRecipe( + service_name=service_name, + port_id=port_id, + endpoint="", + content_type="application/json", + body='{ "jsonrpc": "2.0", "method": "' + method + '", "params": [' + params + '], "id": 1}', + extract=extract + ) + + response = plan.wait(recipe=recipe, + field="code", + assertion="==", + target_value=200) + + return response \ No newline at end of file diff --git a/src/system_variables.star b/src/system_variables.star index f5c977f..0b779fd 100644 --- a/src/system_variables.star +++ b/src/system_variables.star @@ -100,6 +100,7 @@ ARGUMENT_PARSER_MODULE = "github.com/logos-co/wakurtosis/src/arguments_parser.st FILE_HELPERS_MODULE = "github.com/logos-co/wakurtosis/src/file_helpers.star" TEMPLATES_MODULE = "github.com/logos-co/wakurtosis/src/templates.star" WLS_MODULE = "github.com/logos-co/wakurtosis/src/wls.star" +CALL_PROTOCOLS = "github.com/logos-co/wakurtosis/src/call_protocols.star" TEST_ARGUMENTS_MODULE = "github.com/logos-co/wakurtosis/src/tests/test_arguments_parser.star" TEST_FILES_MODULE = "github.com/logos-co/wakurtosis/src/tests/test_file_helpers.star" diff --git a/src/waku.star b/src/waku.star index 8a75cd9..79f598e 100644 --- a/src/waku.star +++ b/src/waku.star @@ -3,30 +3,13 @@ vars = import_module("github.com/logos-co/wakurtosis/src/system_variables.star") # Module Imports files = import_module(vars.FILE_HELPERS_MODULE) - - -def send_json_rpc(plan, service_name, port_id, method, params, extract={}): - recipe = PostHttpRequestRecipe( - service_name=service_name, - port_id=port_id, - endpoint="", - content_type="application/json", - body='{ "jsonrpc": "2.0", "method": "' + method + '", "params": [' + params + '], "id": 1}', - extract=extract - ) - - response = plan.wait(recipe=recipe, - field="code", - assertion="==", - target_value=200) - - return response +call_protocols = import_module(vars.CALL_PROTOCOLS) def get_wakunode_peer_id(plan, service_name, port_id): extract = {"peer_id": '.result.listenAddresses | .[0] | split("/") | .[-1]'} - response = send_json_rpc(plan, service_name, port_id, + response = call_protocols.send_json_rpc(plan, service_name, port_id, vars.GET_WAKU_INFO_METHOD, "", extract) plan.assert(value=response["code"], assertion="==", target_value = 200) @@ -34,7 +17,6 @@ def get_wakunode_peer_id(plan, service_name, port_id): return response["extract.peer_id"] -# todo better name for this function def create_node_multiaddress(node_id, node_information): ip = node_information[vars.IP_KEY] port = node_information[vars.PORTS_KEY][vars.WAKU_LIBP2P_PORT_ID + "_" + node_id][0] @@ -52,7 +34,7 @@ def connect_wakunode_to_peers(plan, service_name, node_id, port_id, peer_ids): params = _merge_peer_ids(peer_ids) port_id = port_id + "_" + node_id - response = send_json_rpc(plan, service_name, port_id, method, params) + response = call_protocols.send_json_rpc(plan, service_name, port_id, method, params) plan.assert(value=response["code"], assertion="==", target_value = 200) @@ -70,7 +52,7 @@ def make_service_wait(plan, service_name, time): def get_waku_peers(plan, waku_service_name): extract = {"peers": '.result | length'} - response = send_json_rpc(plan, waku_service_name, vars.RPC_PORT_ID, + response = call_protocols.send_json_rpc(plan, waku_service_name, vars.RPC_PORT_ID, vars.GET_PEERS_METHOD, "", extract) plan.assert(value=response["code"], assertion="==", target_value=200)