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

test: add e2e signing and ethereum tests #549

Merged
merged 13 commits into from
Mar 5, 2020
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
8 changes: 5 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const commonRules = {
"comma-dangle": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "single", { "avoidEscape": true }],
"no-unused-vars": ["error", { "args": "none" }],
"react-native/no-inline-styles": "off",
"sort-keys": ["error", "asc", {"caseSensitive": true, "natural": false, "minKeys": 2}],
"import/order": ["error", {
Expand All @@ -22,7 +21,7 @@ module.exports = {
globals: { inTest: "writable" },
overrides: [
{
files: ["e2e/*.spec.js", "e2e/init.js", "e2e/e2eUtils.js"],
files: ["e2e/*.spec.js", "e2e/init.js", "e2e/utils.js"],
rules: {
"no-undef": "off"
}
Expand Down Expand Up @@ -83,5 +82,8 @@ module.exports = {
"version": "16.9.0", // React version, default to the latest React stable release
},
},
rules: commonRules
rules: {
...commonRules,
"no-unused-vars": ["error", { "args": "none" }],
}
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package-lock.json
dist/

# jest cache
.jest/cache
test/.jest/

# NDK
NDK/
Expand Down Expand Up @@ -52,6 +52,7 @@ build/
local.properties
*.iml
gen/
*.hprof

# node.js
#
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:

script:
- yarn run lint
- yarn run test
- yarn run unit

# TODO complete following part to Integrate E2E test

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ Corresponding data:

#### Unit Test

Run `yarn test` for all the units test.
Run `yarn unit` for all the units test.

If debugging is needed:

1. Insert `debugger;` in the code where you think it fails.
2. Run `yarn test:debug`
2. Run `yarn unit:debug`
3. Open a new tab in Chrome and go to `chrome://inspect`
4. Click the `inspect` button of target under `Remote Target`
5. Back to the terminal, choose one of the node watch commands to run the tests again.
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
alias: {
components: './src/components',
constants: './src/constants',
e2e: './e2e',
e2e: './test/e2e',
res: './res',
screens: './src/screens',
stores: './src/stores',
Expand Down
6 changes: 0 additions & 6 deletions e2e/config.json

This file was deleted.

43 changes: 0 additions & 43 deletions e2e/mock.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ios/NativeSigner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
shellScript = "export NODE_BINARY=node\nexport NODE_OPTIONS=\"--max_old_space_size=8192\"\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
1,269 changes: 648 additions & 621 deletions ios/main.jsbundle

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"lint:fix": "npx eslint . --ext .js,.jsx,.ts,.tsx --fix --ignore-path .gitignore",
"postinstall": "npx jetify && chmod +x ./scripts/fix-rn-camera-path.sh && ./scripts/fix-rn-camera-path.sh ./node_modules/react-native-camera/ios/RNCamera.xcodeproj/project.pbxproj",
"start": "NODE_OPTIONS=--max_old_space_size=8192 react-native start",
"test": "jest",
"test:debug": "node --inspect node_modules/.bin/jest --watch --runInBand",
"unit": "jest --config ./test/unit/jest.config.js",
"unit:debug": "node --inspect node_modules/.bin/jest --watch --runInBand",
"test-rust": "cd ./rust/signer && cargo test && cd ../..",
"build-e2e:android": "detox build -c android.emu.debug -l info",
"test-e2e:android": "detox test -c android.emu.debug -l info --noStackTrace",
Expand Down Expand Up @@ -83,13 +83,13 @@
"@types/jest": "^25.1.3",
"@types/react": "^16.9.19",
"@types/react-native": "^0.61.10",
"@typescript-eslint/eslint-plugin": "^2.15.0",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.15.0",
"babel-eslint": "10.0.3",
"babel-jest": "^25.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-rewrite-require": "^1.14.5",
"detox": "^14.7.0",
"detox": "^15.4.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.2.0",
"eslint-import-resolver-typescript": "^2.0.0",
Expand Down Expand Up @@ -124,7 +124,7 @@
},
"ios.sim.release": {
"binaryPath": "ios/build/NativeSigner/Build/Products/Release-iphonesimulator/NativeSigner.app",
"build": "xcodebuild -project ios/NativeSigner.xcodeproj -scheme NativeSigner -configuration Release -sdk iphonesimulator -derivedDataPath ios/build/NativeSigner -UseModernBuildSystem=NO | xcpretty -t && exit ${PIPESTATUS[0]}",
"build": "xcodebuild -project ios/NativeSigner.xcodeproj -scheme NativeSigner -configuration Release -sdk iphonesimulator -derivedDataPath ios/build/NativeSigner -UseModernBuildSystem=YES | xcpretty -t && exit ${PIPESTATUS[0]}",
"type": "ios.simulator",
"device": {
"type": "iPhone SE"
Expand All @@ -147,7 +147,7 @@
}
}
},
"runner-config": "e2e/config.json",
"runner-config": "test/e2e/jest.config.js",
"test-runner": "jest"
}
}
32 changes: 6 additions & 26 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import '../shim';

import * as React from 'react';
import { Platform, StatusBar, View, YellowBox } from 'react-native';
import { StatusBar, View, YellowBox } from 'react-native';
import {
createAppContainer,
createSwitchNavigator,
Expand Down Expand Up @@ -67,38 +67,18 @@ import TermsAndConditions from 'screens/TermsAndConditions';
import TxDetails from 'screens/TxDetails';
import LegacyNetworkChooser from 'screens/LegacyNetworkChooser';
import testIDs from 'e2e/testIDs';
import { AppProps, getLaunchArgs } from 'e2e/injections';

const getLaunchArgs = (props: Props): void => {
if (Platform.OS === 'ios') {
if (
Array.isArray(props.launchArgs) &&
props.launchArgs.includes('-detoxServer')
) {
global.inTest = true;
return;
}
} else {
if (props.launchArgs && props.launchArgs.hasOwnProperty('detoxServer')) {
global.inTest = true;
return;
}
}
global.inTest = false;
};

interface Props {
launchArgs?: Array<string> | object;
}

export default class App<Props> extends React.Component<Props> {
constructor(props: Props) {
export default class App extends React.Component<AppProps> {
constructor(props: AppProps) {
super(props);
getLaunchArgs(props);
if (__DEV__) {
YellowBox.ignoreWarnings([
'Warning: componentWillReceiveProps',
'Warning: componentWillMount',
'Warning: componentWillUpdate'
'Warning: componentWillUpdate',
'Warning: Sending `onAnimatedValueUpdate`'
]);
}
}
Expand Down
35 changes: 19 additions & 16 deletions src/screens/AccountNetworkChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
NetworkParams,
SubstrateNetworkParams,
isSubstrateNetworkParams,
EthereumNetworkParams
isEthereumNetworkParams
} from 'types/networkSpecsTypes';
import { NavigationAccountProps } from 'types/props';

Expand Down Expand Up @@ -258,21 +258,24 @@ function AccountNetworkChooser({
<View style={styles.body}>
{renderScreenHeading()}
<ScrollView testID={testIDs.AccountNetworkChooser.chooserScreen}>
{networkList.map(([networkKey, networkParams]) => (
<NetworkCard
key={networkKey}
testID={
testIDs.AccountNetworkChooser.networkButton +
(networkParams as SubstrateNetworkParams).pathId ||
(networkParams as EthereumNetworkParams).ethereumChainId
}
networkKey={networkKey}
onPress={(): Promise<void> =>
onNetworkChosen(networkKey, networkParams)
}
title={networkParams.title}
/>
))}
{networkList.map(([networkKey, networkParams]) => {
const networkIndexSuffix = isEthereumNetworkParams(networkParams)
? networkParams.ethereumChainId
: networkParams.pathId;
return (
<NetworkCard
key={networkKey}
testID={
testIDs.AccountNetworkChooser.networkButton + networkIndexSuffix
}
networkKey={networkKey}
onPress={(): Promise<void> =>
onNetworkChosen(networkKey, networkParams)
}
title={networkParams.title}
/>
);
})}
{renderAddButton()}
</ScrollView>
</View>
Expand Down
3 changes: 3 additions & 0 deletions src/screens/MessageDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React from 'react';
import { ScrollView, StyleSheet, Text } from 'react-native';
import { Subscribe } from 'unstated';

import testIDs from 'e2e/testIDs';
import { NETWORK_LIST } from 'constants/networkSpecs';
import { FoundAccount } from 'types/identityTypes';
import {
Expand Down Expand Up @@ -150,6 +151,7 @@ export class MessageDetailsView extends React.PureComponent<Props> {
<ScrollView
contentContainerStyle={styles.bodyContent}
style={styles.body}
testID={testIDs.MessageDetails.scrollScreen}
>
<Background />
<Text style={styles.topTitle}>Sign Message</Text>
Expand All @@ -169,6 +171,7 @@ export class MessageDetailsView extends React.PureComponent<Props> {
/>
<Button
buttonStyles={styles.signButton}
testID={testIDs.MessageDetails.signButton}
title="Sign Message"
onPress={(): void => {
isHash ? alertMultipart(onNext) : onNext();
Expand Down
6 changes: 3 additions & 3 deletions src/screens/QrScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Alert, Button, StyleSheet, Text, View } from 'react-native';
import { RNCamera } from 'react-native-camera';
import { Subscribe } from 'unstated';

import { createMockSignRequest } from 'e2e/mock';
import { onMockBarCodeRead } from 'e2e/injections';
import { NavigationProps, NavigationScannerProps } from 'types/props';
import colors from 'styles/colors';
import fonts from 'styles/fonts';
Expand Down Expand Up @@ -148,8 +148,8 @@ function QrScannerView({
scannerStore,
...props
}: ViewProps): React.ReactElement {
if (global.inTest) {
props.onBarCodeRead(createMockSignRequest());
if (global.inTest && global.scanRequest !== undefined) {
onMockBarCodeRead(global.scanRequest, props.onBarCodeRead);
}

useEffect((): (() => void) => {
Expand Down
7 changes: 5 additions & 2 deletions src/screens/SignedMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { useEffect } from 'react';
import { ScrollView, StyleSheet, Text } from 'react-native';
import { ScrollView, StyleSheet, Text, View } from 'react-native';

import testIDs from 'e2e/testIDs';
import { NavigationScannerProps } from 'types/props';
import colors from 'styles/colors';
import QrView from 'components/QrView';
Expand All @@ -42,7 +43,9 @@ function SignedMessage({
return (
<ScrollView style={styles.body}>
<Text style={styles.topTitle}>Signed Message</Text>
<QrView data={data} />
<View testID={testIDs.SignedMessage.qrView}>
<QrView data={data} />
</View>
<MessageDetailsCard
isHash={isHash}
message={message ?? ''}
Expand Down
19 changes: 19 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

/* eslint-disable @typescript-eslint/no-unused-vars */
import { ScanTestRequest } from 'e2e/mockScanRequests';
export {};

/*~ If the app has properties exposed on a global variable,
Expand All @@ -9,6 +27,7 @@ declare global {
namespace NodeJS {
interface Global {
inTest: boolean;
scanRequest?: ScanTestRequest;
}
}
// declare webpack modules
Expand Down
Loading