Merge pull request #401 from CosmWasm/ibc-extension

Add IbcExtension with unverified queries
This commit is contained in:
Simon Warta 2020-08-20 11:08:10 +02:00 committed by GitHub
commit 6d6a6be2f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 10598 additions and 1 deletions

View File

@ -5,6 +5,7 @@ command -v shellcheck > /dev/null && shellcheck "$0"
GENERATED_DIR="./tmp"
ROOT_PROTO_DIR="./proto/cosmos/cosmos-sdk"
COSMOS_PROTO_DIR="$ROOT_PROTO_DIR/proto/cosmos"
IBC_PROTO_DIR="$ROOT_PROTO_DIR/proto/ibc"
TENDERMINT_PROTO_DIR="$ROOT_PROTO_DIR/third_party/proto/tendermint"
GOOGLE_PROTO_DIR="$ROOT_PROTO_DIR/third_party/proto/google"
@ -27,6 +28,9 @@ yarn pbjs \
"$COSMOS_PROTO_DIR/query/pagination.proto" \
"$COSMOS_PROTO_DIR/tx/tx.proto" \
"$COSMOS_PROTO_DIR/tx/signing/signing.proto" \
"$IBC_PROTO_DIR/channel/{channel,query}.proto" \
"$IBC_PROTO_DIR/commitment/commitment.proto" \
"$IBC_PROTO_DIR/connection/{connection,query}.proto" \
"$TENDERMINT_PROTO_DIR/abci/types/types.proto" \
"$TENDERMINT_PROTO_DIR/crypto/merkle/merkle.proto" \
"$TENDERMINT_PROTO_DIR/libs/kv/types.proto" \

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,157 @@
import { Client as TendermintClient } from "@cosmjs/tendermint-rpc";
import { pendingWithoutSimapp, simapp } from "../testutils.spec";
import { IbcExtension, setupIbcExtension } from "./ibc";
import { QueryClient } from "./queryclient";
async function makeClientWithIbc(rpcUrl: string): Promise<[QueryClient & IbcExtension, TendermintClient]> {
const tmClient = await TendermintClient.connect(rpcUrl);
return [QueryClient.withExtensions(tmClient, setupIbcExtension), tmClient];
}
describe("IbcExtension", () => {
describe("unverified", () => {
describe("channel", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.channel("foo", "bar");
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("channels", () => {
it("can be called", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.channels();
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("connectionChannels", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.connectionChannels("foo");
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("packetCommitment", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.packetCommitment("foo", "bar", 0);
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("packetCommitments", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.packetCommitments("foo", "bar");
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("packetAcknowledgement", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.packetAcknowledgement("foo", "bar", 1);
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("unrelayedPackets", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.unrelayedPackets("foo", "bar", [0, 1], true);
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("nextSequenceReceive", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.nextSequenceReceive("foo", "bar");
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
// Queries for ibc.connection
describe("connection", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.connection("foo");
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("connections", () => {
it("can be called", async () => {
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.connections();
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
describe("clientConnections", () => {
it("can be called", async () => {
pending("Fails with 'Query failed with (1): internal'. Make it work.");
pendingWithoutSimapp();
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.unverified.clientConnections("foo");
expect(response).toBeTruthy(); // TODO: implement checks
tmClient.disconnect();
});
});
});
});

View File

@ -0,0 +1,154 @@
import Long from "long";
import { ibc } from "../codec";
import { QueryClient } from "./queryclient";
import { toObject } from "./utils";
export interface IbcExtension {
readonly ibc: {
readonly unverified: {
// Queries for ibc.channel
readonly channel: (portId: string, channelId: string) => Promise<ibc.channel.IQueryChannelResponse>;
readonly channels: () => Promise<ibc.channel.IQueryChannelsResponse>;
readonly connectionChannels: (
connection: string,
) => Promise<ibc.channel.IQueryConnectionChannelsResponse>;
readonly packetCommitment: (
portId: string,
channelId: string,
sequence: number,
) => Promise<ibc.channel.IQueryPacketCommitmentResponse>;
readonly packetCommitments: (
portId: string,
channelId: string,
) => Promise<ibc.channel.IQueryPacketCommitmentsResponse>;
readonly packetAcknowledgement: (
portId: string,
channelId: string,
sequence: number,
) => Promise<ibc.channel.IQueryPacketAcknowledgementResponse>;
readonly unrelayedPackets: (
portId: string,
channelId: string,
packetCommitmentSequences: readonly number[],
acknowledgements: boolean,
) => Promise<ibc.channel.IQueryUnrelayedPacketsResponse>;
readonly nextSequenceReceive: (
portId: string,
channelId: string,
) => Promise<ibc.channel.IQueryNextSequenceReceiveResponse>;
// Queries for ibc.connection
readonly connection: (connectionId: string) => Promise<ibc.connection.IQueryConnectionResponse>;
readonly connections: () => Promise<ibc.connection.IQueryConnectionsResponse>;
readonly clientConnections: (
clientId: string,
) => Promise<ibc.connection.IQueryClientConnectionsResponse>;
};
};
}
export function setupIbcExtension(base: QueryClient): IbcExtension {
// Use this service to get easy typed access to query methods
// This cannot be used to for proof verification
const channelQuerySerice = ibc.channel.Query.create((method: any, requestData, callback) => {
// Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229
const path = `/ibc.channel.Query/${method.name}`;
base
.queryUnverified(path, requestData)
.then((response) => callback(null, response))
.catch((error) => callback(error));
});
const connectionQuerySerice = ibc.connection.Query.create((method: any, requestData, callback) => {
// Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229
const path = `/ibc.connection.Query/${method.name}`;
base
.queryUnverified(path, requestData)
.then((response) => callback(null, response))
.catch((error) => callback(error));
});
return {
ibc: {
unverified: {
// Queries for ibc.channel
channel: async (portId: string, channelId: string) => {
const response = await channelQuerySerice.channel({ portId: portId, channelId: channelId });
return toObject(response);
},
channels: async () => {
const response = await channelQuerySerice.channels({});
return toObject(response);
},
connectionChannels: async (connection: string) => {
const response = await channelQuerySerice.connectionChannels({ connection: connection });
return toObject(response);
},
packetCommitment: async (portId: string, channelId: string, sequence: number) => {
const response = await channelQuerySerice.packetCommitment({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence),
});
return toObject(response);
},
packetCommitments: async (portId: string, channelId: string) => {
const response = await channelQuerySerice.packetCommitments({
portId: portId,
channelId: channelId,
});
return toObject(response);
},
packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => {
const response = await channelQuerySerice.packetAcknowledgement({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence),
});
return toObject(response);
},
unrelayedPackets: async (
portId: string,
channelId: string,
packetCommitmentSequences: readonly number[],
acknowledgements: boolean,
) => {
const response = await channelQuerySerice.unrelayedPackets({
portId: portId,
channelId: channelId,
packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s)),
acknowledgements: acknowledgements,
});
return toObject(response);
},
nextSequenceReceive: async (portId: string, channelId: string) => {
const response = await channelQuerySerice.nextSequenceReceive({
portId: portId,
channelId: channelId,
});
return toObject(response);
},
// Queries for ibc.connection
connection: async (connectionId: string) => {
const response = await connectionQuerySerice.connection({ connectionId: connectionId });
return toObject(response);
},
connections: async () => {
const response = await connectionQuerySerice.connections({});
return toObject(response);
},
clientConnections: async (clientId: string) => {
const response = await connectionQuerySerice.clientConnections({ clientId: clientId });
return toObject(response);
},
},
},
};
}

View File

@ -6,3 +6,4 @@ export { QueryClient } from "./queryclient";
export { AuthExtension, setupAuthExtension } from "./auth";
export { BankExtension, setupBankExtension } from "./bank";
export { IbcExtension, setupIbcExtension } from "./ibc";

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
import { ibc } from "../codec";
import { QueryClient } from "./queryclient";
export interface IbcExtension {
readonly ibc: {
readonly unverified: {
readonly channel: (portId: string, channelId: string) => Promise<ibc.channel.IQueryChannelResponse>;
readonly channels: () => Promise<ibc.channel.IQueryChannelsResponse>;
readonly connectionChannels: (
connection: string,
) => Promise<ibc.channel.IQueryConnectionChannelsResponse>;
readonly packetCommitment: (
portId: string,
channelId: string,
sequence: number,
) => Promise<ibc.channel.IQueryPacketCommitmentResponse>;
readonly packetCommitments: (
portId: string,
channelId: string,
) => Promise<ibc.channel.IQueryPacketCommitmentsResponse>;
readonly packetAcknowledgement: (
portId: string,
channelId: string,
sequence: number,
) => Promise<ibc.channel.IQueryPacketAcknowledgementResponse>;
readonly unrelayedPackets: (
portId: string,
channelId: string,
packetCommitmentSequences: readonly number[],
acknowledgements: boolean,
) => Promise<ibc.channel.IQueryUnrelayedPacketsResponse>;
readonly nextSequenceReceive: (
portId: string,
channelId: string,
) => Promise<ibc.channel.IQueryNextSequenceReceiveResponse>;
readonly connection: (connectionId: string) => Promise<ibc.connection.IQueryConnectionResponse>;
readonly connections: () => Promise<ibc.connection.IQueryConnectionsResponse>;
readonly clientConnections: (
clientId: string,
) => Promise<ibc.connection.IQueryClientConnectionsResponse>;
};
};
}
export declare function setupIbcExtension(base: QueryClient): IbcExtension;

View File

@ -1,3 +1,4 @@
export { QueryClient } from "./queryclient";
export { AuthExtension, setupAuthExtension } from "./auth";
export { BankExtension, setupBankExtension } from "./bank";
export { IbcExtension, setupIbcExtension } from "./ibc";