sdk38: Add remaining gov endpoints to lcd
This commit is contained in:
parent
09f9b1fd5f
commit
f5aab614a6
@ -1,8 +1,15 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
import { nonNegativeIntegerMatcher, pendingWithoutWasmd, wasmd } from "../testutils.spec";
|
||||
import {
|
||||
dateTimeStampMatcher,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutWasmd,
|
||||
wasmd,
|
||||
} from "../testutils.spec";
|
||||
import { GovExtension, GovParametersType, setupGovExtension } from "./gov";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
|
||||
const governorAddress = "cosmos14qemq0vw6y3gc3u3e0aty2e764u4gs5le3hada";
|
||||
|
||||
function makeGovClient(apiUrl: string): LcdClient & GovExtension {
|
||||
return LcdClient.withExtensions({ apiUrl }, setupGovExtension);
|
||||
}
|
||||
@ -59,7 +66,160 @@ describe("GovExtension", () => {
|
||||
const response = await client.gov.proposals();
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [],
|
||||
result: [
|
||||
{
|
||||
content: {
|
||||
type: "cosmos-sdk/TextProposal",
|
||||
value: {
|
||||
title: "Test Proposal",
|
||||
description: "This proposal proposes to test whether this proposal passes",
|
||||
},
|
||||
},
|
||||
id: "1",
|
||||
proposal_status: "VotingPeriod",
|
||||
final_tally_result: Object({ yes: "0", abstain: "0", no: "0", no_with_veto: "0" }),
|
||||
submit_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
deposit_end_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
total_deposit: [{ denom: "ustake", amount: "25000000" }],
|
||||
voting_start_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
voting_end_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("proposal", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.proposal(proposalId);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
content: {
|
||||
type: "cosmos-sdk/TextProposal",
|
||||
value: {
|
||||
title: "Test Proposal",
|
||||
description: "This proposal proposes to test whether this proposal passes",
|
||||
},
|
||||
},
|
||||
id: proposalId,
|
||||
proposal_status: "VotingPeriod",
|
||||
final_tally_result: Object({ yes: "0", abstain: "0", no: "0", no_with_veto: "0" }),
|
||||
submit_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
deposit_end_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
total_deposit: [{ denom: "ustake", amount: "25000000" }],
|
||||
voting_start_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
voting_end_time: jasmine.stringMatching(dateTimeStampMatcher),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("proposer", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.proposer(proposalId);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
proposal_id: proposalId,
|
||||
proposer: governorAddress,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("deposits", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.deposits(proposalId);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
proposal_id: proposalId,
|
||||
depositor: governorAddress,
|
||||
amount: [{ denom: "ustake", amount: "25000000" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("deposit", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.deposit(proposalId, governorAddress);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
proposal_id: proposalId,
|
||||
depositor: governorAddress,
|
||||
amount: [{ denom: "ustake", amount: "25000000" }],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("tally", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.tally(proposalId);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
yes: "0",
|
||||
abstain: "0",
|
||||
no: "0",
|
||||
no_with_veto: "0",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("votes", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.votes(proposalId);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
proposal_id: proposalId,
|
||||
voter: governorAddress,
|
||||
option: "Yes",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("vote", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeGovClient(wasmd.endpoint);
|
||||
const proposalId = "1";
|
||||
const response = await client.gov.vote(proposalId, governorAddress);
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: {
|
||||
voter: governorAddress,
|
||||
proposal_id: proposalId,
|
||||
option: "Yes",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -36,69 +36,97 @@ export type GovParametersByTypeResponse =
|
||||
| GovParametersTallyingResponse
|
||||
| GovParametersVotingResponse;
|
||||
|
||||
export interface TallyResult {
|
||||
export interface Tally {
|
||||
readonly yes: string;
|
||||
readonly abstain: string;
|
||||
readonly no: string;
|
||||
readonly no_with_veto: string;
|
||||
}
|
||||
|
||||
export interface TextProposal {
|
||||
readonly proposal_id: number;
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly proposal_type: string;
|
||||
export interface Proposal {
|
||||
readonly id: string;
|
||||
readonly proposal_status: string;
|
||||
readonly final_tally_result: TallyResult;
|
||||
readonly final_tally_result: Tally;
|
||||
readonly submit_time: string;
|
||||
readonly total_deposit: readonly Coin[];
|
||||
readonly deposit_end_time: string;
|
||||
readonly voting_start_time: string;
|
||||
readonly voting_end_time: string;
|
||||
readonly content: {
|
||||
readonly type: string;
|
||||
readonly value: {
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface GovProposalsResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly TextProposal[];
|
||||
readonly result: readonly Proposal[];
|
||||
}
|
||||
|
||||
export interface GovProposalsByIdResponse {
|
||||
export interface GovProposalResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Proposal;
|
||||
}
|
||||
|
||||
export interface GovProposerResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: {
|
||||
readonly proposal_id: string;
|
||||
readonly proposer: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Deposit {
|
||||
readonly amount: readonly Coin[];
|
||||
readonly proposal_id: string;
|
||||
readonly depositor: string;
|
||||
}
|
||||
|
||||
export interface GovDepositsResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: readonly Deposit[];
|
||||
}
|
||||
|
||||
export interface GovDepositsByDepositorResponse {
|
||||
export interface GovDepositResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Deposit;
|
||||
}
|
||||
|
||||
export interface GovTallyResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Tally;
|
||||
}
|
||||
|
||||
export interface Vote {
|
||||
readonly voter: string;
|
||||
readonly proposal_id: string;
|
||||
readonly option: string;
|
||||
}
|
||||
|
||||
export interface GovVotesResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: readonly Vote[];
|
||||
}
|
||||
|
||||
export interface GovVotesByVoterResponse {
|
||||
export interface GovVoteResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Vote;
|
||||
}
|
||||
|
||||
export interface GovExtension {
|
||||
readonly gov: {
|
||||
readonly parametersByType: (parametersType: GovParametersType) => Promise<GovParametersByTypeResponse>;
|
||||
readonly proposals: () => Promise<GovProposalsResponse>;
|
||||
readonly proposal: (proposalId: string) => Promise<GovProposalResponse>;
|
||||
readonly proposer: (proposalId: string) => Promise<GovProposerResponse>;
|
||||
readonly deposits: (proposalId: string) => Promise<GovDepositsResponse>;
|
||||
readonly deposit: (proposalId: string, depositorAddress: string) => Promise<GovDepositResponse>;
|
||||
readonly tally: (proposalId: string) => Promise<GovTallyResponse>;
|
||||
readonly votes: (proposalId: string) => Promise<GovVotesResponse>;
|
||||
readonly vote: (proposalId: string, voterAddress: string) => Promise<GovVoteResponse>;
|
||||
};
|
||||
}
|
||||
|
||||
@ -108,6 +136,15 @@ export function setupGovExtension(base: LcdClient): GovExtension {
|
||||
parametersByType: async (parametersType: GovParametersType) =>
|
||||
base.get(`/gov/parameters/${parametersType}`),
|
||||
proposals: async () => base.get("/gov/proposals"),
|
||||
proposal: async (proposalId: string) => base.get(`/gov/proposals/${proposalId}`),
|
||||
proposer: async (proposalId: string) => base.get(`/gov/proposals/${proposalId}/proposer`),
|
||||
deposits: async (proposalId: string) => base.get(`/gov/proposals/${proposalId}/deposits`),
|
||||
deposit: async (proposalId: string, depositorAddress: string) =>
|
||||
base.get(`/gov/proposals/${proposalId}/deposits/${depositorAddress}`),
|
||||
tally: async (proposalId: string) => base.get(`/gov/proposals/${proposalId}/tally`),
|
||||
votes: async (proposalId: string) => base.get(`/gov/proposals/${proposalId}/votes`),
|
||||
vote: async (proposalId: string, voterAddress: string) =>
|
||||
base.get(`/gov/proposals/${proposalId}/votes/${voterAddress}`),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
62
packages/sdk38/types/lcdapi/gov.d.ts
vendored
62
packages/sdk38/types/lcdapi/gov.d.ts
vendored
@ -30,59 +30,85 @@ export declare type GovParametersByTypeResponse =
|
||||
| GovParametersDepositResponse
|
||||
| GovParametersTallyingResponse
|
||||
| GovParametersVotingResponse;
|
||||
export interface TallyResult {
|
||||
export interface Tally {
|
||||
readonly yes: string;
|
||||
readonly abstain: string;
|
||||
readonly no: string;
|
||||
readonly no_with_veto: string;
|
||||
}
|
||||
export interface TextProposal {
|
||||
readonly proposal_id: number;
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly proposal_type: string;
|
||||
export interface Proposal {
|
||||
readonly id: string;
|
||||
readonly proposal_status: string;
|
||||
readonly final_tally_result: TallyResult;
|
||||
readonly final_tally_result: Tally;
|
||||
readonly submit_time: string;
|
||||
readonly total_deposit: readonly Coin[];
|
||||
readonly deposit_end_time: string;
|
||||
readonly voting_start_time: string;
|
||||
readonly voting_end_time: string;
|
||||
readonly content: {
|
||||
readonly type: string;
|
||||
readonly value: {
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
export interface GovProposalsResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly TextProposal[];
|
||||
readonly result: readonly Proposal[];
|
||||
}
|
||||
export interface GovProposalsByIdResponse {
|
||||
export interface GovProposalResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Proposal;
|
||||
}
|
||||
export interface GovProposerResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: {
|
||||
readonly proposal_id: string;
|
||||
readonly proposer: string;
|
||||
};
|
||||
}
|
||||
export interface Deposit {
|
||||
readonly amount: readonly Coin[];
|
||||
readonly proposal_id: string;
|
||||
readonly depositor: string;
|
||||
}
|
||||
export interface GovDepositsResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: readonly Deposit[];
|
||||
}
|
||||
export interface GovDepositsByDepositorResponse {
|
||||
export interface GovDepositResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Deposit;
|
||||
}
|
||||
export interface GovTallyResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Tally;
|
||||
}
|
||||
export interface Vote {
|
||||
readonly voter: string;
|
||||
readonly proposal_id: string;
|
||||
readonly option: string;
|
||||
}
|
||||
export interface GovVotesResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: readonly Vote[];
|
||||
}
|
||||
export interface GovVotesByVoterResponse {
|
||||
export interface GovVoteResponse {
|
||||
readonly height: string;
|
||||
readonly result: {};
|
||||
readonly result: Vote;
|
||||
}
|
||||
export interface GovExtension {
|
||||
readonly gov: {
|
||||
readonly parametersByType: (parametersType: GovParametersType) => Promise<GovParametersByTypeResponse>;
|
||||
readonly proposals: () => Promise<GovProposalsResponse>;
|
||||
readonly proposal: (proposalId: string) => Promise<GovProposalResponse>;
|
||||
readonly proposer: (proposalId: string) => Promise<GovProposerResponse>;
|
||||
readonly deposits: (proposalId: string) => Promise<GovDepositsResponse>;
|
||||
readonly deposit: (proposalId: string, depositorAddress: string) => Promise<GovDepositResponse>;
|
||||
readonly tally: (proposalId: string) => Promise<GovTallyResponse>;
|
||||
readonly votes: (proposalId: string) => Promise<GovVotesResponse>;
|
||||
readonly vote: (proposalId: string, voterAddress: string) => Promise<GovVoteResponse>;
|
||||
};
|
||||
}
|
||||
export declare function setupGovExtension(base: LcdClient): GovExtension;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user