Merge pull request #746 from cosmos/742-staking-extension

Rearrange staking query extension
This commit is contained in:
Will Clark 2021-03-31 13:46:28 +01:00 committed by GitHub
commit d4fa15befe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 262 additions and 283 deletions

View File

@ -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

View File

@ -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();
});
});
});

View File

@ -26,48 +26,46 @@ export type BondStatusString = Exclude<keyof typeof BondStatus, "BOND_STATUS_UNS
export interface StakingExtension {
readonly staking: {
readonly unverified: {
delegation: (delegatorAddress: string, validatorAddress: string) => Promise<QueryDelegationResponse>;
delegatorDelegations: (
delegatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryDelegatorDelegationsResponse>;
delegatorUnbondingDelegations: (
delegatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryDelegatorUnbondingDelegationsResponse>;
delegatorValidator: (
delegatorAddress: string,
validatorAddress: string,
) => Promise<QueryDelegatorValidatorResponse>;
delegatorValidators: (
delegatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryDelegatorValidatorsResponse>;
historicalInfo: (height: number) => Promise<QueryHistoricalInfoResponse>;
params: () => Promise<QueryParamsResponse>;
pool: () => Promise<QueryPoolResponse>;
redelegations: (
delegatorAddress: string,
sourceValidatorAddress: string,
destinationValidatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryRedelegationsResponse>;
unbondingDelegation: (
delegatorAddress: string,
validatorAddress: string,
) => Promise<QueryUnbondingDelegationResponse>;
validator: (validatorAddress: string) => Promise<QueryValidatorResponse>;
validatorDelegations: (
validatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryValidatorDelegationsResponse>;
validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise<QueryValidatorsResponse>;
validatorUnbondingDelegations: (
validatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryValidatorUnbondingDelegationsResponse>;
};
delegation: (delegatorAddress: string, validatorAddress: string) => Promise<QueryDelegationResponse>;
delegatorDelegations: (
delegatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryDelegatorDelegationsResponse>;
delegatorUnbondingDelegations: (
delegatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryDelegatorUnbondingDelegationsResponse>;
delegatorValidator: (
delegatorAddress: string,
validatorAddress: string,
) => Promise<QueryDelegatorValidatorResponse>;
delegatorValidators: (
delegatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryDelegatorValidatorsResponse>;
historicalInfo: (height: number) => Promise<QueryHistoricalInfoResponse>;
params: () => Promise<QueryParamsResponse>;
pool: () => Promise<QueryPoolResponse>;
redelegations: (
delegatorAddress: string,
sourceValidatorAddress: string,
destinationValidatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryRedelegationsResponse>;
unbondingDelegation: (
delegatorAddress: string,
validatorAddress: string,
) => Promise<QueryUnbondingDelegationResponse>;
validator: (validatorAddress: string) => Promise<QueryValidatorResponse>;
validatorDelegations: (
validatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryValidatorDelegationsResponse>;
validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise<QueryValidatorsResponse>;
validatorUnbondingDelegations: (
validatorAddress: string,
paginationKey?: Uint8Array,
) => Promise<QueryValidatorUnbondingDelegationsResponse>;
};
}
@ -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;
},
},
};