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