From 664affd493fce9aca8fb870e401af1e85724ce9c Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 31 Mar 2021 11:46:16 +0200 Subject: [PATCH 1/2] stargate: Rearrange distribution query extension --- .../stargate/src/queries/distribution.spec.ts | 24 +-- packages/stargate/src/queries/distribution.ts | 158 +++++++++--------- 2 files changed, 86 insertions(+), 96 deletions(-) diff --git a/packages/stargate/src/queries/distribution.spec.ts b/packages/stargate/src/queries/distribution.spec.ts index 880b14bb..39163582 100644 --- a/packages/stargate/src/queries/distribution.spec.ts +++ b/packages/stargate/src/queries/distribution.spec.ts @@ -51,7 +51,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.communityPool(); + const response = await client.distribution.communityPool(); expect(response.pool).toBeDefined(); expect(response.pool).not.toBeNull(); @@ -65,7 +65,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.delegationRewards( + const response = await client.distribution.delegationRewards( faucet.address0, validator.validatorAddress, ); @@ -81,7 +81,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.delegationTotalRewards(faucet.address0); + const response = await client.distribution.delegationTotalRewards(faucet.address0); expect(response.rewards).toBeDefined(); expect(response.rewards).not.toBeNull(); @@ -94,7 +94,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.delegatorValidators(faucet.address0); + const response = await client.distribution.delegatorValidators(faucet.address0); expect(response.validators).toBeDefined(); expect(response.validators).not.toBeNull(); @@ -107,7 +107,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.delegatorWithdrawAddress(faucet.address0); + const response = await client.distribution.delegatorWithdrawAddress(faucet.address0); expect(response.withdrawAddress).toBeDefined(); expect(response.withdrawAddress).not.toBeNull(); @@ -120,7 +120,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.params(); + const response = await client.distribution.params(); expect(response.params).toBeDefined(); expect(response.params).not.toBeNull(); @@ -133,7 +133,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.validatorCommission(validator.validatorAddress); + const response = await client.distribution.validatorCommission(validator.validatorAddress); expect(response.commission).toBeDefined(); expect(response.commission).not.toBeNull(); @@ -146,9 +146,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.validatorOutstandingRewards( - validator.validatorAddress, - ); + const response = await client.distribution.validatorOutstandingRewards(validator.validatorAddress); expect(response.rewards).toBeDefined(); expect(response.rewards).not.toBeNull(); @@ -161,11 +159,7 @@ describe("DistributionExtension", () => { pendingWithoutSimapp(); const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.unverified.validatorSlashes( - validator.validatorAddress, - 1, - 5, - ); + const response = await client.distribution.validatorSlashes(validator.validatorAddress, 1, 5); expect(response.slashes).toBeDefined(); expect(response.slashes).not.toBeNull(); diff --git a/packages/stargate/src/queries/distribution.ts b/packages/stargate/src/queries/distribution.ts index 574a06b4..5597b5e3 100644 --- a/packages/stargate/src/queries/distribution.ts +++ b/packages/stargate/src/queries/distribution.ts @@ -18,27 +18,25 @@ import { createPagination, createProtobufRpcClient } from "./utils"; export interface DistributionExtension { readonly distribution: { - unverified: { - communityPool: () => Promise; - delegationRewards: ( - delegatorAddress: string, - validatorAddress: string, - ) => Promise; - delegationTotalRewards: (delegatorAddress: string) => Promise; - delegatorValidators: (delegatorAddress: string) => Promise; - delegatorWithdrawAddress: (delegatorAddress: string) => Promise; - params: () => Promise; - validatorCommission: (validatorAddress: string) => Promise; - validatorOutstandingRewards: ( - validatorAddress: string, - ) => Promise; - validatorSlashes: ( - validatorAddress: string, - startingHeight: number, - endingHeight: number, - paginationKey?: Uint8Array, - ) => Promise; - }; + communityPool: () => Promise; + delegationRewards: ( + delegatorAddress: string, + validatorAddress: string, + ) => Promise; + delegationTotalRewards: (delegatorAddress: string) => Promise; + delegatorValidators: (delegatorAddress: string) => Promise; + delegatorWithdrawAddress: (delegatorAddress: string) => Promise; + params: () => Promise; + validatorCommission: (validatorAddress: string) => Promise; + validatorOutstandingRewards: ( + validatorAddress: string, + ) => Promise; + validatorSlashes: ( + validatorAddress: string, + startingHeight: number, + endingHeight: number, + paginationKey?: Uint8Array, + ) => Promise; }; } @@ -50,66 +48,64 @@ export function setupDistributionExtension(base: QueryClient): DistributionExten return { distribution: { - unverified: { - communityPool: async () => { - const response = await queryService.CommunityPool({}); - return response; - }, - delegationRewards: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.DelegationRewards({ - delegatorAddress: delegatorAddress, - validatorAddress: validatorAddress, - }); - return response; - }, - delegationTotalRewards: async (delegatorAddress: string) => { - const response = await queryService.DelegationTotalRewards({ - delegatorAddress: delegatorAddress, - }); - return response; - }, - delegatorValidators: async (delegatorAddress: string) => { - const response = await queryService.DelegatorValidators({ - delegatorAddress: delegatorAddress, - }); - return response; - }, - delegatorWithdrawAddress: async (delegatorAddress: string) => { - const response = await queryService.DelegatorWithdrawAddress({ - delegatorAddress: delegatorAddress, - }); - return response; - }, - params: async () => { - const response = await queryService.Params({}); - return response; - }, - validatorCommission: async (validatorAddress: string) => { - const response = await queryService.ValidatorCommission({ - validatorAddress: validatorAddress, - }); - return response; - }, - validatorOutstandingRewards: async (validatorAddress: string) => { - const response = await queryService.ValidatorOutstandingRewards({ - validatorAddress: validatorAddress, - }); - return response; - }, - validatorSlashes: async ( - validatorAddress: string, - startingHeight: number, - endingHeight: number, - paginationKey?: Uint8Array, - ) => { - const response = await queryService.ValidatorSlashes({ - validatorAddress: validatorAddress, - startingHeight: Long.fromNumber(startingHeight, true), - endingHeight: Long.fromNumber(endingHeight, true), - pagination: createPagination(paginationKey), - }); - return response; - }, + communityPool: async () => { + const response = await queryService.CommunityPool({}); + return response; + }, + delegationRewards: async (delegatorAddress: string, validatorAddress: string) => { + const response = await queryService.DelegationRewards({ + delegatorAddress: delegatorAddress, + validatorAddress: validatorAddress, + }); + return response; + }, + delegationTotalRewards: async (delegatorAddress: string) => { + const response = await queryService.DelegationTotalRewards({ + delegatorAddress: delegatorAddress, + }); + return response; + }, + delegatorValidators: async (delegatorAddress: string) => { + const response = await queryService.DelegatorValidators({ + delegatorAddress: delegatorAddress, + }); + return response; + }, + delegatorWithdrawAddress: async (delegatorAddress: string) => { + const response = await queryService.DelegatorWithdrawAddress({ + delegatorAddress: delegatorAddress, + }); + return response; + }, + params: async () => { + const response = await queryService.Params({}); + return response; + }, + validatorCommission: async (validatorAddress: string) => { + const response = await queryService.ValidatorCommission({ + validatorAddress: validatorAddress, + }); + return response; + }, + validatorOutstandingRewards: async (validatorAddress: string) => { + const response = await queryService.ValidatorOutstandingRewards({ + validatorAddress: validatorAddress, + }); + return response; + }, + validatorSlashes: async ( + validatorAddress: string, + startingHeight: number, + endingHeight: number, + paginationKey?: Uint8Array, + ) => { + const response = await queryService.ValidatorSlashes({ + validatorAddress: validatorAddress, + startingHeight: Long.fromNumber(startingHeight, true), + endingHeight: Long.fromNumber(endingHeight, true), + pagination: createPagination(paginationKey), + }); + return response; }, }, }; From ea4e78069073d7fe11bac0624b2b4b481903e558 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 31 Mar 2021 12:00:18 +0200 Subject: [PATCH 2/2] stargate: Simplify distribution extension tests --- .../stargate/src/queries/distribution.spec.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/stargate/src/queries/distribution.spec.ts b/packages/stargate/src/queries/distribution.spec.ts index 39163582..05b300c3 100644 --- a/packages/stargate/src/queries/distribution.spec.ts +++ b/packages/stargate/src/queries/distribution.spec.ts @@ -45,18 +45,16 @@ describe("DistributionExtension", () => { } }); - describe("unverified", () => { - describe("communityPool", () => { - it("works", async () => { - pendingWithoutSimapp(); - const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); + describe("communityPool", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithDistribution(simapp.tendermintUrl); - const response = await client.distribution.communityPool(); - expect(response.pool).toBeDefined(); - expect(response.pool).not.toBeNull(); + const response = await client.distribution.communityPool(); + expect(response.pool).toBeDefined(); + expect(response.pool).not.toBeNull(); - tmClient.disconnect(); - }); + tmClient.disconnect(); }); });