diff --git a/packages/stargate/src/queries/ibc.spec.ts b/packages/stargate/src/queries/ibc.spec.ts index 8b6a5dab..3547f2bd 100644 --- a/packages/stargate/src/queries/ibc.spec.ts +++ b/packages/stargate/src/queries/ibc.spec.ts @@ -12,564 +12,550 @@ async function makeClientWithIbc(rpcUrl: string): Promise<[QueryClient & IbcExte } describe("IbcExtension", () => { - describe("unverified", () => { + describe("channel", () => { describe("channel", () => { - describe("channel", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.channel.channel(ibcTest.portId, ibcTest.channelId); - expect(response.channel).toEqual(ibcTest.channel); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); + const response = await client.ibc.channel.channel(ibcTest.portId, ibcTest.channelId); + expect(response.channel).toEqual(ibcTest.channel); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); - tmClient.disconnect(); - }); - }); - - describe("channels", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.channels(); - expect(response.channels).toEqual([ibcTest.identifiedChannel]); - expect(response.pagination).toBeDefined(); - expect(response.height).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("allChannels", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.allChannels(); - expect(response.channels).toEqual([ibcTest.identifiedChannel]); - - tmClient.disconnect(); - }); - }); - - describe("connectionChannels", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.connectionChannels(ibcTest.connectionId); - expect(response.channels).toEqual([ibcTest.identifiedChannel]); - expect(response.pagination).toBeDefined(); - expect(response.height).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("allConnectionChannels", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.allConnectionChannels(ibcTest.connectionId); - expect(response.channels).toEqual([ibcTest.identifiedChannel]); - - tmClient.disconnect(); - }); - }); - - describe("clientState", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.clientState(ibcTest.portId, ibcTest.channelId); - expect(response.identifiedClientState).toEqual({ - clientId: ibcTest.clientId, - clientState: { - typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", - value: jasmine.any(Uint8Array), - }, - }); - - tmClient.disconnect(); - }); - }); - - describe("consensusState", () => { - xit("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.consensusState( - ibcTest.portId, - ibcTest.channelId, - // TODO: Find valid values - 0, - 0, - ); - expect(response.consensusState).toEqual({ - typeUrl: "/haha", - value: jasmine.any(Uint8Array), - }); - expect(response.clientId).toEqual(ibcTest.clientId); - - tmClient.disconnect(); - }); - }); - - describe("packetCommitment", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.packetCommitment( - ibcTest.portId, - ibcTest.channelId, - Long.fromInt(ibcTest.commitment.sequence, true), - ); - expect(response.commitment).toEqual(ibcTest.commitment.data); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("packetCommitments", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.packetCommitments( - ibcTest.portId, - ibcTest.channelId, - ); - expect(response.commitments).toEqual([ibcTest.packetState]); - expect(response.pagination).toBeDefined(); - expect(response.height).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("allPacketCommitments", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.allPacketCommitments( - ibcTest.portId, - ibcTest.channelId, - ); - expect(response.commitments).toEqual([ibcTest.packetState]); - - tmClient.disconnect(); - }); - }); - - describe("packetReceipt", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.packetReceipt( - ibcTest.portId, - ibcTest.channelId, - 1, - ); - expect(response.received).toEqual(false); - - tmClient.disconnect(); - }); - }); - - describe("packetAcknowledgement", () => { - it("works", async () => { - pending("We don't have an acknowledgement for testing at the moment"); - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.packetAcknowledgement( - ibcTest.portId, - ibcTest.channelId, - ibcTest.commitment.sequence, - ); - expect(response.acknowledgement).toEqual(ibcTest.packetAcknowledgements[0].data); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("packetAcknowledgements", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.packetAcknowledgements( - ibcTest.portId, - ibcTest.channelId, - ); - expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); - expect(response.pagination).toBeDefined(); - expect(response.height).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("allPacketAcknowledgements", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.allPacketAcknowledgements( - ibcTest.portId, - ibcTest.channelId, - ); - expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); - - tmClient.disconnect(); - }); - }); - - describe("unreceivedPackets", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.unreceivedPackets( - ibcTest.portId, - ibcTest.channelId, - [1, 2, 3], - ); - expect(response.sequences).toEqual([1, 2, 3].map((n) => Long.fromInt(n, true))); - expect(response.height).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("unreceivedAcks", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.unreceivedAcks( - ibcTest.portId, - ibcTest.channelId, - [1, 2, 3, 4, 5, 6, 7], - ); - expect(response.sequences).toEqual([Long.fromInt(ibcTest.commitment.sequence, true)]); - expect(response.height).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("nextSequenceReceive", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.channel.nextSequenceReceive( - ibcTest.portId, - ibcTest.channelId, - ); - expect(response.nextSequenceReceive).toEqual(Long.fromInt(1, true)); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); + tmClient.disconnect(); }); }); - describe("client", () => { - describe("state", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("channels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.client.state(ibcTest.clientId); - expect(response.clientState).toEqual({ + const response = await client.ibc.channel.channels(); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allChannels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.allChannels(); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + + tmClient.disconnect(); + }); + }); + + describe("connectionChannels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.connectionChannels(ibcTest.connectionId); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allConnectionChannels", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.allConnectionChannels(ibcTest.connectionId); + expect(response.channels).toEqual([ibcTest.identifiedChannel]); + + tmClient.disconnect(); + }); + }); + + describe("clientState", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.clientState(ibcTest.portId, ibcTest.channelId); + expect(response.identifiedClientState).toEqual({ + clientId: ibcTest.clientId, + clientState: { typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", value: jasmine.any(Uint8Array), - }); - - tmClient.disconnect(); + }, }); - }); - describe("states", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.states(); - expect(response.clientStates).toEqual([ - { - clientId: ibcTest.clientId, - clientState: { - typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", - value: jasmine.any(Uint8Array), - }, - }, - ]); - expect(response.pagination).toBeDefined(); - - tmClient.disconnect(); - }); - }); - - describe("allStates", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.allStates(); - expect(response.clientStates).toEqual([ - { - clientId: ibcTest.clientId, - clientState: { - typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", - value: jasmine.any(Uint8Array), - }, - }, - ]); - - tmClient.disconnect(); - }); - }); - - describe("consensusState", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.consensusState(ibcTest.clientId); - expect(response.consensusState).toEqual({ - typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", - value: jasmine.any(Uint8Array), - }); - - tmClient.disconnect(); - }); - }); - - describe("consensusStates", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.consensusStates(ibcTest.clientId); - expect(response.consensusStates).toEqual( - jasmine.arrayContaining([ - { - height: jasmine.anything(), - consensusState: { - typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", - value: jasmine.any(Uint8Array), - }, - }, - ]), - ); - - tmClient.disconnect(); - }); - }); - - describe("allConsensusStates", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.allConsensusStates(ibcTest.clientId); - expect(response.consensusStates).toEqual( - jasmine.arrayContaining([ - { - height: jasmine.anything(), - consensusState: { - typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", - value: jasmine.any(Uint8Array), - }, - }, - ]), - ); - - tmClient.disconnect(); - }); - }); - - describe("params", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.params(); - expect(response.params).toEqual({ - allowedClients: ["06-solomachine", "07-tendermint"], - }); - - tmClient.disconnect(); - }); - }); - - describe("stateTm", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.stateTm(ibcTest.clientId); - expect(response.chainId).toEqual("ibc-1"); - // TODO: Fill these expectations out - - tmClient.disconnect(); - }); - }); - - describe("statesTm", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.statesTm(); - expect(response).toEqual( - jasmine.arrayContaining([ - jasmine.objectContaining({ - chainId: "ibc-1", - }), - ]), - ); - - tmClient.disconnect(); - }); - }); - - describe("allStatesTm", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.allStatesTm(); - expect(response).toEqual( - jasmine.arrayContaining([ - jasmine.objectContaining({ - chainId: "ibc-1", - }), - ]), - ); - - tmClient.disconnect(); - }); - }); - - describe("consensusStateTm", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.client.consensusStateTm(ibcTest.clientId); - expect(response.nextValidatorsHash).toEqual(jasmine.any(Uint8Array)); - // TODO: Fill out these expectations - - tmClient.disconnect(); - }); + tmClient.disconnect(); }); }); - describe("connection", () => { - describe("connection", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("consensusState", () => { + xit("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.connection.connection(ibcTest.connectionId); - expect(response.connection).toEqual(ibcTest.connection); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); + const response = await client.ibc.channel.consensusState( + ibcTest.portId, + ibcTest.channelId, + // TODO: Find valid values + 0, + 0, + ); + expect(response.consensusState).toEqual({ + typeUrl: "/haha", + value: jasmine.any(Uint8Array), }); + expect(response.clientId).toEqual(ibcTest.clientId); + + tmClient.disconnect(); }); + }); - describe("connections", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("packetCommitment", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.connection.connections(); - expect(response.connections).toEqual([ibcTest.identifiedConnection]); - expect(response.pagination).toBeDefined(); - expect(response.height).toBeDefined(); + const response = await client.ibc.channel.packetCommitment( + ibcTest.portId, + ibcTest.channelId, + Long.fromInt(ibcTest.commitment.sequence, true), + ); + expect(response.commitment).toEqual(ibcTest.commitment.data); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); - tmClient.disconnect(); + tmClient.disconnect(); + }); + }); + + describe("packetCommitments", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.packetCommitments(ibcTest.portId, ibcTest.channelId); + expect(response.commitments).toEqual([ibcTest.packetState]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allPacketCommitments", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.allPacketCommitments(ibcTest.portId, ibcTest.channelId); + expect(response.commitments).toEqual([ibcTest.packetState]); + + tmClient.disconnect(); + }); + }); + + describe("packetReceipt", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.packetReceipt(ibcTest.portId, ibcTest.channelId, 1); + expect(response.received).toEqual(false); + + tmClient.disconnect(); + }); + }); + + describe("packetAcknowledgement", () => { + it("works", async () => { + pending("We don't have an acknowledgement for testing at the moment"); + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.packetAcknowledgement( + ibcTest.portId, + ibcTest.channelId, + ibcTest.commitment.sequence, + ); + expect(response.acknowledgement).toEqual(ibcTest.packetAcknowledgements[0].data); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("packetAcknowledgements", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.packetAcknowledgements(ibcTest.portId, ibcTest.channelId); + expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allPacketAcknowledgements", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.allPacketAcknowledgements( + ibcTest.portId, + ibcTest.channelId, + ); + expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); + + tmClient.disconnect(); + }); + }); + + describe("unreceivedPackets", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.unreceivedPackets(ibcTest.portId, ibcTest.channelId, [ + 1, + 2, + 3, + ]); + expect(response.sequences).toEqual([1, 2, 3].map((n) => Long.fromInt(n, true))); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("unreceivedAcks", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.unreceivedAcks(ibcTest.portId, ibcTest.channelId, [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + ]); + expect(response.sequences).toEqual([Long.fromInt(ibcTest.commitment.sequence, true)]); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("nextSequenceReceive", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.channel.nextSequenceReceive(ibcTest.portId, ibcTest.channelId); + expect(response.nextSequenceReceive).toEqual(Long.fromInt(1, true)); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + }); + + describe("client", () => { + describe("state", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.state(ibcTest.clientId); + expect(response.clientState).toEqual({ + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), }); + + tmClient.disconnect(); }); + }); - describe("allConnections", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("states", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - const response = await client.ibc.unverified.connection.allConnections(); - expect(response.connections).toEqual([ibcTest.identifiedConnection]); - - tmClient.disconnect(); - }); - }); - - describe("clientConnections", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.connection.clientConnections(ibcTest.clientId); - expect(response.connectionPaths).toEqual([ibcTest.connectionId]); - expect(response.proofHeight).toBeDefined(); - expect(response.proofHeight).not.toBeNull(); - - tmClient.disconnect(); - }); - }); - - describe("clientState", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - - const response = await client.ibc.unverified.connection.clientState(ibcTest.connectionId); - expect(response.identifiedClientState).toEqual({ + const response = await client.ibc.client.states(); + expect(response.clientStates).toEqual([ + { clientId: ibcTest.clientId, clientState: { typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", value: jasmine.any(Uint8Array), }, - }); + }, + ]); + expect(response.pagination).toBeDefined(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("consensusState", () => { - xit("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + describe("allStates", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); - // TODO: Find valid values - const response = await client.ibc.unverified.connection.consensusState(ibcTest.connectionId, 1, 1); - expect(response.clientId).toEqual(ibcTest.clientId); - expect(response.consensusState).toEqual({ - typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", - value: jasmine.any(Uint8Array), - }); + const response = await client.ibc.client.allStates(); + expect(response.clientStates).toEqual([ + { + clientId: ibcTest.clientId, + clientState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }, + }, + ]); - tmClient.disconnect(); + tmClient.disconnect(); + }); + }); + + describe("consensusState", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.consensusState(ibcTest.clientId); + expect(response.consensusState).toEqual({ + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), }); + + tmClient.disconnect(); + }); + }); + + describe("consensusStates", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.consensusStates(ibcTest.clientId); + expect(response.consensusStates).toEqual( + jasmine.arrayContaining([ + { + height: jasmine.anything(), + consensusState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }, + }, + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("allConsensusStates", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.allConsensusStates(ibcTest.clientId); + expect(response.consensusStates).toEqual( + jasmine.arrayContaining([ + { + height: jasmine.anything(), + consensusState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }, + }, + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("params", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.params(); + expect(response.params).toEqual({ + allowedClients: ["06-solomachine", "07-tendermint"], + }); + + tmClient.disconnect(); + }); + }); + + describe("stateTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.stateTm(ibcTest.clientId); + expect(response.chainId).toEqual("ibc-1"); + // TODO: Fill these expectations out + + tmClient.disconnect(); + }); + }); + + describe("statesTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.statesTm(); + expect(response).toEqual( + jasmine.arrayContaining([ + jasmine.objectContaining({ + chainId: "ibc-1", + }), + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("allStatesTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.allStatesTm(); + expect(response).toEqual( + jasmine.arrayContaining([ + jasmine.objectContaining({ + chainId: "ibc-1", + }), + ]), + ); + + tmClient.disconnect(); + }); + }); + + describe("consensusStateTm", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.client.consensusStateTm(ibcTest.clientId); + expect(response.nextValidatorsHash).toEqual(jasmine.any(Uint8Array)); + // TODO: Fill out these expectations + + tmClient.disconnect(); + }); + }); + }); + + describe("connection", () => { + describe("connection", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.connection.connection(ibcTest.connectionId); + expect(response.connection).toEqual(ibcTest.connection); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("connections", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.connection.connections(); + expect(response.connections).toEqual([ibcTest.identifiedConnection]); + expect(response.pagination).toBeDefined(); + expect(response.height).toBeDefined(); + + tmClient.disconnect(); + }); + }); + + describe("allConnections", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.connection.allConnections(); + expect(response.connections).toEqual([ibcTest.identifiedConnection]); + + tmClient.disconnect(); + }); + }); + + describe("clientConnections", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.connection.clientConnections(ibcTest.clientId); + expect(response.connectionPaths).toEqual([ibcTest.connectionId]); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("clientState", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.connection.clientState(ibcTest.connectionId); + expect(response.identifiedClientState).toEqual({ + clientId: ibcTest.clientId, + clientState: { + typeUrl: "/ibc.lightclients.tendermint.v1.ClientState", + value: jasmine.any(Uint8Array), + }, + }); + + tmClient.disconnect(); + }); + }); + + describe("consensusState", () => { + xit("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + // TODO: Find valid values + const response = await client.ibc.connection.consensusState(ibcTest.connectionId, 1, 1); + expect(response.clientId).toEqual(ibcTest.clientId); + expect(response.consensusState).toEqual({ + typeUrl: "/ibc.lightclients.tendermint.v1.ConsensusState", + value: jasmine.any(Uint8Array), + }); + + tmClient.disconnect(); }); }); }); diff --git a/packages/stargate/src/queries/ibc.ts b/packages/stargate/src/queries/ibc.ts index 9ae7cb8f..2cfe141f 100644 --- a/packages/stargate/src/queries/ibc.ts +++ b/packages/stargate/src/queries/ibc.ts @@ -64,107 +64,111 @@ function decodeTendermintConsensusStateAny(clientState: Any | undefined): Tender export interface IbcExtension { readonly ibc: { readonly channel: { - readonly channel: (portId: string, channelId: string) => Promise; - readonly packetCommitment: (portId: string, channelId: string, sequence: number) => Promise; + readonly channel: (portId: string, channelId: string) => Promise; + readonly channels: (paginationKey?: Uint8Array) => Promise; + readonly allChannels: () => Promise; + readonly connectionChannels: ( + connection: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allConnectionChannels: (connection: string) => Promise; + readonly clientState: (portId: string, channelId: string) => Promise; + readonly consensusState: ( + portId: string, + channelId: string, + revisionNumber: number, + revisionHeight: number, + ) => Promise; + readonly packetCommitment: ( + portId: string, + channelId: string, + sequence: Long, + ) => Promise; + readonly packetCommitments: ( + portId: string, + channelId: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allPacketCommitments: ( + portId: string, + channelId: string, + ) => Promise; + readonly packetReceipt: ( + portId: string, + channelId: string, + sequence: number, + ) => Promise; readonly packetAcknowledgement: ( portId: string, channelId: string, sequence: number, - ) => Promise; - readonly nextSequenceReceive: (portId: string, channelId: string) => Promise; + ) => Promise; + readonly packetAcknowledgements: ( + portId: string, + channelId: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allPacketAcknowledgements: ( + portId: string, + channelId: string, + ) => Promise; + readonly unreceivedPackets: ( + portId: string, + channelId: string, + packetCommitmentSequences: readonly number[], + ) => Promise; + readonly unreceivedAcks: ( + portId: string, + channelId: string, + packetAckSequences: readonly number[], + ) => Promise; + readonly nextSequenceReceive: ( + portId: string, + channelId: string, + ) => Promise; }; - readonly unverified: { + readonly client: { + readonly state: (clientId: string) => Promise; + readonly states: (paginationKey?: Uint8Array) => Promise; + readonly allStates: () => Promise; + readonly consensusState: (clientId: string, height?: number) => Promise; + readonly consensusStates: ( + clientId: string, + paginationKey?: Uint8Array, + ) => Promise; + readonly allConsensusStates: (clientId: string) => Promise; + readonly params: () => Promise; + readonly stateTm: (clientId: string) => Promise; + readonly statesTm: (paginationKey?: Uint8Array) => Promise; + readonly allStatesTm: () => Promise; + readonly consensusStateTm: (clientId: string, height?: Height) => Promise; + }; + readonly connection: { + readonly connection: (connectionId: string) => Promise; + readonly connections: (paginationKey?: Uint8Array) => Promise; + readonly allConnections: () => Promise; + readonly clientConnections: (clientId: string) => Promise; + readonly clientState: (connectionId: string) => Promise; + readonly consensusState: ( + connectionId: string, + revisionNumber: number, + revisionHeight: number, + ) => Promise; + }; + readonly verified: { readonly channel: { - readonly channel: (portId: string, channelId: string) => Promise; - readonly channels: (paginationKey?: Uint8Array) => Promise; - readonly allChannels: () => Promise; - readonly connectionChannels: ( - connection: string, - paginationKey?: Uint8Array, - ) => Promise; - readonly allConnectionChannels: (connection: string) => Promise; - readonly clientState: (portId: string, channelId: string) => Promise; - readonly consensusState: ( - portId: string, - channelId: string, - revisionNumber: number, - revisionHeight: number, - ) => Promise; + readonly channel: (portId: string, channelId: string) => Promise; readonly packetCommitment: ( - portId: string, - channelId: string, - sequence: Long, - ) => Promise; - readonly packetCommitments: ( - portId: string, - channelId: string, - paginationKey?: Uint8Array, - ) => Promise; - readonly allPacketCommitments: ( - portId: string, - channelId: string, - ) => Promise; - readonly packetReceipt: ( portId: string, channelId: string, sequence: number, - ) => Promise; + ) => Promise; readonly packetAcknowledgement: ( portId: string, channelId: string, sequence: number, - ) => Promise; - readonly packetAcknowledgements: ( - portId: string, - channelId: string, - paginationKey?: Uint8Array, - ) => Promise; - readonly allPacketAcknowledgements: ( - portId: string, - channelId: string, - ) => Promise; - readonly unreceivedPackets: ( - portId: string, - channelId: string, - packetCommitmentSequences: readonly number[], - ) => Promise; - readonly unreceivedAcks: ( - portId: string, - channelId: string, - packetAckSequences: readonly number[], - ) => Promise; - readonly nextSequenceReceive: ( - portId: string, - channelId: string, - ) => Promise; - }; - readonly client: { - readonly state: (clientId: string) => Promise; - readonly states: (paginationKey?: Uint8Array) => Promise; - readonly allStates: () => Promise; - readonly consensusState: (clientId: string, height?: number) => Promise; - readonly consensusStates: ( - clientId: string, - paginationKey?: Uint8Array, - ) => Promise; - readonly allConsensusStates: (clientId: string) => Promise; - readonly params: () => Promise; - readonly stateTm: (clientId: string) => Promise; - readonly statesTm: (paginationKey?: Uint8Array) => Promise; - readonly allStatesTm: () => Promise; - readonly consensusStateTm: (clientId: string, height?: Height) => Promise; - }; - readonly connection: { - readonly connection: (connectionId: string) => Promise; - readonly connections: (paginationKey?: Uint8Array) => Promise; - readonly allConnections: () => Promise; - readonly clientConnections: (clientId: string) => Promise; - readonly clientState: (connectionId: string) => Promise; - readonly consensusState: ( - connectionId: string, - revisionNumber: number, - revisionHeight: number, - ) => Promise; + ) => Promise; + readonly nextSequenceReceive: (portId: string, channelId: string) => Promise; }; }; }; @@ -181,318 +185,318 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { return { ibc: { channel: { - channel: async (portId: string, channelId: string) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L55-L65 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L117-L120 - const key = toAscii(`channelEnds/ports/${portId}/channels/${channelId}`); - const responseData = await base.queryVerified("ibc", key); - return responseData.length ? Channel.decode(responseData) : null; + channel: async (portId: string, channelId: string) => + channelQueryService.Channel({ + portId: portId, + channelId: channelId, + }), + channels: async (paginationKey?: Uint8Array) => + channelQueryService.Channels({ + pagination: createPagination(paginationKey), + }), + allChannels: async () => { + const channels = []; + let response: QueryChannelsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.Channels({ + pagination: createPagination(key), + }); + channels.push(...response.channels); + key = response.pagination?.nextKey; + } while (key); + return { + channels: channels, + height: response.height, + }; }, - packetCommitment: async (portId: string, channelId: string, sequence: number) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L128-L133 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L183-L185 - const key = toAscii(`commitments/ports/${portId}/channels/${channelId}/packets/${sequence}`); - const responseData = await base.queryVerified("ibc", key); - // keeper code doesn't parse, but returns raw - return responseData; + connectionChannels: async (connection: string, paginationKey?: Uint8Array) => + channelQueryService.ConnectionChannels({ + connection: connection, + pagination: createPagination(paginationKey), + }), + allConnectionChannels: async (connection: string) => { + const channels = []; + let response: QueryConnectionChannelsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.ConnectionChannels({ + connection: connection, + pagination: createPagination(key), + }); + channels.push(...response.channels); + key = response.pagination?.nextKey; + } while (key); + return { + channels: channels, + height: response.height, + }; }, - packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L159-L166 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L153-L156 - const key = toAscii(`acks/ports/${portId}/channels/${channelId}/acknowledgements/${sequence}`); - const responseData = await base.queryVerified("ibc", key); - // keeper code doesn't parse, but returns raw - return responseData; + clientState: async (portId: string, channelId: string) => + channelQueryService.ChannelClientState({ + portId: portId, + channelId: channelId, + }), + consensusState: async ( + portId: string, + channelId: string, + revisionNumber: number, + revisionHeight: number, + ) => + channelQueryService.ChannelConsensusState({ + portId: portId, + channelId: channelId, + revisionNumber: Long.fromNumber(revisionNumber, true), + revisionHeight: Long.fromNumber(revisionHeight, true), + }), + packetCommitment: async (portId: string, channelId: string, sequence: Long) => + channelQueryService.PacketCommitment({ + portId: portId, + channelId: channelId, + sequence: sequence, + }), + packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) => + channelQueryService.PacketCommitments({ + channelId: channelId, + portId: portId, + pagination: createPagination(paginationKey), + }), + allPacketCommitments: async (portId: string, channelId: string) => { + const commitments = []; + let response: QueryPacketCommitmentsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.PacketCommitments({ + channelId: channelId, + portId: portId, + pagination: createPagination(key), + }); + commitments.push(...response.commitments); + key = response.pagination?.nextKey; + } while (key); + return { + commitments: commitments, + height: response.height, + }; }, - nextSequenceReceive: async (portId: string, channelId: string) => { - // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L92-L101 - // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L133-L136 - const key = toAscii(`seqAcks/ports/${portId}/channels/${channelId}/nextSequenceAck`); - const responseData = await base.queryVerified("ibc", key); - return responseData.length ? Uint64.fromBytes(responseData).toNumber() : null; + packetReceipt: async (portId: string, channelId: string, sequence: number) => + channelQueryService.PacketReceipt({ + portId: portId, + channelId: channelId, + sequence: Long.fromNumber(sequence, true), + }), + packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => + channelQueryService.PacketAcknowledgement({ + portId: portId, + channelId: channelId, + sequence: Long.fromNumber(sequence, true), + }), + packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => + channelQueryService.PacketAcknowledgements({ + portId: portId, + channelId: channelId, + pagination: createPagination(paginationKey), + }), + allPacketAcknowledgements: async (portId: string, channelId: string) => { + const acknowledgements = []; + let response: QueryPacketAcknowledgementsResponse; + let key: Uint8Array | undefined; + do { + response = await channelQueryService.PacketAcknowledgements({ + channelId: channelId, + portId: portId, + pagination: createPagination(key), + }); + acknowledgements.push(...response.acknowledgements); + key = response.pagination?.nextKey; + } while (key); + return { + acknowledgements: acknowledgements, + height: response.height, + }; + }, + unreceivedPackets: async ( + portId: string, + channelId: string, + packetCommitmentSequences: readonly number[], + ) => + channelQueryService.UnreceivedPackets({ + portId: portId, + channelId: channelId, + packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s, true)), + }), + unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => + channelQueryService.UnreceivedAcks({ + portId: portId, + channelId: channelId, + packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s, true)), + }), + nextSequenceReceive: async (portId: string, channelId: string) => + channelQueryService.NextSequenceReceive({ + portId: portId, + channelId: channelId, + }), + }, + client: { + state: (clientId: string) => clientQueryService.ClientState({ clientId }), + states: (paginationKey?: Uint8Array) => + clientQueryService.ClientStates({ + pagination: createPagination(paginationKey), + }), + allStates: async () => { + const clientStates = []; + let response: QueryClientStatesResponse; + let key: Uint8Array | undefined; + do { + response = await clientQueryService.ClientStates({ + pagination: createPagination(key), + }); + clientStates.push(...response.clientStates); + key = response.pagination?.nextKey; + } while (key); + return { + clientStates: clientStates, + }; + }, + consensusState: (clientId: string, consensusHeight?: number) => + clientQueryService.ConsensusState( + QueryConsensusStateRequest.fromPartial({ + clientId: clientId, + revisionHeight: + consensusHeight !== undefined ? Long.fromNumber(consensusHeight, true) : undefined, + latestHeight: consensusHeight === undefined, + }), + ), + consensusStates: (clientId: string, paginationKey?: Uint8Array) => + clientQueryService.ConsensusStates({ + clientId: clientId, + pagination: createPagination(paginationKey), + }), + allConsensusStates: async (clientId: string) => { + const consensusStates = []; + let response: QueryConsensusStatesResponse; + let key: Uint8Array | undefined; + do { + response = await clientQueryService.ConsensusStates({ + clientId: clientId, + pagination: createPagination(key), + }); + consensusStates.push(...response.consensusStates); + key = response.pagination?.nextKey; + } while (key); + return { + consensusStates: consensusStates, + }; + }, + params: () => clientQueryService.ClientParams({}), + stateTm: async (clientId: string) => { + const response = await clientQueryService.ClientState({ clientId }); + return decodeTendermintClientStateAny(response.clientState); + }, + statesTm: async (paginationKey?: Uint8Array) => { + const { clientStates } = await clientQueryService.ClientStates({ + pagination: createPagination(paginationKey), + }); + return clientStates.map(({ clientState }) => decodeTendermintClientStateAny(clientState)); + }, + allStatesTm: async () => { + const clientStates = []; + let response: QueryClientStatesResponse; + let key: Uint8Array | undefined; + do { + response = await clientQueryService.ClientStates({ + pagination: createPagination(key), + }); + clientStates.push(...response.clientStates); + key = response.pagination?.nextKey; + } while (key); + return clientStates.map(({ clientState }) => decodeTendermintClientStateAny(clientState)); + }, + consensusStateTm: async (clientId: string, consensusHeight?: Height) => { + const response = await clientQueryService.ConsensusState( + QueryConsensusStateRequest.fromPartial({ + clientId: clientId, + revisionHeight: consensusHeight?.revisionHeight, + revisionNumber: consensusHeight?.revisionNumber, + latestHeight: consensusHeight === undefined, + }), + ); + return decodeTendermintConsensusStateAny(response.consensusState); }, }, - unverified: { - channel: { - channel: async (portId: string, channelId: string) => - channelQueryService.Channel({ - portId: portId, - channelId: channelId, - }), - channels: async (paginationKey?: Uint8Array) => - channelQueryService.Channels({ - pagination: createPagination(paginationKey), - }), - allChannels: async () => { - const channels = []; - let response: QueryChannelsResponse; - let key: Uint8Array | undefined; - do { - response = await channelQueryService.Channels({ - pagination: createPagination(key), - }); - channels.push(...response.channels); - key = response.pagination?.nextKey; - } while (key); - return { - channels: channels, - height: response.height, - }; - }, - connectionChannels: async (connection: string, paginationKey?: Uint8Array) => - channelQueryService.ConnectionChannels({ - connection: connection, - pagination: createPagination(paginationKey), - }), - allConnectionChannels: async (connection: string) => { - const channels = []; - let response: QueryConnectionChannelsResponse; - let key: Uint8Array | undefined; - do { - response = await channelQueryService.ConnectionChannels({ - connection: connection, - pagination: createPagination(key), - }); - channels.push(...response.channels); - key = response.pagination?.nextKey; - } while (key); - return { - channels: channels, - height: response.height, - }; - }, - clientState: async (portId: string, channelId: string) => - channelQueryService.ChannelClientState({ - portId: portId, - channelId: channelId, - }), - consensusState: async ( - portId: string, - channelId: string, - revisionNumber: number, - revisionHeight: number, - ) => - channelQueryService.ChannelConsensusState({ - portId: portId, - channelId: channelId, - revisionNumber: Long.fromNumber(revisionNumber, true), + connection: { + connection: async (connectionId: string) => + connectionQueryService.Connection({ + connectionId: connectionId, + }), + connections: async (paginationKey?: Uint8Array) => + connectionQueryService.Connections({ + pagination: createPagination(paginationKey), + }), + allConnections: async () => { + const connections = []; + let response: QueryConnectionsResponse; + let key: Uint8Array | undefined; + do { + response = await connectionQueryService.Connections({ + pagination: createPagination(key), + }); + connections.push(...response.connections); + key = response.pagination?.nextKey; + } while (key); + return { + connections: connections, + height: response.height, + }; + }, + clientConnections: async (clientId: string) => + connectionQueryService.ClientConnections({ + clientId: clientId, + }), + clientState: async (connectionId: string) => + connectionQueryService.ConnectionClientState({ + connectionId: connectionId, + }), + consensusState: async (connectionId: string, revisionHeight: number) => + connectionQueryService.ConnectionConsensusState( + QueryConnectionConsensusStateRequest.fromPartial({ + connectionId: connectionId, revisionHeight: Long.fromNumber(revisionHeight, true), }), - packetCommitment: async (portId: string, channelId: string, sequence: Long) => - channelQueryService.PacketCommitment({ - portId: portId, - channelId: channelId, - sequence: sequence, - }), - packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) => - channelQueryService.PacketCommitments({ - channelId: channelId, - portId: portId, - pagination: createPagination(paginationKey), - }), - allPacketCommitments: async (portId: string, channelId: string) => { - const commitments = []; - let response: QueryPacketCommitmentsResponse; - let key: Uint8Array | undefined; - do { - response = await channelQueryService.PacketCommitments({ - channelId: channelId, - portId: portId, - pagination: createPagination(key), - }); - commitments.push(...response.commitments); - key = response.pagination?.nextKey; - } while (key); - return { - commitments: commitments, - height: response.height, - }; + ), + }, + verified: { + channel: { + channel: async (portId: string, channelId: string) => { + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L55-L65 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L117-L120 + const key = toAscii(`channelEnds/ports/${portId}/channels/${channelId}`); + const responseData = await base.queryVerified("ibc", key); + return responseData.length ? Channel.decode(responseData) : null; }, - packetReceipt: async (portId: string, channelId: string, sequence: number) => - channelQueryService.PacketReceipt({ - portId: portId, - channelId: channelId, - sequence: Long.fromNumber(sequence, true), - }), - packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => - channelQueryService.PacketAcknowledgement({ - portId: portId, - channelId: channelId, - sequence: Long.fromNumber(sequence, true), - }), - packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => - channelQueryService.PacketAcknowledgements({ - portId: portId, - channelId: channelId, - pagination: createPagination(paginationKey), - }), - allPacketAcknowledgements: async (portId: string, channelId: string) => { - const acknowledgements = []; - let response: QueryPacketAcknowledgementsResponse; - let key: Uint8Array | undefined; - do { - response = await channelQueryService.PacketAcknowledgements({ - channelId: channelId, - portId: portId, - pagination: createPagination(key), - }); - acknowledgements.push(...response.acknowledgements); - key = response.pagination?.nextKey; - } while (key); - return { - acknowledgements: acknowledgements, - height: response.height, - }; + packetCommitment: async (portId: string, channelId: string, sequence: number) => { + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L128-L133 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L183-L185 + const key = toAscii(`commitments/ports/${portId}/channels/${channelId}/packets/${sequence}`); + const responseData = await base.queryVerified("ibc", key); + // keeper code doesn't parse, but returns raw + return responseData; }, - unreceivedPackets: async ( - portId: string, - channelId: string, - packetCommitmentSequences: readonly number[], - ) => - channelQueryService.UnreceivedPackets({ - portId: portId, - channelId: channelId, - packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s, true)), - }), - unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => - channelQueryService.UnreceivedAcks({ - portId: portId, - channelId: channelId, - packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s, true)), - }), - nextSequenceReceive: async (portId: string, channelId: string) => - channelQueryService.NextSequenceReceive({ - portId: portId, - channelId: channelId, - }), - }, - client: { - state: (clientId: string) => clientQueryService.ClientState({ clientId }), - states: (paginationKey?: Uint8Array) => - clientQueryService.ClientStates({ - pagination: createPagination(paginationKey), - }), - allStates: async () => { - const clientStates = []; - let response: QueryClientStatesResponse; - let key: Uint8Array | undefined; - do { - response = await clientQueryService.ClientStates({ - pagination: createPagination(key), - }); - clientStates.push(...response.clientStates); - key = response.pagination?.nextKey; - } while (key); - return { - clientStates: clientStates, - }; + packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => { + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L159-L166 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L153-L156 + const key = toAscii(`acks/ports/${portId}/channels/${channelId}/acknowledgements/${sequence}`); + const responseData = await base.queryVerified("ibc", key); + // keeper code doesn't parse, but returns raw + return responseData; }, - consensusState: (clientId: string, consensusHeight?: number) => - clientQueryService.ConsensusState( - QueryConsensusStateRequest.fromPartial({ - clientId: clientId, - revisionHeight: - consensusHeight !== undefined ? Long.fromNumber(consensusHeight, true) : undefined, - latestHeight: consensusHeight === undefined, - }), - ), - consensusStates: (clientId: string, paginationKey?: Uint8Array) => - clientQueryService.ConsensusStates({ - clientId: clientId, - pagination: createPagination(paginationKey), - }), - allConsensusStates: async (clientId: string) => { - const consensusStates = []; - let response: QueryConsensusStatesResponse; - let key: Uint8Array | undefined; - do { - response = await clientQueryService.ConsensusStates({ - clientId: clientId, - pagination: createPagination(key), - }); - consensusStates.push(...response.consensusStates); - key = response.pagination?.nextKey; - } while (key); - return { - consensusStates: consensusStates, - }; + nextSequenceReceive: async (portId: string, channelId: string) => { + // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L92-L101 + // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L133-L136 + const key = toAscii(`seqAcks/ports/${portId}/channels/${channelId}/nextSequenceAck`); + const responseData = await base.queryVerified("ibc", key); + return responseData.length ? Uint64.fromBytes(responseData).toNumber() : null; }, - params: () => clientQueryService.ClientParams({}), - stateTm: async (clientId: string) => { - const response = await clientQueryService.ClientState({ clientId }); - return decodeTendermintClientStateAny(response.clientState); - }, - statesTm: async (paginationKey?: Uint8Array) => { - const { clientStates } = await clientQueryService.ClientStates({ - pagination: createPagination(paginationKey), - }); - return clientStates.map(({ clientState }) => decodeTendermintClientStateAny(clientState)); - }, - allStatesTm: async () => { - const clientStates = []; - let response: QueryClientStatesResponse; - let key: Uint8Array | undefined; - do { - response = await clientQueryService.ClientStates({ - pagination: createPagination(key), - }); - clientStates.push(...response.clientStates); - key = response.pagination?.nextKey; - } while (key); - return clientStates.map(({ clientState }) => decodeTendermintClientStateAny(clientState)); - }, - consensusStateTm: async (clientId: string, consensusHeight?: Height) => { - const response = await clientQueryService.ConsensusState( - QueryConsensusStateRequest.fromPartial({ - clientId: clientId, - revisionHeight: consensusHeight?.revisionHeight, - revisionNumber: consensusHeight?.revisionNumber, - latestHeight: consensusHeight === undefined, - }), - ); - return decodeTendermintConsensusStateAny(response.consensusState); - }, - }, - connection: { - connection: async (connectionId: string) => - connectionQueryService.Connection({ - connectionId: connectionId, - }), - connections: async (paginationKey?: Uint8Array) => - connectionQueryService.Connections({ - pagination: createPagination(paginationKey), - }), - allConnections: async () => { - const connections = []; - let response: QueryConnectionsResponse; - let key: Uint8Array | undefined; - do { - response = await connectionQueryService.Connections({ - pagination: createPagination(key), - }); - connections.push(...response.connections); - key = response.pagination?.nextKey; - } while (key); - return { - connections: connections, - height: response.height, - }; - }, - clientConnections: async (clientId: string) => - connectionQueryService.ClientConnections({ - clientId: clientId, - }), - clientState: async (connectionId: string) => - connectionQueryService.ConnectionClientState({ - connectionId: connectionId, - }), - consensusState: async (connectionId: string, revisionHeight: number) => - connectionQueryService.ConnectionConsensusState( - QueryConnectionConsensusStateRequest.fromPartial({ - connectionId: connectionId, - revisionHeight: Long.fromNumber(revisionHeight, true), - }), - ), }, }, },