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 #6

Merged
merged 15 commits into from
Nov 11, 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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ jobs:
cd packages/celotool
./ci_test_transfers.sh checkout master

end-to-end-geth-exit-test:
end-to-end-geth-blockchain-parameters-test:
<<: *e2e-defaults
steps:
- attach_workspace:
Expand All @@ -542,7 +542,7 @@ jobs:
command: |
set -e
cd packages/celotool
./ci_test_exit.sh checkout master
./ci_test_blockchain_parameters.sh checkout master

end-to-end-geth-governance-test:
<<: *e2e-defaults
Expand Down Expand Up @@ -748,7 +748,7 @@ workflows:
requires:
- lint-checks
- contractkit-test
- end-to-end-geth-exit-test:
- end-to-end-geth-blockchain-parameters-test:
requires:
- lint-checks
- contractkit-test
Expand Down
15 changes: 12 additions & 3 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
- [Celo Engineering Setup](#celo-engineering-setup)
- [Getting Everything Installed](#getting-everything-installed)
- [MacOS](#macos)
- [XCode](#xcode)
- [Xcode](#xcode)
- [Homebrew](#homebrew)
- [Install Node, Yarn and friends](#install-node-yarn-and-friends)
- [Java](#java)
- [Install Android Dev Tools](#install-android-dev-tools)
- [Install iOS Dev Tools](#install-ios-dev-tools)
- [Linux](#linux)
- [Install Node, Yarn and friends](#install-node-yarn-and-friends-1)
- [Installing OpenJDK 8](#installing-openjdk-8)
Expand All @@ -31,9 +32,9 @@ build the celo-monorepo codebase.

### MacOS

#### XCode
#### Xcode

Install XCode and its command line tools:
Install Xcode and its command line tools:

```bash
xcode-select --install
Expand Down Expand Up @@ -110,6 +111,14 @@ Then install the Android 28 platform:
sdkmanager 'platforms;android-28'
```

#### Install iOS Dev Tools

Install [Xcode 10.3](https://download.developer.apple.com/Developer_Tools/Xcode_10.3/Xcode_10.3.xip) (an Apple Developer Account is needed to access this link).

We do not recommend installing Xcode through the App Store as it can auto update and become incompatible with our projects (until we decide to upgrade).

Note that using the method above, you can have multiple versions of Xcode installed in parallel by using different app names. For instance `Xcode10.3.app` and `Xcode11.app` inside the `/Applications` folder.

### Linux

#### Install Node, Yarn and friends
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"report-coverage": "yarn run lerna run test-coverage",
"test:watch": "node node_modules/jest/bin/jest.js --watch",
"postinstall": "yarn run lerna run postinstall && patch-package && yarn keys:decrypt",
"preinstall": "bash scripts/create_key_templates.sh",
"keys:decrypt": "bash scripts/key_placer.sh decrypt",
"keys:encrypt": "bash scripts/key_placer.sh encrypt",
"check:packages": "node ./scripts/check-packages.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.pilot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env_variables:
# TODO Pull addresses from the build artifacts of the network in protocol/build
FAUCET_ADDRESS: "0x387bCb16Bfcd37AccEcF5c9eB2938E30d3aB8BF2"
VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5"
WEB3_PROVIDER_URL: "https://pilot-forno.celo-testnet.org/"
WEB3_PROVIDER_URL: "https://pilot-infura.celo-testnet.org/"
3 changes: 1 addition & 2 deletions packages/blockchain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"build": "tsc -p .",
"clean": "rm -rf dist coverage",
"gcp-build": "npm run build",
"deploy": "./deploy.sh",
"postinstall": "test -f src/secrets.json || echo \"{}\" > src/secrets.json"
"deploy": "./deploy.sh"
},
"dependencies": {
"@celo/contractkit": "0.1.6",
Expand Down
20 changes: 20 additions & 0 deletions packages/blockchain-api/src/secrets.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"local": {
"EXCHANGE_RATES_API_ACCESS_KEY": "CHANGE_ME"
},
"integration": {
"EXCHANGE_RATES_API_ACCESS_KEY": "CHANGE_ME"
},
"alfajores": {
"EXCHANGE_RATES_API_ACCESS_KEY": "CHANGE_ME"
},
"alfajoresstaging": {
"EXCHANGE_RATES_API_ACCESS_KEY": "CHANGE_ME"
},
"pilot": {
"EXCHANGE_RATES_API_ACCESS_KEY": "CHANGE_ME"
},
"pilotstaging": {
"EXCHANGE_RATES_API_ACCESS_KEY": "CHANGE_ME"
}
}
1 change: 1 addition & 0 deletions packages/blockchain-api/yarn.lock
2 changes: 2 additions & 0 deletions packages/celotool/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/lib/
.tmp

twilio-config.js
30 changes: 30 additions & 0 deletions packages/celotool/README-e2e.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Celo-Blockchain End-to-End Tests

This package contains a number of end-to-end tests that depend both on the
monorepo protocol package and the Golang celo-blockchain implmenetation.

## Setup

1. Run `yarn` to install node dependencies
2. Other dependencies:
1. `nc`, the [netcat](https://en.wikipedia.org/wiki/Netcat) networking utility

## Usage

The tests are run using bash script wrappers. They are the
`ci_test_<TEST NAME>.sh` files in this package. Each requires a version of
celo-blockchain to be specified, which can be done in two ways.

### Celo-blockchain built from local source

```
./ci_test_governance.sh local PATH
```

Where `PATH` is a path to a local source repository for celo-blockchain.

### Celo-blockchain built from a specific GitHub branch

```
./ci_test_governance.sh checkout BRANCH
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ if [ "${1}" == "checkout" ]; then
# Test master by default.
BRANCH_TO_TEST=${2:-"master"}
echo "Checking out geth at branch ${BRANCH_TO_TEST}..."
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/exit_test.ts --branch ${BRANCH_TO_TEST}
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/blockchain_parameters_tests.ts --branch ${BRANCH_TO_TEST}
elif [ "${1}" == "local" ]; then
export GETH_DIR="${2}"
echo "Testing using local geth dir ${GETH_DIR}..."
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/exit_test.ts --localgeth ${GETH_DIR}
../../node_modules/.bin/mocha -r ts-node/register src/e2e-tests/blockchain_parameters_tests.ts --localgeth ${GETH_DIR}
fi
32 changes: 22 additions & 10 deletions packages/celotool/src/cmds/account/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { downloadArtifacts } from 'src/lib/artifacts'
import { switchToClusterFromEnv } from 'src/lib/cluster'
/* tslint:disable no-console */
import { newKit } from '@celo/contractkit'
import { convertToContractDecimals } from 'src/lib/contract-utils'
import { portForwardAnd } from 'src/lib/port_forward'
import { execCmd, validateAccountAddress } from 'src/lib/utils'
import { validateAccountAddress } from 'src/lib/utils'
import * as yargs from 'yargs'
import { AccountArgv } from '../account'

Expand All @@ -28,18 +29,29 @@ export const builder = (argv: yargs.Argv) => {
}

export const handler = async (argv: FaucetArgv) => {
await switchToClusterFromEnv()
const address = argv.account

const cb = async () => {
await execCmd(
// TODO(yerdua): reimplement the protocol transfer script here, using
// the SDK + Web3 when the SDK can be built for multiple environments
`yarn --cwd ../protocol run transfer -n ${argv.celoEnv} -a ${argv.account} -d 10 -g 10`
)
const kit = newKit('http://localhost:8545')
const account = (await kit.web3.eth.getAccounts())[0]
console.log(`Using account: ${account}`)
kit.defaultAccount = account

const [goldToken, stableToken] = await Promise.all([
kit.contracts.getGoldToken(),
kit.contracts.getStableToken(),
])
const goldAmount = (await convertToContractDecimals(1, goldToken)).toString()
const stableTokenAmount = (await convertToContractDecimals(10, stableToken)).toString()

console.log(`Fauceting ${goldAmount} Gold and ${stableTokenAmount} StableToken to ${address}`)
await Promise.all([
goldToken.transfer(address, goldAmount).sendAndWaitForReceipt(),
stableToken.transfer(address, stableTokenAmount).sendAndWaitForReceipt(),
])
}

try {
await downloadArtifacts(argv.celoEnv)
await portForwardAnd(argv.celoEnv, cb)
} catch (error) {
console.error(`Unable to faucet ${argv.account} on ${argv.celoEnv}`)
Expand Down
109 changes: 84 additions & 25 deletions packages/celotool/src/cmds/account/invite.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* tslint:disable no-console */
import { downloadArtifacts } from 'src/lib/artifacts'
import { switchToClusterFromEnv } from 'src/lib/cluster'
import { newKit } from '@celo/contractkit'
import { BigNumber } from 'bignumber.js'
import { convertToContractDecimals } from 'src/lib/contract-utils'
import { portForwardAnd } from 'src/lib/port_forward'
import { execCmd } from 'src/lib/utils'
import twilio from 'twilio'
import { Argv } from 'yargs'
import { AccountArgv } from '../account'

Expand All @@ -12,39 +14,96 @@ export const describe = 'command for sending an invite code to a phone number'

interface InviteArgv extends AccountArgv {
phone: string
fast: boolean
}

export const builder = (yargs: Argv) => {
return yargs
.option('phone', {
type: 'string',
description: 'Phone number to send invite code,',
demand: 'Please specify phone number to send invite code',
})
.option('fast', {
type: 'boolean',
default: false,
description: "Don't download artifacts, use this for repeated invocations",
demand: 'Please specify phone number to send invite code',
})
return yargs.option('phone', {
type: 'string',
description: 'Phone number to send invite code,',
demand: 'Please specify phone number to send invite code',
})
}

export const handler = async (argv: InviteArgv) => {
console.log(`Sending invitation code to ${argv.phone}`)
const phone = argv.phone

console.log(`Sending invitation code to ${phone}`)

// This key is only present in celo-testnet
await execCmd('gcloud config set project celo-testnet')
await execCmd(
'gcloud kms decrypt --ciphertext-file=twilio-config.enc --plaintext-file=twilio-config.js \
--key=github-key --keyring=celo-keyring --location=global'
)
const cb = async () => {
await execCmd(
`yarn --cwd ../protocol run invite -n ${argv.celoEnv} -p ${argv.phone} -f ${argv.fast}`
const kit = newKit('http://localhost:8545')
const account = (await kit.web3.eth.getAccounts())[0]
console.log(`Using account: ${account}`)
kit.defaultAccount = account

// TODO(asa): This number was made up
const attestationGasAmount = new BigNumber(10000000)
// TODO: this default gas price might not be accurate
const gasPrice = 100000000000

const temporaryWalletAccount = await kit.web3.eth.accounts.create()
const temporaryAddress = temporaryWalletAccount.address
// Buffer.from doesn't expect a 0x for hex input
const privateKeyHex = temporaryWalletAccount.privateKey.substring(2)
const inviteCode = Buffer.from(privateKeyHex, 'hex').toString('base64')

const [goldToken, stableToken, attestations, escrow] = await Promise.all([
kit.contracts.getGoldToken(),
kit.contracts.getStableToken(),
kit.contracts.getAttestations(),
kit.contracts.getEscrow(),
])
const attestationFee = new BigNumber(
await attestations.attestationRequestFees(stableToken.address)
)
const goldAmount = attestationGasAmount.times(gasPrice).toString()
const stableTokenInviteAmount = attestationFee.times(10).toString()
const stableTokenEscrowAmount = (await convertToContractDecimals(5, stableToken)).toString()

const phoneHash: string = kit.web3.utils.soliditySha3({
type: 'string',
value: phone,
})

await stableToken.approve(escrow.address, stableTokenEscrowAmount).sendAndWaitForReceipt()
const expirySeconds = 60 * 60 * 24 * 5 // 5 days

console.log(
`Transferring ${goldAmount} Gold, ${stableTokenInviteAmount} StableToken, and escrowing ${stableTokenEscrowAmount} StableToken`
)
await Promise.all([
// TODO: remove if no one is paying for gas with gold
goldToken.transfer(temporaryAddress, goldAmount).sendAndWaitForReceipt(),
stableToken.transfer(temporaryAddress, stableTokenInviteAmount).sendAndWaitForReceipt(),
escrow
.transfer(
phoneHash,
stableToken.address,
stableTokenEscrowAmount,
expirySeconds,
temporaryAddress,
0
)
.sendAndWaitForReceipt(),
])
console.log(`Temp address: ${temporaryAddress}`)
console.log(`Invite code: ${inviteCode}`)
const messageText = `Hi! I would like to invite you to join the Celo payments network. Your invite code is: ${inviteCode}`
console.log('Sending SMS...')
const twilioConfig = require('twilio-config')
const twilioClient = twilio(twilioConfig.sid, twilioConfig.authToken)
await twilioClient.messages.create({
body: messageText,
from: twilioConfig.phoneNumber,
to: argv.phone,
})
}
try {
if (argv.fast) {
console.log(`Fast mode is on, cluster won't be switched, artifacts won't be downloaded`)
} else {
console.log(`Fast mode is off, artifacts will be downloaded`)
await switchToClusterFromEnv(false)
await downloadArtifacts(argv.celoEnv)
}
await portForwardAnd(argv.celoEnv, cb)
} catch (error) {
console.error(`Unable to send invitation code to ${argv.phone}`)
Expand Down
Loading