Skip to content

Commit

Permalink
test: gov module increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 20, 2023
1 parent 977cdeb commit 5d16521
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 14 deletions.
14 changes: 7 additions & 7 deletions integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@terra-money/feather.js": "^1.2.1",
"@terra-money/feather.js": "^2.0.0-beta.1",
"@terra-money/terra.proto": "^4.0.1",
"moment": "^2.29.4"
}
Expand Down
154 changes: 148 additions & 6 deletions integration-tests/src/modules/gov.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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
const LCD = getLCDClient();
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({
Expand All @@ -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) {
Expand All @@ -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(
[],
Expand All @@ -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
Expand All @@ -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));
});
})
});

0 comments on commit 5d16521

Please sign in to comment.