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

Detox #26

Merged
merged 60 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
5156b03
this is a mock for doc purposes
Oct 10, 2018
a135e8b
implemented aes function
Oct 12, 2018
bedf211
iOS unit tests
Oct 16, 2018
b2397e6
detox setup
Oct 17, 2018
b280036
test app for detox
Oct 19, 2018
487a645
m
Oct 19, 2018
7a94375
reset index.js in cleanup of detox tests
Oct 20, 2018
2bd464c
including e2e test notes in readme
Oct 20, 2018
bf9f553
make iv proper length, delete unused files
Oct 20, 2018
500470d
Merge branch 'master' of github.com:ConsenSys/imagineering-sojourn
Oct 22, 2018
03f3358
this is a mock for doc purposes
Oct 10, 2018
0cdca4e
implemented aes function
Oct 12, 2018
91508b8
iOS unit tests
Oct 16, 2018
39919c7
detox setup
Oct 17, 2018
d0402c0
test app for detox
Oct 19, 2018
81aed5b
reset index.js in cleanup of detox tests
Oct 20, 2018
4662b2a
including e2e test notes in readme
Oct 20, 2018
cbc5eec
make iv proper length, delete unused files
Oct 20, 2018
4b36be1
this is a mock for doc purposes
Oct 10, 2018
905433d
implemented aes function
Oct 12, 2018
de6824a
iOS unit tests
Oct 16, 2018
4540918
detox setup
Oct 17, 2018
8f4d1c1
make iv proper length, delete unused files
Oct 20, 2018
6242961
package.json
Oct 22, 2018
a8cf21e
conflict merge
Oct 22, 2018
48f5e12
detox detox detox
Oct 22, 2018
8b5a969
detox
Oct 22, 2018
c065df6
made test directory for unit tests
Oct 23, 2018
c235dde
testing detox with travis
Oct 23, 2018
0685882
travis <3 detox
Oct 23, 2018
bbdbbe0
travis attempt 3
Oct 24, 2018
467a591
travis
Oct 24, 2018
50d9900
travis
Oct 24, 2018
e6b52ad
travis <3 brew
Oct 24, 2018
2f6a75c
travis still <3 brew
Oct 24, 2018
a6a32af
travis <3 xcode tools
Oct 24, 2018
dff781d
downgraded iphone to match xcode 9, which is used to match travis xco…
Oct 24, 2018
a565988
updated index files
Oct 24, 2018
b563268
package json alteration to get detox to work in travis
Oct 24, 2018
9a8f407
ensure there is a polyfill
Oct 24, 2018
3cbb5a5
fixed package.json
Oct 24, 2018
0314527
travis <3 react-native
Oct 24, 2018
1855763
typo
Oct 24, 2018
a92fd4d
install react-native-cli
Oct 24, 2018
39eb25d
travis <3 detox-cli
Oct 24, 2018
bbf6367
took detox out of travis
Oct 25, 2018
51c3f3c
changed some filenames for more clarity
Oct 25, 2018
becab52
merge
Oct 25, 2018
3defe29
updated readme
Oct 25, 2018
4abbd18
code review changes
Oct 26, 2018
2d12a1a
reverted travis
Oct 26, 2018
7badc02
made readme more readable
Oct 26, 2018
d1f6e48
post install react-native link"
Oct 26, 2018
3ae77a5
corrected file name
Oct 26, 2018
7a48c46
Merge branch 'master' into detox
barlock Oct 26, 2018
6830337
Remove Polyfill from index
barlock Oct 26, 2018
772c395
Update index.ios.js
barlock Oct 26, 2018
69460ca
Update meat-grinder.js
barlock Oct 26, 2018
aa1d73c
Update init.js
barlock Oct 26, 2018
c762ff9
Delete index.js
barlock Oct 26, 2018
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructors can't be async so doing async here means you have uncaught exceptions.

The right place is compomnentDidMount

class SomeClass extends Component {
  state = { input16: 0, input20: 0, input48: 0 };
}

☝️ Class properties mean less typing!

super(props);
this.state = { input16: 0, input20: 0, input48: 0 };
inputSizes.map(inputSize => {
this.encryptForSize(inputSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to do this on componentDidMount() for initialization

https://reactjs.org/docs/react-component.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next PR

});
}
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return seems unnecessary ?

}
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 @@
{
barlock marked this conversation as resolved.
Show resolved Hide resolved
"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*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the .eslint file so you don't need it 🎉

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 () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for commented code? Looks like boiler plate you didn't delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholder -- will be deleted in next pull request

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);
hadasz marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Nice! I love the documentation. Is this format a standard? Should we use JSDoc instead? I see that fairly commonly.

export async function encryptWithAes(privateKey, plainTextFile) {
const iv = 'sixteen bytes iv'; //To DO: randomly generate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you plan on using an IV? Per file/user? I think they're optional, though definitely good practice, yeah?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IV will be used per file, so nobody can do cryptanalysis on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any thoughts on how we're going to store the IV? I'm guessing it will need to go in the azure "how to decrypt" file? (Obviously not necessary for this pr, just curious)

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's all of the commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was for mocking purposes for John, Will be filled in as I complete it

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;
}
*/