From acc3f1e53df3ea8972f2ba1b48c9cfded1f2c3a8 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 18 Nov 2021 15:21:01 +0100 Subject: [PATCH] Add SDK 0.44 vote options to tests --- packages/stargate/src/queries/gov.spec.ts | 93 ++++++++++++++++++----- 1 file changed, 72 insertions(+), 21 deletions(-) diff --git a/packages/stargate/src/queries/gov.spec.ts b/packages/stargate/src/queries/gov.spec.ts index ad8cf153..27a56132 100644 --- a/packages/stargate/src/queries/gov.spec.ts +++ b/packages/stargate/src/queries/gov.spec.ts @@ -3,7 +3,13 @@ import { toAscii } from "@cosmjs/encoding"; import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; import { assert, sleep } from "@cosmjs/utils"; -import { ProposalStatus, TextProposal, Vote, VoteOption } from "cosmjs-types/cosmos/gov/v1beta1/gov"; +import { + ProposalStatus, + TextProposal, + Vote, + VoteOption, + WeightedVoteOption, +} from "cosmjs-types/cosmos/gov/v1beta1/gov"; import { Any } from "cosmjs-types/google/protobuf/any"; import Long from "long"; @@ -20,6 +26,7 @@ import { nonNegativeIntegerMatcher, pendingWithoutSimapp, simapp, + simapp42Enabled, simappEnabled, validator, } from "../testutils.spec"; @@ -326,19 +333,47 @@ describe("GovExtension", () => { const [client, tmClient] = await makeClientWithGov(simapp.tendermintUrl); const response = await client.gov.votes(proposalId); - expect(response.votes).toEqual([ - // why is vote 2 first? - Vote.fromPartial({ - proposalId: longify(proposalId), - voter: voter2Address, - option: VoteOption.VOTE_OPTION_NO_WITH_VETO, - }), - Vote.fromPartial({ - proposalId: longify(proposalId), - voter: voter1Address, - option: VoteOption.VOTE_OPTION_YES, - }), - ]); + if (simapp42Enabled()) { + expect(response.votes).toEqual([ + // why is vote 2 first? + Vote.fromPartial({ + proposalId: longify(proposalId), + voter: voter2Address, + option: VoteOption.VOTE_OPTION_NO_WITH_VETO, + }), + Vote.fromPartial({ + proposalId: longify(proposalId), + voter: voter1Address, + option: VoteOption.VOTE_OPTION_YES, + }), + ]); + } else { + expect(response.votes).toEqual([ + // why is vote 2 first? + Vote.fromPartial({ + proposalId: longify(proposalId), + voter: voter2Address, + option: VoteOption.VOTE_OPTION_NO_WITH_VETO, + options: [ + WeightedVoteOption.fromPartial({ + option: VoteOption.VOTE_OPTION_NO_WITH_VETO, + weight: "1000000000000000000", + }), + ], + }), + Vote.fromPartial({ + proposalId: longify(proposalId), + voter: voter1Address, + option: VoteOption.VOTE_OPTION_YES, + options: [ + WeightedVoteOption.fromPartial({ + option: VoteOption.VOTE_OPTION_YES, + weight: "1000000000000000000", + }), + ], + }), + ]); + } tmClient.disconnect(); }); @@ -351,13 +386,29 @@ describe("GovExtension", () => { const [client, tmClient] = await makeClientWithGov(simapp.tendermintUrl); const response = await client.gov.vote(proposalId, voter1Address); - expect(response.vote).toEqual( - Vote.fromPartial({ - voter: voter1Address, - proposalId: longify(proposalId), - option: VoteOption.VOTE_OPTION_YES, - }), - ); + if (simapp42Enabled()) { + expect(response.vote).toEqual( + Vote.fromPartial({ + voter: voter1Address, + proposalId: longify(proposalId), + option: VoteOption.VOTE_OPTION_YES, + }), + ); + } else { + expect(response.vote).toEqual( + Vote.fromPartial({ + voter: voter1Address, + proposalId: longify(proposalId), + option: VoteOption.VOTE_OPTION_YES, + options: [ + WeightedVoteOption.fromPartial({ + option: VoteOption.VOTE_OPTION_YES, + weight: "1000000000000000000", + }), + ], + }), + ); + } tmClient.disconnect(); });