tendermint-rpc: Add v0.33 support (part 2)

This commit is contained in:
willclarktech
2020-06-24 12:53:29 +02:00
parent 9ba93ebc9e
commit 66e38860f7
6 changed files with 28 additions and 25 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ function pendingWithoutTendermint(): void {
async function tendermintSearchIndexUpdated(): Promise<void> {
// Tendermint needs some time before a committed transaction is found in search
return sleep(50);
return sleep(75);
}
function buildKvTx(k: string, v: string): TxBytes {
+1 -1
View File
@@ -5,7 +5,7 @@ describe("jsonrpc", () => {
it("generates proper object with correct method", () => {
const request = createJsonRpcRequest("do_something");
expect(request.jsonrpc).toEqual("2.0");
expect(request.id).toMatch(/^[a-zA-Z0-9]{12}$/);
expect(request.id.toString()).toMatch(/^[0-9]{10,12}$/);
expect(request.method).toEqual("do_something");
});
+11 -8
View File
@@ -1,16 +1,19 @@
import { JsonRpcRequest } from "@iov/jsonrpc";
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const numbers = "0123456789";
/** generates a random alphanumeric character */
function randomChar(): string {
return alphabet[Math.floor(Math.random() * alphabet.length)];
/** generates a random numeric character */
function randomNumericChar(): string {
return numbers[Math.floor(Math.random() * numbers.length)];
}
function randomId(): string {
return Array.from({ length: 12 })
.map(() => randomChar())
.join("");
function randomId(): number {
return parseInt(
Array.from({ length: 12 })
.map(() => randomNumericChar())
.join(""),
10,
);
}
/** Creates a JSON-RPC request with random ID */
@@ -95,7 +95,7 @@ class RpcEventProducer implements Producer<SubscriptionEvent> {
// Tendermint adds an "#event" suffix for events that follow a previous subscription
// https://github.com/tendermint/tendermint/blob/v0.23.0/rpc/core/events.go#L107
const idEventSubscription = responseStream
.filter((response) => response.id === `${this.request.id}#event`)
.filter((response) => response.id === this.request.id)
.subscribe({
next: (response) => {
if (isJsonRpcErrorResponse(response)) {
@@ -191,7 +191,7 @@ export class WebsocketClient implements RpcStreamingClient {
this.subscriptionStreams.set(query, stream);
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.subscriptionStreams.get(query)!;
return this.subscriptionStreams.get(query)!.filter((response) => response.query !== undefined);
}
/**
+12 -12
View File
@@ -528,9 +528,9 @@ function decodeStatus(data: RpcStatusResponse): responses.StatusResponse {
/**
* Example data:
* {
* "RootHash": "10A1A17D5F818099B5CAB5B91733A3CC27C0DB6CE2D571AC27FB970C314308BB",
* "Data": "ZVlERVhDV2lVNEUwPXhTUjc4Tmp2QkNVSg==",
* "Proof": {
* "root_hash": "10A1A17D5F818099B5CAB5B91733A3CC27C0DB6CE2D571AC27FB970C314308BB",
* "data": "ZVlERVhDV2lVNEUwPXhTUjc4Tmp2QkNVSg==",
* "proof": {
* "total": "1",
* "index": "0",
* "leaf_hash": "EKGhfV+BgJm1yrW5FzOjzCfA22zi1XGsJ/uXDDFDCLs=",
@@ -539,9 +539,9 @@ function decodeStatus(data: RpcStatusResponse): responses.StatusResponse {
* }
*/
interface RpcTxProof {
readonly Data: Base64String;
readonly RootHash: HexString;
readonly Proof: {
readonly data: Base64String;
readonly root_hash: HexString;
readonly proof: {
readonly total: IntegerString;
readonly index: IntegerString;
readonly leaf_hash: Base64String;
@@ -551,13 +551,13 @@ interface RpcTxProof {
function decodeTxProof(data: RpcTxProof): responses.TxProof {
return {
data: Base64.decode(assertNotEmpty(data.Data)),
rootHash: fromHex(assertNotEmpty(data.RootHash)),
data: Base64.decode(assertNotEmpty(data.data)),
rootHash: fromHex(assertNotEmpty(data.root_hash)),
proof: {
total: Integer.parse(assertNotEmpty(data.Proof.total)),
index: Integer.parse(assertNotEmpty(data.Proof.index)),
leafHash: Base64.decode(assertNotEmpty(data.Proof.leaf_hash)),
aunts: assertArray(data.Proof.aunts).map(Base64.decode),
total: Integer.parse(assertNotEmpty(data.proof.total)),
index: Integer.parse(assertNotEmpty(data.proof.index)),
leafHash: Base64.decode(assertNotEmpty(data.proof.leaf_hash)),
aunts: assertArray(data.proof.aunts).map(Base64.decode),
},
};
}