Skip to content

Commit 825c551

Browse files
authored
Problem: url encoded characters are not properly handled in contract_by_denom (#1560)
* Problem: url encoded characters are not properly handled in contract_by_denom * add test * update query str
1 parent eb0a15d commit 825c551

File tree

7 files changed

+102
-94
lines changed

7 files changed

+102
-94
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
* [#1520](https://github.com/crypto-org-chain/cronos/pull/1520) Avoid invalid chain id for signer error when rpc call before chain id set in BeginBlock.
3838
* [#1539](https://github.com/crypto-org-chain/cronos/pull/1539) Fix go-block-stm bug that causes app hash mismatch.
39+
* [#1560](https://github.com/crypto-org-chain/cronos/pull/1560) Update queries contract addresses by native denom from a query in contract_by_denom.
3940

4041
*Jun 18, 2024*
4142

client/docs/swagger-ui/swagger.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ info:
44
description: A REST interface for state queries
55
version: 1.0.0
66
paths:
7-
/cronos/v1/contract_by_denom/{denom}:
7+
/cronos/v1/contract_by_denom:
88
get:
9-
summary: ContractByDenom queries contract addresses by native denom
9+
summary: >-
10+
ContractByDenom queries contract addresses by native denom from a query
11+
string.
1012
operationId: ContractByDenom
1113
responses:
1214
'200':
@@ -217,8 +219,8 @@ paths:
217219
}
218220
parameters:
219221
- name: denom
220-
in: path
221-
required: true
222+
in: query
223+
required: false
222224
type: string
223225
tags:
224226
- Query

integration_tests/configs/genesis_token_mapping.jsonnet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ config {
5656
denom: 'gravity0x0000000000000000000000000000000000000000',
5757
contract: '0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503',
5858
},
59+
{
60+
denom: 'ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865',
61+
contract: '0x0000000000000000000000000000000000000000',
62+
},
5963
],
6064
auto_contracts: [
6165
{

integration_tests/test_exported_genesis.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33

44
import pytest
5+
import requests
6+
from pystarport import ports
57

68
from .network import setup_custom_cronos
79
from .utils import ADDRS, CONTRACTS
@@ -29,8 +31,25 @@ def test_exported_contract(custom_cronos):
2931

3032
def test_exported_token_mapping(custom_cronos):
3133
cli = custom_cronos.cosmos_cli(0)
32-
rsp = cli.query_contract_by_denom(
33-
"gravity0x0000000000000000000000000000000000000000"
34-
)
35-
assert rsp["contract"] == "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503"
36-
assert rsp["auto_contract"] == "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503"
34+
port = ports.api_port(custom_cronos.base_port(0))
35+
for case in [
36+
{
37+
"denom": "gravity0x0000000000000000000000000000000000000000",
38+
"expected": {
39+
"contract": "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503",
40+
"auto_contract": "0x68542BD12B41F5D51D6282Ec7D91D7d0D78E4503",
41+
},
42+
},
43+
{
44+
"denom": "ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865", # noqa: E501
45+
"expected": {
46+
"contract": "0x0000000000000000000000000000000000000000",
47+
"auto_contract": "",
48+
},
49+
},
50+
]:
51+
denom = case["denom"]
52+
expected = case["expected"]
53+
assert cli.query_contract_by_denom(denom) == expected
54+
url = f"http://127.0.0.1:{port}/cronos/v1/contract_by_denom?denom={denom}"
55+
assert requests.get(url).json() == expected

proto/cronos/query.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ option go_package = "github.com/crypto-org-chain/cronos/v2/x/cronos/types";
1212

1313
// Query defines the gRPC querier service.
1414
service Query {
15-
// ContractByDenom queries contract addresses by native denom
15+
// ContractByDenom queries contract addresses by native denom from a query string.
1616
rpc ContractByDenom(ContractByDenomRequest) returns (ContractByDenomResponse) {
17-
option (google.api.http).get = "/cronos/v1/contract_by_denom/{denom}";
17+
option (google.api.http).get = "/cronos/v1/contract_by_denom";
1818
}
1919

2020
// DenomByContract queries native denom by contract address

x/cronos/types/query.pb.go

Lines changed: 52 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/cronos/types/query.pb.gw.go

Lines changed: 13 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)