Skip to content

Commit

Permalink
Fix #155 -- allow passing large deposit amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmgdr committed Feb 27, 2024
1 parent eeeba23 commit dd240b5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cli/exampleProposal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
79 changes: 79 additions & 0 deletions packages/cli/src/commands/governance/propose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Address } from '@celo/connect'
import { newKitFromWeb3 } from '@celo/contractkit'
import { NetworkConfig, testWithGanache } from '@celo/dev-utils/lib/ganache-test'
import { ux } from '@oclif/core'
import Web3 from 'web3'
import { testLocally } from '../../test-utils/cliUtils'
import Propose from './propose'
process.env.NO_SYNCCHECK = 'true'

const expConfig = NetworkConfig.governance

testWithGanache('governance:propose cmd', (web3: Web3) => {
const minDeposit = web3.utils.toWei(expConfig.minDeposit.toString(), 'ether')
const kit = newKitFromWeb3(web3)

let accounts: Address[] = []

beforeEach(async () => {
accounts = await web3.eth.getAccounts()
kit.defaultAccount = accounts[0]
})
test('fails when descriptionURl is missing', async () => {
await expect(
testLocally(Propose, [
'--from',
accounts[0],
'--deposit',
'0',
'--jsonTransactions',
'./exampleProposal.json',
])
).rejects.toThrow('Missing required flag descriptionURL')
})
test('can submit empty proposal', async () => {
await testLocally(Propose, [
'--from',
accounts[0],
'--deposit',
minDeposit,
'--jsonTransactions',
'./exampleProposal.json',
'--descriptionURL',
'https://example.com',
])
})
test('can submit proposal using e notion for deposit', async () => {
const spyStart = jest.spyOn(ux.action, 'start')
const spyStop = jest.spyOn(ux.action, 'stop')
await testLocally(Propose, [
'--from',
accounts[0],
'--deposit',
'10000e18',
'--jsonTransactions',
'./exampleProposal.json',
'--descriptionURL',
'https://example.com',
])
expect(spyStart).toHaveBeenCalledWith('Sending Transaction: proposeTx')
expect(spyStop).toHaveBeenCalled()
})
test('when deposit is 10K it succeeds', async () => {
const spyStart = jest.spyOn(ux.action, 'start')
const spyStop = jest.spyOn(ux.action, 'stop')

await testLocally(Propose, [
'--from',
accounts[0],
'--deposit',
'10000000000000000000000',
'--jsonTransactions',
'./exampleProposal.json',
'--descriptionURL',
'https://example.com',
])
expect(spyStart).toHaveBeenCalledWith('Sending Transaction: proposeTx')
expect(spyStop).toHaveBeenCalled()
})
})
7 changes: 5 additions & 2 deletions packages/cli/src/commands/governance/propose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default class Propose extends BaseCommand {
required: true,
description: 'Path to json transactions',
}),
deposit: Flags.string({ required: true, description: 'Amount of Gold to attach to proposal' }),
deposit: Flags.string({
required: true,
description: 'Amount of Celo to attach to proposal',
}),
from: CustomFlags.address({ required: true, description: "Proposer's address" }),
force: Flags.boolean({ description: 'Skip execution check', default: false }),
descriptionURL: Flags.string({
Expand Down Expand Up @@ -88,7 +91,7 @@ export default class Propose extends BaseCommand {
await displaySendTx(
'proposeTx',
governance.propose(proposal, res.flags.descriptionURL),
{ value: deposit.toString() },
{ value: deposit.toFixed() },
'ProposalQueued'
)
}
Expand Down

0 comments on commit dd240b5

Please sign in to comment.