Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type id search using typescript args #1533

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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