diff --git a/integration-tests/src/modules/gov.test.ts b/integration-tests/src/modules/gov.test.ts index 68a2f6b9..e036f985 100644 --- a/integration-tests/src/modules/gov.test.ts +++ b/integration-tests/src/modules/gov.test.ts @@ -1,8 +1,8 @@ import { getMnemonics } from "../helpers/mnemonics"; import { getLCDClient } from "../helpers/lcd.connection"; -import { Coins, MsgVote, Fee, MsgSubmitProposal } from "@terra-money/feather.js"; +import { Coins, MsgVote, Fee, MsgSubmitProposal, Proposal, Int } from "@terra-money/feather.js"; import { blockInclusion, votingPeriod } from "../helpers/const"; -import { VoteOption } from "@terra-money/terra.proto/cosmos/gov/v1beta1/gov"; +import { ProposalStatus, VoteOption } from "@terra-money/terra.proto/cosmos/gov/v1beta1/gov"; describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/v0.3.x) ", () => { // Prepare environment clients, accounts and wallets @@ -10,12 +10,12 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/ const accounts = getMnemonics(); const val2Wallet = LCD.chain2.wallet(accounts.val2); const val2WalletAddress = val2Wallet.key.accAddress("terra"); + let proposalId = 0; // Will be populated on "Must submit a proposal on chain" test('Must contain the expected module params', async () => { try { - // Query Alliance module params + // Query All gov module params const moduleParams = await LCD.chain2.gov.params("test-2"); - // Validate that the params were set correctly on genesis expect(moduleParams) .toStrictEqual({ @@ -36,6 +36,111 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/ "voting_params": { "voting_period": "4s", }, + "params": { + "burn_proposal_deposit_prevote": false, + "burn_vote_quorum": false, + "burn_vote_veto": true, + "max_deposit_period": "172800s", + "min_deposit": [{ + "amount": "10000000", + "denom": "uluna", + }], + "min_initial_deposit_ratio": "0.000000000000000000", + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000", + "voting_period": "4s", + }, + }); + + // Query tally module params + const tallyParams = await LCD.chain2.gov.tallyParams("test-2"); + // Validate that the params were set correctly on genesis + expect(tallyParams) + .toStrictEqual({ + "deposit_params": null, + "voting_params": null, + "tally_params": { + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000", + }, + "params": { + "burn_proposal_deposit_prevote": false, + "burn_vote_quorum": false, + "burn_vote_veto": true, + "max_deposit_period": "172800s", + "min_deposit": [{ + "amount": "10000000", + "denom": "uluna", + }], + "min_initial_deposit_ratio": "0.000000000000000000", + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000", + "voting_period": "4s", + }, + }); + + // Query voting gov module params + const votingParams = await LCD.chain2.gov.votingParams("test-2"); + // Validate that the params were set correctly on genesis + expect(votingParams) + .toStrictEqual({ + "deposit_params": null, + "tally_params": null, + "voting_params": { + "voting_period": "4s", + }, + "params": { + "burn_proposal_deposit_prevote": false, + "burn_vote_quorum": false, + "burn_vote_veto": true, + "max_deposit_period": "172800s", + "min_deposit": [{ + "amount": "10000000", + "denom": "uluna", + }], + "min_initial_deposit_ratio": "0.000000000000000000", + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000", + "voting_period": "4s", + }, + }); + + + // Query deposit gov module params + const depositParams = await LCD.chain2.gov.depositParams("test-2"); + // Validate that the params were set correctly on genesis + expect(depositParams) + .toStrictEqual({ + "voting_params": null, + "tally_params": null, + "deposit_params": { + "max_deposit_period": "172800s", + "min_deposit": [ + { + "amount": "10000000", + "denom": "uluna", + }, + ], + }, + "params": { + "burn_proposal_deposit_prevote": false, + "burn_vote_quorum": false, + "burn_vote_veto": true, + "max_deposit_period": "172800s", + "min_deposit": [{ + "amount": "10000000", + "denom": "uluna", + }], + "min_initial_deposit_ratio": "0.000000000000000000", + "quorum": "0.334000000000000000", + "threshold": "0.500000000000000000", + "veto_threshold": "0.334000000000000000", + "voting_period": "4s", + }, }); } catch (e) { @@ -44,7 +149,7 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/ } }); - test('Must submit a proposal on chain', async () => { + test('Must submit an empty proposal on chain', async () => { try { const msgProposal = new MsgSubmitProposal( [], @@ -67,7 +172,7 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/ expect(txResult.code).toBe(0); // Get the proposal id and validate exists - let proposalId = Number(txResult.logs[0].eventsByType.submit_proposal.proposal_id[0]); + proposalId = Number(txResult.logs[0].eventsByType.submit_proposal.proposal_id[0]); expect(proposalId) // Vote for the proposal @@ -92,5 +197,42 @@ describe("Alliance Module (https://github.com/terra-money/alliance/tree/release/ // Query the alliance and check if it exists const res = await LCD.chain2.gov.proposals("test-2"); expect(res).toBeDefined(); + }); + + describe("After submitting the proposal on chain", () => { + test('Must query the proposals', async () => { + // Query the alliance and check if it exists + const res = await LCD.chain2.gov.proposals("test-2"); + let proposal; + for (const prop of res.proposals) { + if (prop.id === proposalId){ + proposal = prop; + } + } + expect(proposal).toBeDefined(); + proposal = proposal as Proposal; + expect(proposal.id).toBe(proposalId); + expect(proposal.proposer).toBe(val2WalletAddress); + expect(proposal.metadata).toBe("metadata"); + expect(proposal.title).toBe("title"); + expect(proposal.summary).toBe("summary"); + expect(proposal.messages.length).toBe(0); + expect(proposal.total_deposit).toStrictEqual(Coins.fromString("1000000000uluna")); + expect(proposal.submit_time.getTime()).toBeLessThan(Date.now()); + expect(proposal.voting_start_time?.getTime()).toBeLessThan(Date.now()); + expect(proposal.deposit_end_time?.getTime()).toBeGreaterThan(Date.now()); + expect(proposal.voting_end_time?.getTime()).toBeLessThan(Date.now()); + expect(proposal.status).toBe(ProposalStatus.PROPOSAL_STATUS_PASSED) + }); + + test('Must query the tally', async () => { + // Query the alliance and check if it exists + const res = await LCD.chain2.gov.tally("test-2", proposalId); + expect(res).toBeDefined(); + expect(res.yes_count).toStrictEqual(new Int(27000000000)); + expect(res.abstain_count).toStrictEqual(new Int(0)); + expect(res.no_count).toStrictEqual(new Int(0)); + expect(res.no_with_veto_count).toStrictEqual(new Int(0)); + }); }) }); \ No newline at end of file