Skip to content

Commit

Permalink
fix: type id search using typescript args (nervosnetwork#1533)
Browse files Browse the repository at this point in the history
* fix: type id search using typescript args

* chore: adjust tests
  • Loading branch information
rabbitz authored and ttt12334 committed Dec 25, 2023
1 parent cac7db9 commit 82f9491
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/models/suggest_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/type_script_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TypeScriptSerializer
include FastJsonapi::ObjectSerializer

attributes :args, :code_hash, :hash_type
attributes :args, :code_hash, :hash_type, :script_hash
end
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions test/controllers/api/v1/suggest_queries_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82f9491

Please sign in to comment.