Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fedekunze/1568-mocked-submit-proposal #1571

Merged
merged 4 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* [\1552](https://github.com/cosmos/voyager/issues/1522) Deposit on proposals through modal @fedekunze
* [\1548](https://github.com/cosmos/voyager/issues/1548) Add mocked deposit for testing @fedekunze
* [\1116](https://github.com/cosmos/voyager/issues/1116) Elaborate a bit about the release process. @NodeGuy
* [\1568](https://github.com/cosmos/voyager/issues/1568) Add mocked submit deposit for testing @fedekunze

### Changed

Expand Down
4 changes: 2 additions & 2 deletions app/src/renderer/components/governance/LiProposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export default {
message: `This proposal has been rejected and voting is closed`,
color: `red`
}
if (this.proposal.proposal_status === `Pending`)
if (this.proposal.proposal_status === `DepositPeriod`)
return {
button: `deposit`,
message: `Deposits are open for this proposal`,
color: `yellow`
}
if (this.proposal.proposal_status === `Active`)
if (this.proposal.proposal_status === `VotingPeriod`)
return {
button: `vote`,
message: `Voting for this proposal is open`,
Expand Down
95 changes: 81 additions & 14 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ let state = {
{
proposal_id: `2`,
proposal_type: `Text`,
title: `Active proposal`,
title: `VotingPeriod proposal`,
description: `custom text proposal description`,
initial_deposit: [
{
Expand All @@ -367,7 +367,7 @@ let state = {
],
submit_block: `10`,
voting_start_block: `10`,
proposal_status: `Active`,
proposal_status: `VotingPeriod`,
tally_result: {
yes: `0`,
no: `0`,
Expand All @@ -394,7 +394,7 @@ let state = {
],
submit_block: `10`,
voting_start_block: `-1`,
proposal_status: `Pending`,
proposal_status: `DepositPeriod`,
tally_result: {
yes: `0`,
no: `0`,
Expand Down Expand Up @@ -903,10 +903,74 @@ module.exports = {
async getProposals() {
return state.proposals || []
},
async submitProposal({
base_req,
title,
description,
proposal_type,
proposer,
initial_deposit
}) {
let results = []
// get new proposal id
let proposal_id = `1`
let proposalsLen = state.proposals.length
if (state.proposals && proposalsLen > 0) {
proposal_id = String(
parseInt(state.proposals[proposalsLen - 1].proposal_id) + 1
)
}

if (
proposal_type !== `Text` &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pattern I use sometimes in those cases:

[`Text`, `ParameterChange`, `SoftwareUpgrade`].indexOf(proposal_type) === -1

proposal_type !== `ParameterChange` &&
proposal_type !== `SoftwareUpgrade`
) {
results.push(txResult(2, `${proposal_type} is not a valid proposal type`))
return results
}

let tally_result = {
yes: `0`,
no: `0`,
no_with_veto: `0`,
abstain: `0`
}
let submit_time = Date.now()
let deposit_end_time = moment(submit_time)
.add(86400000, `ms`)
.toDate()

let proposal = {
proposal_id,
title,
description,
proposal_type,
proposal_status: `DepositPeriod`,
tally_result,
submit_time,
deposit_end_time,
voting_start_time: undefined,
voting_end_time: undefined,
total_deposit: []
}

// we add the proposal to the state to make it available for the submitProposalDeposit function
state.proposals.push(proposal)
results = await this.submitProposalDeposit({
base_req,
proposal_id,
depositer: proposer,
amount: initial_deposit
})
// remove proposal from state if it fails
if (results[0].check_tx.code !== 0) {
state.proposals.pop()
}
return results
},
async getProposal(proposalId) {
return state.proposals.find(
proposal => proposal.proposal_id === String(proposalId)
)
return state.proposals.find(proposal => proposal.proposal_id === proposalId)
},
async getProposalDeposits(proposalId) {
return state.deposits[proposalId] || []
Expand Down Expand Up @@ -947,8 +1011,8 @@ module.exports = {
results.push(txResult(3, `Nonexistent proposal`))
return results
} else if (
proposal.proposal_status != `Pending` &&
proposal.proposal_status != `Active`
proposal.proposal_status != `DepositPeriod` &&
proposal.proposal_status != `VotingPeriod`
) {
results.push(txResult(3, `Proposal #${proposal_id} already finished`))
return results
Expand Down Expand Up @@ -994,12 +1058,15 @@ module.exports = {

// ============= USER'S DEPOSITS =============
// check if there's an existing deposit by the depositer
let prevDeposit = state.deposits[proposal_id].find(
deposit => deposit.depositer === depositer
)
let prevDeposit =
state.deposits[proposal_id] &&
state.deposits[proposal_id].find(
deposit => deposit.depositer === depositer
)

if (!prevDeposit) {
// if no previous deposit by the depositer, we add it to the existing deposits
if (!state.deposits[proposal_id]) state.deposits[proposal_id] = []
state.deposits[proposal_id].push(submittedDeposit)
break // break since no need to iterate over other coins
} else {
Expand All @@ -1021,14 +1088,14 @@ module.exports = {
incrementSequence(fromAccount)

// check if the propoposal is now active
if (proposal.proposal_status === `Pending`) {
if (proposal.proposal_status === `DepositPeriod`) {
// TODO: get min deposit denom from gov params instead of stake params
let depositCoinAmt = proposal.total_deposit.find(coin => {
return coin.denom === `steak`
}).amount
// TODO: get min deposit amount from gov params
if (parseInt(depositCoinAmt) >= 10) {
proposal.proposal_status = `Active`
proposal.proposal_status = `VotingPeriod`
// TODO: get voting time from gov params
proposal.voting_start_block = Date.now()
proposal.voting_end_block = moment(proposal.voting_start_block)
Expand Down Expand Up @@ -1075,7 +1142,7 @@ module.exports = {
if (!proposal) {
results.push(txResult(3, `Nonexistent proposal`))
return results
} else if (proposal.proposal_status != `Active`) {
} else if (proposal.proposal_status != `VotingPeriod`) {
results.push(txResult(3, `Proposal #${proposal_id} is inactive`))
return results
} else if (
Expand Down
6 changes: 3 additions & 3 deletions test/unit/specs/components/governance/LiProposal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe(`LiProposal`, () => {
})

it(`should return status info for active proposals`, () => {
proposal.proposal_status = `Active`
proposal.proposal_status = `VotingPeriod`
let { wrapper } = mount(LiProposal, {
propsData: {
proposal
Expand All @@ -67,8 +67,8 @@ describe(`LiProposal`, () => {
})
})

it(`should return status info for pending proposals`, () => {
proposal.proposal_status = `Pending`
it(`should return status info for 'DepositPeriod' proposals`, () => {
proposal.proposal_status = `DepositPeriod`
let { wrapper } = mount(LiProposal, {
propsData: {
proposal
Expand Down
4 changes: 2 additions & 2 deletions test/unit/specs/components/governance/PageProposal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe(`PageProposal`, () => {
})

describe(`Modal onVote`, () => {
it(`enables voting if the proposal is either 'Active' or 'Pending'`, () => {
it(`enables voting if the proposal is on the 'VotingPeriod'`, () => {
let status = { button: `vote` }
wrapper.setProps({ status })

Expand All @@ -76,7 +76,7 @@ describe(`PageProposal`, () => {
expect(voteBtn.html()).not.toContain(`disabled="disabled"`)
})

it(`disables voting if the proposal is Pending deposits`, () => {
it(`disables voting if the proposal is on the 'DepositPeriod'`, () => {
let status = { button: `deposit` }
wrapper.setProps({ status })
expect(wrapper.find(`#vote-btn`).exists()).toEqual(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exports[`TabProposals has the expected html structure 1`] = `
<td class=\\"li-proposal__value\\">
<span class=\\"validator-profile__status blue\\"></span>
<h2>
<a href=\\"#/governance/2\\" class=\\"\\">Active proposal</a>
<a href=\\"#/governance/2\\" class=\\"\\">VotingPeriod proposal</a>
</h2>
<p>
custom text proposal description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exports[`TableProposals has the expected html structure 1`] = `
<td class=\\"li-proposal__value\\">
<span class=\\"validator-profile__status blue\\"></span>
<h2>
<a href=\\"#/governance/2\\" class=\\"\\">Active proposal</a>
<a href=\\"#/governance/2\\" class=\\"\\">VotingPeriod proposal</a>
</h2>
<p>
custom text proposal description
Expand Down
Loading