Skip to content

Commit

Permalink
Feat/x core api ADA (#3676)
Browse files Browse the repository at this point in the history
* feat: core chain ada & jest

* fix: yarn 3.5.0
  • Loading branch information
sidmorizon authored Oct 19, 2023
1 parent 5b43668 commit 1fdd7cc
Show file tree
Hide file tree
Showing 75 changed files with 34,613 additions and 19,359 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const tsRules = {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/require-await': 'off',
'sort-imports': [
'error',
{
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ __generated__
.DS_Store
.idea/
.vscode/
.chat/
packages/core/src/chains/_x/

dist
build-electron
Expand Down
873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.5.0.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.5.0.cjs
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"dependencies": {
"@onekeyhq/components": "*",
"@onekeyhq/shared": "*",
"@onekeyhq/kit": "*",
"@onekeyhq/shared": "*",
"adm-zip": "^0.5.10",
"electron-config": "^2.0.0",
"electron-context-menu": "^3.5.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"private": true,
"dependencies": {
"@onekeyhq/components": "*",
"@onekeyhq/shared": "*",
"@onekeyhq/kit": "*"
"@onekeyhq/kit": "*",
"@onekeyhq/shared": "*"
}
}
30 changes: 15 additions & 15 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@
"@formatjs/intl-locale": "^2.4.47",
"@formatjs/intl-pluralrules": "^4.3.3",
"@onekeyhq/components": "*",
"@onekeyhq/shared": "*",
"@onekeyhq/kit": "*",
"@onekeyhq/shared": "*",
"@react-native-async-storage/async-storage": "1.18.2",
"burnt": "0.12",
"expo": "~49.0.13",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"expo-device": "~5.4.0",
"expo-haptics": "^12.2.1",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"js-base64": "^3.7.5",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-reanimated": "^3.5.4",
"react-native-gesture-handler": "^2.10.1",
"react-native-uuid": "^2.0.1",
"uuid": "^3.0.0",
"lottie-react": "^2.4.0",
"lottie-react-native": "^6.3.0",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-device-info": "^10.8.0",
"react-native-safe-area-context": "^4.7.2",
"react-native-file-logger": "^0.4.1",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "^2.10.1",
"react-native-get-random-values": "^1.9.0",
"react-native-svg": "^13.9.0",
"react-native-keyboard-manager": "^6.5.11-1",
"react-native-mmkv": "^2.8.0",
"react-native-reanimated": "^3.5.4",
"react-native-safe-area-context": "^4.7.2",
"react-native-screens": "^3.25.0",
"react-native-fs": "^2.20.0",
"react-native-file-logger": "^0.4.1",
"react-native-keyboard-manager": "^6.5.11-1",
"react-native-svg": "^13.9.0",
"react-native-uuid": "^2.0.1",
"react-native-zip-archive": "^6.0.9",
"text-encoding": "^0.7.0"
"text-encoding": "^0.7.0",
"uuid": "^3.0.0"
},
"workspaces": {
"nohoist": [
Expand Down
4 changes: 2 additions & 2 deletions apps/web-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"private": true,
"dependencies": {
"@onekeyhq/components": "*",
"@onekeyhq/shared": "*",
"@onekeyhq/kit": "*"
"@onekeyhq/kit": "*",
"@onekeyhq/shared": "*"
}
}
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"dependencies": {
"@onekeyhq/components": "*",
"@onekeyhq/shared": "*",
"@onekeyhq/kit": "*"
"@onekeyhq/kit": "*",
"@onekeyhq/shared": "*"
},
"private": true
}
76 changes: 76 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// require('react-native-reanimated').setUpTests();

// FIX: ReferenceError: self is not defined
global.self = global.self || global;

class LocalStorageMock {
constructor() {
this.store = {};
}

clear() {
this.store = {};
}

getItem(key) {
return this.store[key] || null;
}

setItem(key, value) {
this.store[key] = String(value);
}

removeItem(key) {
delete this.store[key];
}
}

global.localStorage = new LocalStorageMock();
global.$$onekeyAppStorage = new LocalStorageMock();
global.fetch = require('node-fetch');
global.WebSocket = require('isomorphic-ws');

jest.mock('react-native-zip-archive', () => ({
zip: jest.fn(),
}));

jest.mock('react-native-file-logger', () => ({
FileLogger: {
configure: jest.fn(),
write: jest.fn(),
},
LogLevel: {
Debug: 0,
Info: 1,
Warning: 2,
Error: 3,
},
}));

jest.mock('react-native-device-info', () => ({
getBuildNumber: jest.fn(),
getDeviceId: jest.fn(),
getIncrementalSync: jest.fn(),
getModel: jest.fn(),
getSystemName: jest.fn(),
getSystemVersion: jest.fn(),
getTotalMemorySync: jest.fn(),
getUsedMemorySync: jest.fn(),
}));

// ** shim TextEncoder
// const { TextEncoder, TextDecoder } = require('util');
// global.TextEncoder = TextEncoder;
// global.TextDecoder = TextDecoder;

// ** shim App variables
// require('./packages/app/shim');

// ** Array, Buffer, Error
// https://github.com/facebook/jest/issues/2549

// ** asm.js support
// Linking failure in asm.js: Unexpected stdlib member

// ** await import() support
// Error: You need to run with a version of node that supports ES Modules in the VM API. See https://jestjs.io/docs/ecmascript-modules
65 changes: 65 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// https://jestjs.io/docs/configuration
const { defaults } = require('jest-config');
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);

module.exports = async () => {
const { stdout } = await exec('yarn config get cacheFolder');
const cacheDirectory = stdout.trim().replace('\n', '');
return {
// ts-jest, react-native, jest-expo, jest-expo/web,
preset: 'jest-expo/web', // require *.web.ts, do not require *.native.ts
coverageProvider: 'v8',
cacheDirectory: `${cacheDirectory}/.app-mono-jest-cache`,
setupFilesAfterEnv: [
'./jest-setup.js',
'./node_modules/react-native-gesture-handler/jestSetup.js',
],
// buffer type incorrect if use [jsdom] https://github.com/facebook/jest/issues/4422
// jest-environment-node, node, jsdom
testEnvironment: 'jest-environment-node',
verbose: true,
moduleFileExtensions: [
...defaults.moduleFileExtensions,
'd.ts',
'jest.ts', // not working
'jest.tsx',
'ts',
'tsx',
],
// 'extensionsToTreatAsEsm': ['.wasm', '.ts'],
// 'globals': {
// 'ts-jest': {
// 'useESM': true,
// },
// },
moduleNameMapper: {
// '^(\\.{1,2}/.*/cardano_message_signing_bg\\.wasm\\.js)$': '$1',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
'@onekeyhq/kit/src/background/instance/backgroundApiProxy':
'<rootDir>/__mocks__/backgroundApiProxyMock.js',
'@emurgo/cardano-serialization-lib-browser':
'@emurgo/cardano-serialization-lib-nodejs',
'@emurgo/cardano-message-signing-browser':
'@emurgo/cardano-message-signing-nodejs',
'\\./adaWebSdk$':
'<rootDir>/packages/core/src/chains/ada/sdkAda/sdk/adaWebSdk.jest.ts',
},
// TODO unify with transpile modules
transformIgnorePatterns: ['nodo_modules/react-native-reanimated'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
reporters: [
'default',
[
'./node_modules/jest-html-reporter',
{
'pageTitle': 'Test Report',
},
],
],
};
};
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-env": "^7.22.9",
"@emurgo/cardano-message-signing-nodejs": "^1.0.1",
"@emurgo/cardano-serialization-lib-nodejs": "^11.5.0",
"@expo/webpack-config": "^18.1.3",
"@open-wc/webpack-import-meta-loader": "^0.4.7",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
"@tamagui/babel-plugin": "1.71.0",
"@types/chrome": "^0.0.248",
"@types/elliptic": "^6.4.16",
"@types/jest": "^29.5.6",
"@types/lodash": "^4.14.200",
"@types/memoizee": "^0.4.10",
"@types/react": "^18.2.29",
Expand Down Expand Up @@ -101,6 +105,9 @@
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"html-webpack-plugin": "^5.5.3",
"jest": "^29.7.0",
"jest-expo": "^49.0.0",
"jest-html-reporter": "^3.10.2",
"node-notifier": "^10.0.1",
"patch-package": "^7.0.0",
"prettier": "^2.8.1",
Expand All @@ -109,12 +116,17 @@
"react-refresh": "^0.14.0",
"style-loader": "^3.3.3",
"tamagui-loader": "1.71.0",
"ts-jest": "^29.1.1",
"ultra-runner": "^3.10.5",
"webpack": "5.88.2",
"webpack-bundle-analyzer": "^4.9.1",
"webpack-cli": "5.1.4",
"webpack-dev-server": "^4.15.1",
"webpack-manifest-plugin": "^5.0.0",
"webpack-subresource-integrity": "^5.2.0-rc.1"
}
},
"resolutions": {
"tronweb@^5.1.0": "5.1.0"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit 1fdd7cc

Please sign in to comment.