Skip to content

Commit

Permalink
Detox (#26)
Browse files Browse the repository at this point in the history
* this is a mock for doc purposes

* implemented aes function

* iOS unit tests

* detox setup

* test app for detox

* m

* reset index.js in cleanup of detox tests

* including e2e test notes in readme

* make iv proper length, delete unused files

* this is a mock for doc purposes

* implemented aes function

* iOS unit tests

* detox setup

* test app for detox

* reset index.js in cleanup of detox tests

* including e2e test notes in readme

* make iv proper length, delete unused files

* this is a mock for doc purposes

* implemented aes function

* iOS unit tests

* detox setup

* make iv proper length, delete unused files

* package.json

* detox detox detox

* detox

* made test directory for unit tests

* testing detox with travis

* travis <3 detox

* travis attempt 3

* travis

* travis

* travis <3 brew

* travis still <3 brew

* travis <3 xcode tools

* downgraded iphone to match xcode 9, which is used to match travis xcode cli tools

* updated index files

* package json alteration to get detox to work in travis

* ensure there is a polyfill

* fixed package.json

* travis <3 react-native

* typo

* install react-native-cli

* travis <3 detox-cli

* took detox out of travis

* changed some filenames for more clarity

* updated readme

* code review changes

* reverted travis

* made readme more readable

* post install react-native link"

* corrected file name

* Remove Polyfill from index

* Update index.ios.js

* Update meat-grinder.js

* Update init.js

* Delete index.js
  • Loading branch information
hadasz authored and barlock committed Oct 26, 2018
1 parent f0587f9 commit 1f8fb50
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
node: true,
browser: true,
jest: true,
jasmine: true,
mocha: true
},
globals: {
Expand All @@ -18,7 +19,7 @@ module.exports = {
'plugin:react/recommended',
'plugin:prettier/recommended'
],
plugins: ['react', 'react-native'],
plugins: ['react', 'react-native', 'jasmine', 'detox'],
settings: {
react: {
pragma: 'React',
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ buck-out/
# Bundle artifact
*.jsbundle

#index file that gets replaced by e2e test scripts
./index.js
# env
.env.*
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "8"
- '8'
branches:
only:
- master
- master
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ UPORT_APP_NAME=Sojourn
UPORT_APP_ADDRESS=2onKAS55Vs9hGwDPsBT6DYHwAP1HJ3FsBXh
UPORT_PRIVATE_KEY=<YOUR_PRIVATE_KEY>
```

# Testing

### End to End Tests

Run `yarn e2e` to run end to end tests. Because schemes other than debug and release are not trivial in react-native,
and because javascript environment variables are not trivial to pass in react-native,
there are two index files, index.ios.js which is the entry point for the regular app as it should be used in production,
and index.e2e.js, an entry point which is used for e2e tests. This is a temporary measure, as a way to test native modules
on the javascript side that are not yet integrated into the app (mainly for cryptography functions);
35 changes: 35 additions & 0 deletions e2e/E2ETests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { Component } from 'react';
import { encryptWithAes } from '../src/utils/meat-grinder.js';
import { View, Text } from 'react-native';
var inputSizes = [16, 20, 48];
const testPrivateKey =
'8238BAE35C77FE4AEBB2DEB1B83A6F0027A01D0E4D93BF5B81F7117796955A17';
export default class E2ETests extends Component {
constructor(props) {
super(props);
this.state = { input16: 0, input20: 0, input48: 0 };
inputSizes.map(inputSize => {
this.encryptForSize(inputSize);
});
}
async encryptForSize(sizeInBytes) {
let aesOutput = await encryptWithAes(
testPrivateKey,
new Array(sizeInBytes).join('x')
);
if (!aesOutput) {
throw Error('output is not good');
}
this.setState({ ['input'.concat(sizeInBytes)]: aesOutput.ciphertext });
return 'success';
}
render() {
return (
<View testID="welcome" style={{ flex: 1, justifyContent: 'center' }}>
<Text testID="16ByteInput">{this.state.input16.length}</Text>
<Text testID="20ByteInput">{this.state.input20.length}</Text>
<Text testID="48ByteInput">{this.state.input48.length}</Text>
</View>
);
}
}
4 changes: 4 additions & 0 deletions e2e/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"setupTestFrameworkScriptFile": "./init.js",
"testEnvironment": "node"
}
20 changes: 20 additions & 0 deletions e2e/firstTest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-env detox/detox, jest*/
describe('Example', () => {
beforeEach(async () => {
await device.reloadReactNative();
});

it('should have welcome screen', async () => {
await expect(element(by.id('16ByteInput'))).toHaveText('24');
});
/* it('should show hello screen after tap', async () => {
await element(by.id('hello_button')).tap();
await expect(element(by.text('Hello!!!'))).toBeVisible();
});
it('should show world screen after tap', async () => {
await element(by.id('world_button')).tap();
await expect(element(by.text('World!!!'))).toBeVisible();
});
*/
});
22 changes: 22 additions & 0 deletions e2e/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const { exec } = require('child_process');

jest.setTimeout(120000);
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
exec('cp index.e2e.js index.js');
await detox.init(config);
});

beforeEach(async () => {
await adapter.beforeEach();
});

afterAll(async () => {
await adapter.afterAll();
exec('rm index.js');
await detox.cleanup();
});
4 changes: 4 additions & 0 deletions index.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AppRegistry } from 'react-native';
import { name as appName } from './app.json';
import E2ETests from './e2e/E2ETests';
AppRegistry.registerComponent(appName, () => E2ETests);
4 changes: 4 additions & 0 deletions index.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AppRegistry } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, () => App);
9 changes: 0 additions & 9 deletions index.js

This file was deleted.

2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ module.exports = {
},
transformIgnorePatterns: ['node_modules/(?!react-|drizzle).+\\.js$'],
setupFiles: ['./src/setupJest.js'],
testPathIgnorePatterns: ['/node_modules/', '/test/']
testPathIgnorePatterns: ['/node_modules', '/e2e/', '/test/']
};
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
"ios": "react-native run-ios",
"lint": "eslint .",
"jest": "yarn build:truffle && jest",
"prettier": "prettier \"**/*.{js,json,css,md}\" --write",
"test": "yarn lint && yarn jest --coverage && yarn solidity-coverage",
"prettier": "prettier \"**/*.{js,json,css,md}\" --write"
"post-install": "react-native link",
"e2e": "detox build && detox test"
},
"dependencies": {
"react-native-aes-crypto": "^1.2.3",
"react": "16.5.0",
"react-native": "0.57.2",
"react-native-dotenv": "^0.2.0",
Expand All @@ -35,8 +38,11 @@
"babel-jest": "^23.6.0",
"chai": "^4.2.0",
"concurrently": "^4.0.1",
"detox": "^9.0.4",
"eslint": "^5.6.1",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-detox": "^1.0.0",
"eslint-plugin-jasmine": "^2.10.1",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-react-native": "^3.3.0",
Expand All @@ -58,5 +64,16 @@
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"detox": {
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/sojourn.app",
"build": "xcodebuild -project ios/sojourn.xcodeproj -configuration Debug -scheme sojourn -sdk iphonesimulator -derivedDataPath ios/build -UseModernBuildSystem=NO",
"type": "ios.simulator",
"name": "iPhone 7"
}
},
"test-runner": "jest"
}
}
51 changes: 51 additions & 0 deletions src/utils/meat-grinder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Aes from 'react-native-aes-crypto';
//arguments: file - plaintext file
//return value:encrypted file
export async function encryptWithAes(privateKey, plainTextFile) {
const iv = 'sixteen bytes iv'; //To DO: randomly generate
try {
const ciphertext = await Aes.encrypt(plainTextFile, privateKey, iv);
return { ciphertext, iv };
} catch (error) {
throw error;
}
}

//arguments: encrypted file
//return value: array of (x,y) coordinates
/*
import Aes from '@trackforce/react-native-aes-crypto';
//arguments: file - plaintext file
//return value:encrypted file
export async function encryptWithAes(privateKey, plainTextFile) {
const iv = 'sixteen bytes iv'; //To DO: randomly generate
try {
const ciphertext = await Aes.encrypt(plainTextFile, privateKey, iv);
return { ciphertext, iv };
} catch (error) {
throw error;
}
}
//arguments: encrypted file
//return value: array of (x,y) coordinates
function encryptWithShamirs(encryptedFile) {}
//arguments:array points needed to reconstruct encryptedFile
//return value: array of new (x,y) coordinates
function hashPointsWithPrivateKey(arrayOfPoints) {}
//argument: array of (x,y) coordinates
//return value: Promise that resolves to an array of IPFS Hashe's
async function submitPointsToIPFS(points) {}
async function saveToVault(plainTextFile) {
let points = hashPointsWithPrivateKey(
encryptWithShamirs(encryptWithAes(plainTextFile))
);
let ipfsHashes = await submitPointsToIPFS(points);
return ipfsHashes;
}
*/

0 comments on commit 1f8fb50

Please sign in to comment.