diff --git a/CHANGELOG.md b/CHANGELOG.md index bb36ba4b..7345a7e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,8 +77,8 @@ and this project adheres to `Bech32.encode(prefix, rawSecp256k1PubkeyToRawAddress(pubkeyRaw))` with `rawSecp256k1PubkeyToRawAddress` from @cosmjs/amino. - @cosmjs/stargate: `parseRawLog` is now nested under the `logs` export. -- @cosmjs/stargate: `auth` and `bank` extensions now have unverified queries at - the root and verified queries nested under `.verified`. +- @cosmjs/stargate: Query extensions now have unverified queries at the root and + verified queries nested under `.verified`. - @cosmjs/cosmwasm-stargate: `wasm` extension now has unverified queries at the root. - @cosmjs/stargate: `StargateClient.getAccount` now uses an unverified query and diff --git a/packages/stargate/src/queries/staking.spec.ts b/packages/stargate/src/queries/staking.spec.ts index b624becf..212913c4 100644 --- a/packages/stargate/src/queries/staking.spec.ts +++ b/packages/stargate/src/queries/staking.spec.ts @@ -61,203 +61,186 @@ describe("StakingExtension", () => { } }); - describe("unverified", () => { - describe("delegation", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("delegation", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.delegation( - faucet.address0, - validator.validatorAddress, - ); - expect(response.delegationResponse).toBeDefined(); - expect(response.delegationResponse).not.toBeNull(); + const response = await client.staking.delegation(faucet.address0, validator.validatorAddress); + expect(response.delegationResponse).toBeDefined(); + expect(response.delegationResponse).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("delegatorDelegations", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("delegatorDelegations", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.delegatorDelegations(faucet.address0); - expect(response.delegationResponses).toBeDefined(); - expect(response.delegationResponses).not.toBeNull(); + const response = await client.staking.delegatorDelegations(faucet.address0); + expect(response.delegationResponses).toBeDefined(); + expect(response.delegationResponses).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("delegatorUnbondingDelegations", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("delegatorUnbondingDelegations", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.delegatorUnbondingDelegations(faucet.address0); - expect(response.unbondingResponses).toBeDefined(); - expect(response.unbondingResponses).not.toBeNull(); + const response = await client.staking.delegatorUnbondingDelegations(faucet.address0); + expect(response.unbondingResponses).toBeDefined(); + expect(response.unbondingResponses).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("delegatorValidator", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("delegatorValidator", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.delegatorValidator( - faucet.address0, - validator.validatorAddress, - ); - expect(response.validator).toBeDefined(); - expect(response.validator).not.toBeNull(); + const response = await client.staking.delegatorValidator(faucet.address0, validator.validatorAddress); + expect(response.validator).toBeDefined(); + expect(response.validator).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("delegatorValidators", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("delegatorValidators", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.delegatorValidators(faucet.address0); - expect(response.validators).toBeDefined(); - expect(response.validators).not.toBeNull(); + const response = await client.staking.delegatorValidators(faucet.address0); + expect(response.validators).toBeDefined(); + expect(response.validators).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("historicalInfo", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("historicalInfo", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.historicalInfo(5); - expect(response.hist).toBeDefined(); - expect(response.hist).not.toBeNull(); + const response = await client.staking.historicalInfo(5); + expect(response.hist).toBeDefined(); + expect(response.hist).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("params", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("params", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.params(); - expect(response.params).toBeDefined(); - expect(response.params).not.toBeNull(); + const response = await client.staking.params(); + expect(response.params).toBeDefined(); + expect(response.params).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("pool", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("pool", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.pool(); - expect(response.pool).toBeDefined(); - expect(response.pool).not.toBeNull(); + const response = await client.staking.pool(); + expect(response.pool).toBeDefined(); + expect(response.pool).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("redelegations", () => { - it("works", async () => { - // TODO: Set up a result for this test - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("redelegations", () => { + it("works", async () => { + // TODO: Set up a result for this test + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - await expectAsync( - client.staking.unverified.redelegations( - faucet.address0, - validator.validatorAddress, - validator.validatorAddress, - ), - ).toBeRejectedWithError(/redelegation not found/i); + await expectAsync( + client.staking.redelegations(faucet.address0, validator.validatorAddress, validator.validatorAddress), + ).toBeRejectedWithError(/redelegation not found/i); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("unbondingDelegation", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("unbondingDelegation", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.unbondingDelegation( - faucet.address0, - validator.validatorAddress, - ); - expect(response.unbond).toBeDefined(); - expect(response.unbond).not.toBeNull(); + const response = await client.staking.unbondingDelegation(faucet.address0, validator.validatorAddress); + expect(response.unbond).toBeDefined(); + expect(response.unbond).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("validator", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("validator", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.validator(validator.validatorAddress); - expect(response.validator).toBeDefined(); - expect(response.validator).not.toBeNull(); + const response = await client.staking.validator(validator.validatorAddress); + expect(response.validator).toBeDefined(); + expect(response.validator).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("validatorDelegations", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("validatorDelegations", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.validatorDelegations(validator.validatorAddress); - expect(response.delegationResponses).toBeDefined(); - expect(response.delegationResponses).not.toBeNull(); + const response = await client.staking.validatorDelegations(validator.validatorAddress); + expect(response.delegationResponses).toBeDefined(); + expect(response.delegationResponses).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("validators", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("validators", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.validators("BOND_STATUS_BONDED"); - expect(response.validators).toBeDefined(); - expect(response.validators).not.toBeNull(); + const response = await client.staking.validators("BOND_STATUS_BONDED"); + expect(response.validators).toBeDefined(); + expect(response.validators).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); + }); - describe("validatorUnbondingDelegations", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); + describe("validatorUnbondingDelegations", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithStaking(simapp.tendermintUrl); - const response = await client.staking.unverified.validatorUnbondingDelegations( - validator.validatorAddress, - ); - expect(response.unbondingResponses).toBeDefined(); - expect(response.unbondingResponses).not.toBeNull(); + const response = await client.staking.validatorUnbondingDelegations(validator.validatorAddress); + expect(response.unbondingResponses).toBeDefined(); + expect(response.unbondingResponses).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); }); }); diff --git a/packages/stargate/src/queries/staking.ts b/packages/stargate/src/queries/staking.ts index 4b726304..5161da5c 100644 --- a/packages/stargate/src/queries/staking.ts +++ b/packages/stargate/src/queries/staking.ts @@ -26,48 +26,46 @@ export type BondStatusString = Exclude Promise; - delegatorDelegations: ( - delegatorAddress: string, - paginationKey?: Uint8Array, - ) => Promise; - delegatorUnbondingDelegations: ( - delegatorAddress: string, - paginationKey?: Uint8Array, - ) => Promise; - delegatorValidator: ( - delegatorAddress: string, - validatorAddress: string, - ) => Promise; - delegatorValidators: ( - delegatorAddress: string, - paginationKey?: Uint8Array, - ) => Promise; - historicalInfo: (height: number) => Promise; - params: () => Promise; - pool: () => Promise; - redelegations: ( - delegatorAddress: string, - sourceValidatorAddress: string, - destinationValidatorAddress: string, - paginationKey?: Uint8Array, - ) => Promise; - unbondingDelegation: ( - delegatorAddress: string, - validatorAddress: string, - ) => Promise; - validator: (validatorAddress: string) => Promise; - validatorDelegations: ( - validatorAddress: string, - paginationKey?: Uint8Array, - ) => Promise; - validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise; - validatorUnbondingDelegations: ( - validatorAddress: string, - paginationKey?: Uint8Array, - ) => Promise; - }; + delegation: (delegatorAddress: string, validatorAddress: string) => Promise; + delegatorDelegations: ( + delegatorAddress: string, + paginationKey?: Uint8Array, + ) => Promise; + delegatorUnbondingDelegations: ( + delegatorAddress: string, + paginationKey?: Uint8Array, + ) => Promise; + delegatorValidator: ( + delegatorAddress: string, + validatorAddress: string, + ) => Promise; + delegatorValidators: ( + delegatorAddress: string, + paginationKey?: Uint8Array, + ) => Promise; + historicalInfo: (height: number) => Promise; + params: () => Promise; + pool: () => Promise; + redelegations: ( + delegatorAddress: string, + sourceValidatorAddress: string, + destinationValidatorAddress: string, + paginationKey?: Uint8Array, + ) => Promise; + unbondingDelegation: ( + delegatorAddress: string, + validatorAddress: string, + ) => Promise; + validator: (validatorAddress: string) => Promise; + validatorDelegations: ( + validatorAddress: string, + paginationKey?: Uint8Array, + ) => Promise; + validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise; + validatorUnbondingDelegations: ( + validatorAddress: string, + paginationKey?: Uint8Array, + ) => Promise; }; } @@ -79,102 +77,100 @@ export function setupStakingExtension(base: QueryClient): StakingExtension { return { staking: { - unverified: { - delegation: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.Delegation({ - delegatorAddr: delegatorAddress, - validatorAddr: validatorAddress, - }); - return response; - }, - delegatorDelegations: async (delegatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.DelegatorDelegations({ - delegatorAddr: delegatorAddress, - pagination: createPagination(paginationKey), - }); - return response; - }, - delegatorUnbondingDelegations: async (delegatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.DelegatorUnbondingDelegations({ - delegatorAddr: delegatorAddress, - pagination: createPagination(paginationKey), - }); - return response; - }, - delegatorValidator: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.DelegatorValidator({ - delegatorAddr: delegatorAddress, - validatorAddr: validatorAddress, - }); - return response; - }, - delegatorValidators: async (delegatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.DelegatorValidators({ - delegatorAddr: delegatorAddress, - pagination: createPagination(paginationKey), - }); - return response; - }, - historicalInfo: async (height: number) => { - const response = await queryService.HistoricalInfo({ - height: Long.fromNumber(height, true), - }); - return response; - }, - params: async () => { - const response = await queryService.Params({}); - return response; - }, - pool: async () => { - const response = await queryService.Pool({}); - return response; - }, - redelegations: async ( - delegatorAddress: string, - sourceValidatorAddress: string, - destinationValidatorAddress: string, - paginationKey?: Uint8Array, - ) => { - const response = await queryService.Redelegations({ - delegatorAddr: delegatorAddress, - srcValidatorAddr: sourceValidatorAddress, - dstValidatorAddr: destinationValidatorAddress, - pagination: createPagination(paginationKey), - }); - return response; - }, - unbondingDelegation: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.UnbondingDelegation({ - delegatorAddr: delegatorAddress, - validatorAddr: validatorAddress, - }); - return response; - }, - validator: async (validatorAddress: string) => { - const response = await queryService.Validator({ validatorAddr: validatorAddress }); - return response; - }, - validatorDelegations: async (validatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.ValidatorDelegations({ - validatorAddr: validatorAddress, - pagination: createPagination(paginationKey), - }); - return response; - }, - validators: async (status: BondStatusString, paginationKey?: Uint8Array) => { - const response = await queryService.Validators({ - status: status, - pagination: createPagination(paginationKey), - }); - return response; - }, - validatorUnbondingDelegations: async (validatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.ValidatorUnbondingDelegations({ - validatorAddr: validatorAddress, - pagination: createPagination(paginationKey), - }); - return response; - }, + delegation: async (delegatorAddress: string, validatorAddress: string) => { + const response = await queryService.Delegation({ + delegatorAddr: delegatorAddress, + validatorAddr: validatorAddress, + }); + return response; + }, + delegatorDelegations: async (delegatorAddress: string, paginationKey?: Uint8Array) => { + const response = await queryService.DelegatorDelegations({ + delegatorAddr: delegatorAddress, + pagination: createPagination(paginationKey), + }); + return response; + }, + delegatorUnbondingDelegations: async (delegatorAddress: string, paginationKey?: Uint8Array) => { + const response = await queryService.DelegatorUnbondingDelegations({ + delegatorAddr: delegatorAddress, + pagination: createPagination(paginationKey), + }); + return response; + }, + delegatorValidator: async (delegatorAddress: string, validatorAddress: string) => { + const response = await queryService.DelegatorValidator({ + delegatorAddr: delegatorAddress, + validatorAddr: validatorAddress, + }); + return response; + }, + delegatorValidators: async (delegatorAddress: string, paginationKey?: Uint8Array) => { + const response = await queryService.DelegatorValidators({ + delegatorAddr: delegatorAddress, + pagination: createPagination(paginationKey), + }); + return response; + }, + historicalInfo: async (height: number) => { + const response = await queryService.HistoricalInfo({ + height: Long.fromNumber(height, true), + }); + return response; + }, + params: async () => { + const response = await queryService.Params({}); + return response; + }, + pool: async () => { + const response = await queryService.Pool({}); + return response; + }, + redelegations: async ( + delegatorAddress: string, + sourceValidatorAddress: string, + destinationValidatorAddress: string, + paginationKey?: Uint8Array, + ) => { + const response = await queryService.Redelegations({ + delegatorAddr: delegatorAddress, + srcValidatorAddr: sourceValidatorAddress, + dstValidatorAddr: destinationValidatorAddress, + pagination: createPagination(paginationKey), + }); + return response; + }, + unbondingDelegation: async (delegatorAddress: string, validatorAddress: string) => { + const response = await queryService.UnbondingDelegation({ + delegatorAddr: delegatorAddress, + validatorAddr: validatorAddress, + }); + return response; + }, + validator: async (validatorAddress: string) => { + const response = await queryService.Validator({ validatorAddr: validatorAddress }); + return response; + }, + validatorDelegations: async (validatorAddress: string, paginationKey?: Uint8Array) => { + const response = await queryService.ValidatorDelegations({ + validatorAddr: validatorAddress, + pagination: createPagination(paginationKey), + }); + return response; + }, + validators: async (status: BondStatusString, paginationKey?: Uint8Array) => { + const response = await queryService.Validators({ + status: status, + pagination: createPagination(paginationKey), + }); + return response; + }, + validatorUnbondingDelegations: async (validatorAddress: string, paginationKey?: Uint8Array) => { + const response = await queryService.ValidatorUnbondingDelegations({ + validatorAddr: validatorAddress, + pagination: createPagination(paginationKey), + }); + return response; }, }, };