Skip to content

Commit

Permalink
Merge pull request #1271 from cosmos/utf8-queryContractSmart
Browse files Browse the repository at this point in the history
Accept non-ASCII inputs in query requests of queryContractSmart
  • Loading branch information
webmaster128 committed Sep 15, 2022
2 parents e1ad942 + f7ab4a5 commit aaa171e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ and this project adheres to
- @cosmjs/tendermint-rpc: Fix decoding events without attributes ([#1198]).
- @cosmjs/amino, @cosmjs/proto-signing: Support amounts larger than the uint64
range in `parseCoins` ([#1268]).
- @cosmjs/cosmwasm-stargate: Accept non-ASCII inputs in query requests of
`{CosmWasmClient,WasmExtension}.queryContractSmart` ([#1269]).

[#1170]: https://github.com/cosmos/cosmjs/issues/1170
[#1177]: https://github.com/cosmos/cosmjs/issues/1177
[#1188]: https://github.com/cosmos/cosmjs/pull/1188
[#1198]: https://github.com/cosmos/cosmjs/pull/1198
[#1268]: https://github.com/cosmos/cosmjs/issues/1268
[#1269]: https://github.com/cosmos/cosmjs/issues/1269

### Changed

Expand Down
8 changes: 4 additions & 4 deletions packages/cosmwasm-stargate/src/modules/wasm/queries.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sha256 } from "@cosmjs/crypto";
import { fromAscii, fromHex, toAscii, toHex } from "@cosmjs/encoding";
import { fromAscii, fromHex, toAscii, toHex, toUtf8 } from "@cosmjs/encoding";
import { DirectSecp256k1HdWallet, OfflineDirectSigner, Registry } from "@cosmjs/proto-signing";
import {
assertIsDeliverTxSuccess,
Expand Down Expand Up @@ -75,7 +75,7 @@ async function instantiateContract(
sender: alice.address0,
codeId: Long.fromNumber(codeId),
label: "my escrow",
msg: toAscii(
msg: toUtf8(
JSON.stringify({
verifier: alice.address0,
beneficiary: beneficiaryAddress,
Expand Down Expand Up @@ -108,7 +108,7 @@ async function executeContract(
value: MsgExecuteContract.fromPartial({
sender: alice.address0,
contract: contractAddress,
msg: toAscii(JSON.stringify(msg)),
msg: toUtf8(JSON.stringify(msg)),
funds: [],
}),
};
Expand Down Expand Up @@ -254,7 +254,7 @@ describe("WasmExtension", () => {
jasmine.objectContaining({
codeId: Long.fromNumber(hackatomCodeId, true),
operation: ContractCodeHistoryOperationType.CONTRACT_CODE_HISTORY_OPERATION_TYPE_INIT,
msg: toAscii(
msg: toUtf8(
JSON.stringify({
verifier: alice.address0,
beneficiary: beneficiaryAddress,
Expand Down
4 changes: 2 additions & 2 deletions packages/cosmwasm-stargate/src/modules/wasm/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fromUtf8, toAscii } from "@cosmjs/encoding";
import { fromUtf8, toUtf8 } from "@cosmjs/encoding";
import { createPagination, createProtobufRpcClient, QueryClient } from "@cosmjs/stargate";
import {
QueryAllContractStateResponse,
Expand Down Expand Up @@ -117,7 +117,7 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
},

queryContractSmart: async (address: string, query: Record<string, unknown>) => {
const request = { address: address, queryData: toAscii(JSON.stringify(query)) };
const request = { address: address, queryData: toUtf8(JSON.stringify(query)) };
const { data } = await queryService.SmartContractState(request);
// By convention, smart queries must return a valid JSON document (see https://github.com/CosmWasm/cosmwasm/issues/144)
let responseText: string;
Expand Down

0 comments on commit aaa171e

Please sign in to comment.