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

master #14

Merged
merged 7 commits into from
Dec 2, 2019
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
35 changes: 24 additions & 11 deletions packages/celotool/src/e2e-tests/governance_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ describe('governance tests', () => {
await waitToFinishSyncing(groupWeb3)
const groupKit = newKitFromWeb3(groupWeb3)
const group: string = (await groupWeb3.eth.getAccounts())[0]
await (await groupKit.contracts.getElection()).activate(group)
const txos = await (await groupKit.contracts.getElection()).activate(group)
for (const txo of txos) {
await txo.sendAndWaitForReceipt({ from: group })
}

validators = await groupKit._web3Contracts.getValidators()
const membersToSwap = [validatorAccounts[0], validatorAccounts[1]]
Expand Down Expand Up @@ -603,6 +606,7 @@ describe('governance tests', () => {
const activeVotes = new BigNumber(
await election.methods.getActiveVotes().call({}, blockNumber - 1)
)
assert.isFalse(activeVotes.isZero())
const targetVotingYield = new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber))[0]
)
Expand Down Expand Up @@ -644,17 +648,26 @@ describe('governance tests', () => {
const previousTarget = new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber - 1))[0]
)
const difference = currentTarget.minus(previousTarget)

// Assert equal to 9 decimal places due to rounding errors.
assert.equal(
fromFixed(difference)
.dp(9)
.toFixed(),
fromFixed(expected)
.dp(9)
.toFixed()
const max = new BigNumber(
(await epochRewards.methods.getTargetVotingYieldParameters().call({}, blockNumber))[1]
)
const expectedTarget = previousTarget.plus(expected)
if (expectedTarget.isGreaterThanOrEqualTo(max)) {
assert.equal(currentTarget.toFixed(), max.toFixed())
} else if (expectedTarget.isLessThanOrEqualTo(0)) {
assert.isTrue(currentTarget.isZero())
} else {
const difference = currentTarget.minus(previousTarget)
// Assert equal to 9 decimal places due to rounding errors.
assert.equal(
fromFixed(difference)
.dp(9)
.toFixed(),
fromFixed(expected)
.dp(9)
.toFixed()
)
}
}

const assertTargetVotingYieldUnchanged = async (blockNumber: number) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/e2e-tests/sync_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('sync tests', function(this: any) {
// Give the validators time to create more blocks.
await sleep(20)
const validatingLatestBlock = await validatingWeb3.eth.getBlockNumber()
await sleep(1)
await sleep(10)
const syncLatestBlock = await syncWeb3.eth.getBlockNumber()
assert.isAbove(validatingLatestBlock, 1)
// Assert that the validator is still producing blocks.
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/account/show.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseCommand } from '../../base'
import { printValueMap } from '../../utils/cli'
import { printValueMapRecursive } from '../../utils/cli'
import { Args } from '../../utils/command'

export default class Show extends BaseCommand {
Expand All @@ -18,6 +18,6 @@ export default class Show extends BaseCommand {
const { args } = this.parse(Show)

const accounts = await this.kit.contracts.getAccounts()
printValueMap(await accounts.getAccountSummary(args.address))
printValueMapRecursive(await accounts.getAccountSummary(args.address))
}
}
7 changes: 6 additions & 1 deletion packages/cli/src/commands/election/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default class ElectionShow extends BaseCommand {
Args.address('address', { description: "Voter or Validator Groups's address" }),
]

static examples = ['show 0x97f7333c51897469E8D98E7af8653aAb468050a3']
static examples = [
'show 0x97f7333c51897469E8D98E7af8653aAb468050a3 --voter',
'show 0x97f7333c51897469E8D98E7af8653aAb468050a3 --group',
]

async run() {
const res = this.parse(ElectionShow)
Expand All @@ -43,6 +46,8 @@ export default class ElectionShow extends BaseCommand {
.runChecks()
const voter = await election.getVoter(address)
printValueMapRecursive(voter)
} else {
throw Error('Must select --voter or --group')
}
}
}
4 changes: 3 additions & 1 deletion packages/cli/src/commands/election/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ export default class ElectionVote extends BaseCommand {
]
async run() {
const res = this.parse(ElectionVote)
const value = new BigNumber(res.flags.value)

this.kit.defaultAccount = res.flags.from
await newCheckBuilder(this, res.flags.from)
.isSignerOrAccount()
.isValidatorGroup(res.flags.for)
.hasEnoughNonvotingLockedGold(value)
.runChecks()

const election = await this.kit.contracts.getElection()
const tx = await election.vote(res.flags.for, new BigNumber(res.flags.value))
const tx = await election.vote(res.flags.for, value)
await displaySendTx('vote', tx)
}
}
7 changes: 5 additions & 2 deletions packages/cli/src/commands/lockedgold/unlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { flags } from '@oclif/command'
import BigNumber from 'bignumber.js'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
Expand All @@ -23,11 +24,13 @@ export default class Unlock extends BaseCommand {
const res = this.parse(Unlock)
this.kit.defaultAccount = res.flags.from
const lockedgold = await this.kit.contracts.getLockedGold()
const value = new BigNumber(res.flags.value)

await newCheckBuilder(this)
await newCheckBuilder(this, res.flags.from)
.isAccount(res.flags.from)
.hasEnoughNonvotingLockedGold(value)
.runChecks()

await displaySendTx('unlock', lockedgold.unlock(res.flags.value))
await displaySendTx('unlock', lockedgold.unlock(value))
}
}
32 changes: 30 additions & 2 deletions packages/cli/src/utils/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ class CheckBuilder {
}
}

withLockedGold<A>(f: (lockedGold: LockedGoldWrapper) => A): () => Promise<Resolve<A>> {
withLockedGold<A>(
f: (lockedGold: LockedGoldWrapper, signer: Address, account: Address) => A
): () => Promise<Resolve<A>> {
return async () => {
const lockedGold = await this.kit.contracts.getLockedGold()
return f(lockedGold) as Resolve<A>
const validators = await this.kit.contracts.getValidators()
if (this.signer) {
const account = await validators.signerToAccount(this.signer)
return f(lockedGold, this.signer, account) as Resolve<A>
} else {
return f(lockedGold, '', '') as Resolve<A>
}
}
}

Expand Down Expand Up @@ -152,6 +160,26 @@ class CheckBuilder {
)
}

hasEnoughLockedGold = (value: BigNumber) => {
const valueInEth = this.kit.web3.utils.fromWei(value.toFixed(), 'ether')
return this.addCheck(
`Account has at least ${valueInEth} Locked Gold`,
this.withLockedGold(async (l, _signer, account) =>
value.isLessThanOrEqualTo(await l.getAccountTotalLockedGold(account))
)
)
}

hasEnoughNonvotingLockedGold = (value: BigNumber) => {
const valueInEth = this.kit.web3.utils.fromWei(value.toFixed(), 'ether')
return this.addCheck(
`Account has at least ${valueInEth} non-voting Locked Gold`,
this.withLockedGold(async (l, _signer, account) =>
value.isLessThanOrEqualTo(await l.getAccountNonvotingLockedGold(account))
)
)
}

async runChecks() {
console.log(`Running Checks:`)
let allPassed = true
Expand Down
8 changes: 4 additions & 4 deletions packages/contractkit/src/wrappers/Election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ export class ElectionWrapper extends BaseWrapper<Election> {
*/
async hasPendingVotes(account: Address): Promise<boolean> {
const groups: string[] = await this.contract.methods.getGroupsVotedForByAccount(account).call()
const isNotPending = await Promise.all(
const isPending = await Promise.all(
groups.map(async (g) =>
toBigNumber(
await this.contract.methods.getPendingVotesForGroupByAccount(account, g).call()
).isZero()
await this.contract.methods.getPendingVotesForGroupByAccount(g, account).call()
).isGreaterThan(0)
)
)
return !isNotPending.every((a: boolean) => a)
return isPending.some((a: boolean) => a)
}

async hasActivatablePendingVotes(account: Address): Promise<boolean> {
Expand Down
5 changes: 3 additions & 2 deletions packages/docs/command-line-interface/election.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ OPTIONS
--group Show information about a group running in Validator elections
--voter Show information about an account voting in Validator elections

EXAMPLE
show 0x97f7333c51897469E8D98E7af8653aAb468050a3
EXAMPLES
show 0x97f7333c51897469E8D98E7af8653aAb468050a3 --voter
show 0x97f7333c51897469E8D98E7af8653aAb468050a3 --group
```

_See code: [packages/cli/src/commands/election/show.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/election/show.ts)_
Expand Down
32 changes: 0 additions & 32 deletions packages/docs/command-line-interface/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,6 @@ npm install -g @celo/celocli
We are currently deploying the CLI with only Node v10.x LTS support. If you are running a different version of Node, consider using [NVM](https://github.com/nvm-sh/nvm#installation-and-update) to manage your node versions. e.g. with: `nvm install 10 && nvm use 10`
{% endhint %}

### Docker Image

Additionally, if don't have NPM or are having trouble installing the Celo CLI with your version of node, you can use a docker image that runs the Celo Blockchain client in full sync mode which includes the Celo CLI.

```bash
docker pull us.gcr.io/celo-testnet/celocli:master
```

For more details on configuring this container, see the [Running a Full Node](../getting-started/running-a-full-node.md) section. You can run the container with the following command.

```bash
docker run --name celo_cli_container -it -p 8545:8545 us.gcr.io/celo-testnet/celocli:master -v
```

With additional arguments to the image, it can also be run in ultralight sync mode.

```bash
docker run --name celo_cli_container -p 8545:8545 --entrypoint=/celo/start_geth.sh us.gcr.io/celo-testnet/celocli:master "/usr/local/bin/geth" "alfajores" "ultralight"
```

An interactive shell where the Celo CLI is available can be obtained via the following command. All of the subsequent documentation should be appropriate from this shell.

```bash
docker exec -it celo_cli_container /bin/sh
```

Make sure to kill the container when you are done.

```bash
docker kill celo_cli_container
```

### **Prerequisites**

- **You have a full node running.** See the [Running a Full Node](running-a-full-node.md) instructions for more details on running a full node.
Expand Down
Loading