mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Add AbciQueryResponse fields
This commit is contained in:
parent
05f89b107b
commit
cd31414e96
@ -10,6 +10,8 @@ and this project adheres to
|
||||
|
||||
- @cosmjs/stargate: Add `makeMultisignedTxBytes` which is like
|
||||
`makeMultisignedTx` but returns bytes ready to broadcast ([#1176]).
|
||||
- @cosmjs/tendermint-rpc: Add fields `codespace` and `info` to
|
||||
`AbciQueryResponse`.
|
||||
|
||||
[#1176]: https://github.com/cosmos/cosmjs/pull/1176
|
||||
|
||||
|
@ -72,11 +72,14 @@ interface RpcAbciQueryResponse {
|
||||
readonly key: string;
|
||||
/** base64 encoded */
|
||||
readonly value?: string;
|
||||
readonly proofOps?: RpcQueryProof;
|
||||
readonly proofOps?: RpcQueryProof | null;
|
||||
readonly height?: string;
|
||||
/** An integer; can be negative */
|
||||
readonly index?: string;
|
||||
readonly code?: string; // only for errors
|
||||
readonly code?: number; // only for errors
|
||||
readonly codespace?: string;
|
||||
readonly log?: string;
|
||||
readonly info?: string;
|
||||
}
|
||||
|
||||
function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryResponse {
|
||||
@ -86,8 +89,10 @@ function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryRespons
|
||||
proof: may(decodeQueryProof, data.proofOps),
|
||||
height: may(Integer.parse, data.height),
|
||||
code: may(Integer.parse, data.code),
|
||||
codespace: assertString(data.codespace ?? ""),
|
||||
index: may(Integer.parse, data.index),
|
||||
log: data.log,
|
||||
info: assertString(data.info ?? ""),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,9 @@ export interface AbciQueryResponse {
|
||||
readonly height?: number;
|
||||
readonly index?: number;
|
||||
readonly code?: number; // non-falsy for errors
|
||||
readonly codespace: string;
|
||||
readonly log?: string;
|
||||
readonly info: string;
|
||||
}
|
||||
|
||||
export interface BlockResponse {
|
||||
|
@ -9,6 +9,7 @@ import { HttpClient, RpcClient, WebsocketClient } from "../rpcclients";
|
||||
import {
|
||||
buildKvTx,
|
||||
ExpectedValues,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutTendermint,
|
||||
randomString,
|
||||
tendermintEnabled,
|
||||
@ -107,23 +108,31 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can query the state", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint34Client.create(rpcFactory());
|
||||
describe("abciQuery", () => {
|
||||
it("can query the state", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint34Client.create(rpcFactory());
|
||||
|
||||
const key = randomString();
|
||||
const value = randomString();
|
||||
await client.broadcastTxCommit({ tx: buildKvTx(key, value) });
|
||||
const key = randomString();
|
||||
const value = randomString();
|
||||
await client.broadcastTxCommit({ tx: buildKvTx(key, value) });
|
||||
|
||||
const binKey = toAscii(key);
|
||||
const binValue = toAscii(value);
|
||||
const queryParams = { path: "/key", data: binKey, prove: true };
|
||||
const response = await client.abciQuery(queryParams);
|
||||
expect(response.key).toEqual(binKey);
|
||||
expect(response.value).toEqual(binValue);
|
||||
expect(response.code).toBeFalsy();
|
||||
const binKey = toAscii(key);
|
||||
const binValue = toAscii(value);
|
||||
const queryParams = { path: "/key", data: binKey, prove: true };
|
||||
const response = await client.abciQuery(queryParams);
|
||||
expect(response.key).toEqual(binKey);
|
||||
expect(response.value).toEqual(binValue);
|
||||
expect(response.code).toEqual(0);
|
||||
expect(response.codespace).toEqual("");
|
||||
expect(response.index).toEqual(-1);
|
||||
expect(response.proof).toBeUndefined();
|
||||
expect(response.log).toEqual("exists");
|
||||
expect(response.info).toEqual("");
|
||||
expect(response.height).toMatch(nonNegativeIntegerMatcher);
|
||||
|
||||
client.disconnect();
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
it("can get a commit", async () => {
|
||||
|
@ -72,11 +72,13 @@ interface RpcAbciQueryResponse {
|
||||
readonly key: string;
|
||||
/** base64 encoded */
|
||||
readonly value?: string;
|
||||
readonly proofOps?: RpcQueryProof;
|
||||
readonly proofOps?: RpcQueryProof | null;
|
||||
readonly height?: string;
|
||||
readonly index?: string;
|
||||
readonly code?: string; // only for errors
|
||||
readonly codespace?: string;
|
||||
readonly log?: string;
|
||||
readonly info?: string;
|
||||
}
|
||||
|
||||
function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryResponse {
|
||||
@ -86,8 +88,10 @@ function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryRespons
|
||||
proof: may(decodeQueryProof, data.proofOps),
|
||||
height: may(Integer.parse, data.height),
|
||||
code: may(Integer.parse, data.code),
|
||||
codespace: assertString(data.codespace ?? ""),
|
||||
index: may(Integer.parse, data.index),
|
||||
log: data.log,
|
||||
info: assertString(data.info ?? ""),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,9 @@ export interface AbciQueryResponse {
|
||||
readonly height?: number;
|
||||
readonly index?: number;
|
||||
readonly code?: number; // non-falsy for errors
|
||||
readonly codespace: string;
|
||||
readonly log?: string;
|
||||
readonly info: string;
|
||||
}
|
||||
|
||||
export interface BlockResponse {
|
||||
|
@ -9,6 +9,7 @@ import { HttpClient, RpcClient, WebsocketClient } from "../rpcclients";
|
||||
import {
|
||||
buildKvTx,
|
||||
ExpectedValues,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutTendermint,
|
||||
randomString,
|
||||
tendermintEnabled,
|
||||
@ -107,23 +108,31 @@ function defaultTestSuite(rpcFactory: () => RpcClient, expected: ExpectedValues)
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can query the state", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint35Client.create(rpcFactory());
|
||||
describe("abciQuery", () => {
|
||||
it("can query the state", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Tendermint35Client.create(rpcFactory());
|
||||
|
||||
const key = randomString();
|
||||
const value = randomString();
|
||||
await client.broadcastTxCommit({ tx: buildKvTx(key, value) });
|
||||
const key = randomString();
|
||||
const value = randomString();
|
||||
await client.broadcastTxCommit({ tx: buildKvTx(key, value) });
|
||||
|
||||
const binKey = toAscii(key);
|
||||
const binValue = toAscii(value);
|
||||
const queryParams = { path: "/key", data: binKey, prove: true };
|
||||
const response = await client.abciQuery(queryParams);
|
||||
expect(response.key).toEqual(binKey);
|
||||
expect(response.value).toEqual(binValue);
|
||||
expect(response.code).toBeFalsy();
|
||||
const binKey = toAscii(key);
|
||||
const binValue = toAscii(value);
|
||||
const queryParams = { path: "/key", data: binKey, prove: true };
|
||||
const response = await client.abciQuery(queryParams);
|
||||
expect(response.key).toEqual(binKey);
|
||||
expect(response.value).toEqual(binValue);
|
||||
expect(response.code).toEqual(0);
|
||||
expect(response.codespace).toEqual("");
|
||||
expect(response.index).toEqual(-1);
|
||||
expect(response.proof).toBeUndefined();
|
||||
expect(response.log).toEqual("exists");
|
||||
expect(response.info).toEqual("");
|
||||
expect(response.height).toMatch(nonNegativeIntegerMatcher);
|
||||
|
||||
client.disconnect();
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
it("can get a commit", async () => {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { toAscii } from "@cosmjs/encoding";
|
||||
import { sleep } from "@cosmjs/utils";
|
||||
|
||||
export const nonNegativeIntegerMatcher = /^[0-9]+$/;
|
||||
export const anyMatcher = /^.*$/; // Any string, including empty. Does not do more than a type check.
|
||||
|
||||
export interface ExpectedValues {
|
||||
|
Loading…
x
Reference in New Issue
Block a user