From 358e47d0f6ac812cf932ec2446e911952e019bcb Mon Sep 17 00:00:00 2001 From: Rabbit Date: Thu, 14 Dec 2023 08:33:07 +0800 Subject: [PATCH 1/2] fix: type id search using typescript args --- app/models/suggest_query.rb | 4 ++-- app/serializers/type_script_serializer.rb | 2 +- test/controllers/api/v1/suggest_queries_controller_test.rb | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/suggest_query.rb b/app/models/suggest_query.rb index 84afbec93..1940b3c05 100644 --- a/app/models/suggest_query.rb +++ b/app/models/suggest_query.rb @@ -56,8 +56,8 @@ def find_udt_by_type_hash end def find_type_script_by_type_id - type_script = TypeScript.find_by(script_hash: query_key) - { data: { args: type_script.args } } if type_script.present? + type_script = TypeScript.find_by(args: query_key, code_hash: Settings.type_id_code_hash) + TypeScriptSerializer.new(type_script) if type_script.present? end def find_by_hex diff --git a/app/serializers/type_script_serializer.rb b/app/serializers/type_script_serializer.rb index 017e2120f..fcc6585e9 100644 --- a/app/serializers/type_script_serializer.rb +++ b/app/serializers/type_script_serializer.rb @@ -1,5 +1,5 @@ class TypeScriptSerializer include FastJsonapi::ObjectSerializer - attributes :args, :code_hash, :hash_type + attributes :args, :code_hash, :hash_type, :script_hash end diff --git a/test/controllers/api/v1/suggest_queries_controller_test.rb b/test/controllers/api/v1/suggest_queries_controller_test.rb index 3adcec79d..90c644bf2 100644 --- a/test/controllers/api/v1/suggest_queries_controller_test.rb +++ b/test/controllers/api/v1/suggest_queries_controller_test.rb @@ -190,12 +190,14 @@ class SuggestQueriesControllerTest < ActionDispatch::IntegrationTest type_script = create( :type_script, code_hash: Settings.type_id_code_hash, + args: "0x2ab17f74009a9948ae2d3623dac853cc3ff1ef8270304ea5d9980b1f2b6810d5", script_hash: "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8" ) + response_json = TypeScriptSerializer.new(type_script).serialized_json - valid_get api_v1_suggest_queries_url, params: { q: type_script.script_hash } + valid_get api_v1_suggest_queries_url, params: { q: type_script.args } - assert_equal type_script.args, json.dig("data", "args") + assert_equal response_json, response.body end end end From 0f2d073f41f5c6a632b260c38319c26b226478de Mon Sep 17 00:00:00 2001 From: Rabbit Date: Thu, 14 Dec 2023 08:47:46 +0800 Subject: [PATCH 2/2] chore: adjust tests --- .../api/v1/cell_input_type_scripts_controller_test.rb | 2 +- .../api/v1/cell_output_type_scripts_controller_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/controllers/api/v1/cell_input_type_scripts_controller_test.rb b/test/controllers/api/v1/cell_input_type_scripts_controller_test.rb index b277ea390..8f5ce45f4 100644 --- a/test/controllers/api/v1/cell_input_type_scripts_controller_test.rb +++ b/test/controllers/api/v1/cell_input_type_scripts_controller_test.rb @@ -78,7 +78,7 @@ class CellInputTypeScriptsControllerTest < ActionDispatch::IntegrationTest valid_get api_v1_cell_input_type_script_url(cell_input.id) - assert_equal %w(args code_hash hash_type).sort, json["data"]["attributes"].keys.sort + assert_equal %w(args code_hash hash_type script_hash).sort, json["data"]["attributes"].keys.sort end test "should return error object when no cell input found by id" do diff --git a/test/controllers/api/v1/cell_output_type_scripts_controller_test.rb b/test/controllers/api/v1/cell_output_type_scripts_controller_test.rb index 33662845e..fd359b6bb 100644 --- a/test/controllers/api/v1/cell_output_type_scripts_controller_test.rb +++ b/test/controllers/api/v1/cell_output_type_scripts_controller_test.rb @@ -86,7 +86,7 @@ class CellOutputTypeScriptsControllerTest < ActionDispatch::IntegrationTest valid_get api_v1_cell_output_type_script_url(cell_output.id) - assert_equal %w(args code_hash hash_type).sort, json["data"]["attributes"].keys.sort + assert_equal %w(args code_hash hash_type script_hash).sort, json["data"]["attributes"].keys.sort end test "should return error object when no cell output found by id" do