Skip to content

Commit

Permalink
feat: merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Jun 28, 2024
2 parents 02f8088 + 2b4e1be commit 8faef74
Show file tree
Hide file tree
Showing 49 changed files with 4,020 additions and 488 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Coverage Diff

on:
push:
branches:
- master
pull_request: {}

jobs:
test:
name: Coverage Diff
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 20
cache: yarn
- run: yarn install
- run: yarn run test:coverage
- name: Coverage Diff
uses: greatwizard/coverage-diff-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid",
"proseWrap": "always",
"endOfLine": "auto"
}
4 changes: 4 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
"presets": ["@babel/preset-env"],
"plugins": [ "babel-plugin-transform-import-meta", ["@babel/plugin-syntax-import-attributes", { "deprecatedAssertSyntax": true }]]
}
3 changes: 1 addition & 2 deletions bin/aelf-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ process.on('uncaughtException', err => {
logger.fatal(err.message || err);
process.exit(1);
});

run();
run(process.argv);
66 changes: 33 additions & 33 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import globals from "globals";
import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import { fileURLToPath } from "url";
import { fixupPluginRules } from "@eslint/compat";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import babelParser from "@babel/eslint-parser";
import globals from 'globals';
import { FlatCompat } from '@eslint/eslintrc';
import path from 'path';
import { fileURLToPath } from 'url';
import { fixupPluginRules } from '@eslint/compat';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import babelParser from '@babel/eslint-parser';

// mimic CommonJS variables -- not needed if using CommonJS
const __filename = fileURLToPath(import.meta.url);
Expand All @@ -13,7 +13,7 @@ const compat = new FlatCompat({
baseDirectory: __dirname
});

function legacyPlugin(name,alias = name) {
function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias];

if (!plugin) {
Expand All @@ -23,58 +23,58 @@ function legacyPlugin(name,alias = name) {
return fixupPluginRules(plugin);
}


export default [
eslintPluginPrettierRecommended,
{
plugins: {
import: legacyPlugin("eslint-plugin-import","import"),
import: legacyPlugin('eslint-plugin-import', 'import')
},
files: ["**/*.js", "**/*.mjs"],
files: ['**/*.js', '**/*.mjs'],
languageOptions: {
globals: {
...globals.es6,
...globals.node,
...globals.jest,
myCustomGlobal: "readonly"
myCustomGlobal: 'readonly'
},
parser: babelParser,
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
babelrc: false,
configFile: false,
presets: ["@babel/preset-env"],
plugins: ["@babel/plugin-syntax-import-assertions"]
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-syntax-import-assertions']
}
}
},
rules: {
"no-console": ["warn"],
"no-useless-escape": 0,
"no-empty": 0,
"comma-dangle": 0,
"arrow-parens": ["error","as-needed"],
"import/prefer-default-export": "off",
"import/no-cycle": "off",
"no-underscore-dangle": "off",
"no-bitwise": "off",
"no-mixed-operators": "off",
"max-len": ["error",{ "code": 130 }],
"class-methods-use-this": "off",
"no-plusplus": "off",
"prettier/prettier": [
"error",
'no-console': ['warn'],
'no-useless-escape': 0,
'no-empty': 0,
'comma-dangle': 0,
'arrow-parens': ['error', 'as-needed'],
'import/prefer-default-export': 'off',
'import/no-cycle': 'off',
'no-underscore-dangle': 'off',
'no-bitwise': 'off',
'no-mixed-operators': 'off',
'max-len': ['error', { code: 130 }],
'class-methods-use-this': 'off',
'no-plusplus': 'off',
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'none',
arrowParens: 'avoid',
proseWrap: 'always',
endOfLine: 'auto',
endOfLine: 'auto'
}
]
},
ignores: ["scripts","examples","test","jest.config.js"]
}];
ignores: ['scripts', 'examples', 'test', 'jest.config.js']
}
];
50 changes: 23 additions & 27 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
const path = require('path');
import path from 'path';
process.env.RUNTIME_ENV = 'node';

module.exports = {
export default {
// All imported modules in your tests should be mocked automatically
// automock: false,

Expand All @@ -30,17 +30,10 @@ module.exports = {
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns: ['/node_modules/', '/src/utils/constants.js', '/src/command/index.js'],

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
coverageReporters: ['text', 'json-summary'],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: null,
Expand All @@ -64,9 +57,9 @@ module.exports = {
// globals: {},

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: [
'node_modules'
],
// moduleDirectories: [
// 'node_modules'
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
Expand All @@ -79,9 +72,9 @@ module.exports = {
// ],

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
'^scryptsy$': path.resolve('src/scrypt-polyfill.js')
},
// moduleNameMapper: {
// '^scryptsy$': path.resolve('src/scrypt-polyfill.js')
// },

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],
Expand Down Expand Up @@ -143,10 +136,13 @@ module.exports = {
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
testMatch: [
// '**/test/utils/Logger.test.js'
'**/test/command/dappServer/socket-sign.test.js',
'**/test/**/?(*.)+(spec|test).[jt]s?(x)'
// "**/?(*.)+(spec|test).[tj]s?(x)"
],
testTimeout: 20000,

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
Expand All @@ -169,14 +165,14 @@ module.exports = {
// timers: "real",

// A map from regular expressions to paths to transformers
// transform: {
// '^.+\\.js?$': 'babel-jest'
// }
transform: {
'^.+\\.js?$': 'babel-jest'
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/"
// ],
transformIgnorePatterns: [
// "/node_modules/(?!chalk|update-notifier|configstore|xdg-basedir|unique-string|crypto-random-string|semver-diff|latest-version|package-json|got|@sindresorhus|p-cancelable|@szmarczak/http-timer|cacheable-request|normalize-url|responselike|lowercase-keys|mimic-response|form-data-encoder)"
]

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-command",
"version": "0.1.47-beta.3",
"version": "0.1.47-beta.4",
"description": "A CLI tools for AElf",
"main": "src/index.js",
"type": "module",
Expand All @@ -9,7 +9,9 @@
"commit": "git-cz",
"lint": "eslint src",
"release": "standard-version",
"test": "npx cross-env NODE_ENV=test jest",
"test": "jest --config=jest.config.js --detectOpenHandles",
"test:watch": "jest --config=jest.config.js --watch --detectOpenHandles",
"test:coverage": "jest --config=jest.config.js --coverage --detectOpenHandles",
"prepare": "husky",
"lint-staged": "lint-staged",
"tsc": "tsc"
Expand Down Expand Up @@ -42,8 +44,12 @@
},
"engineStrict": true,
"dependencies": {
"@babel/core": "^7.24.6",
"@babel/plugin-syntax-import-attributes": "^7.24.6",
"@babel/preset-env": "^7.24.6",
"aelf-sdk": "^3.4.12",
"async-validator": "^4.2.5",
"babel-plugin-transform-import-meta": "^2.2.1",
"boxen": "^7.1.1",
"camelcase": "^8.0.0",
"chalk": "^5.3.0",
Expand Down Expand Up @@ -79,6 +85,7 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "^9.3.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-prettier": "^5.1.3",
Expand All @@ -88,7 +95,8 @@
"lint-staged": "^15.2.5",
"prettier": "^3.3.2",
"standard-version": "^9.5.0",
"typescript": "^5.5.2"
"typescript": "^5.5.2",
"socket.io-client": "^4.7.5"
},
"keywords": [
"AElf",
Expand All @@ -109,6 +117,9 @@
"collectCoverageFrom": [
"src/**/*.js"
],
"transform": {
"^.+\\.js$": "babel-jest"
},
"testEnvironment": "node"
}
}
5 changes: 2 additions & 3 deletions src/command/baseSubCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { interopImportCJSDefault } from 'node-cjs-interop';
import asyncValidator from 'async-validator';
const Schema = interopImportCJSDefault(asyncValidator);

import inquirer from 'inquirer';
import ora from 'ora';
import { logger } from '../utils/myLogger.js';
Expand Down Expand Up @@ -142,7 +141,7 @@ class BaseSubCommand {
const lastArg = args.slice(this.parameters.length)[0];
const localOptions = {};
this.options.forEach(({ name }) => {
localOptions[name] = lastArg[name] || undefined;
localOptions[name] = lastArg?.[name] || undefined;
});
const uniOptions = BaseSubCommand.getUniConfig(commander);
// get options from global config and process.argv
Expand All @@ -153,7 +152,7 @@ class BaseSubCommand {
});

const globalPrompts = globalOptionsPrompts.filter(
prompt => this.validatorDesc[prompt.name].required && !options[prompt.name]
prompt => this.validatorDesc[prompt.name]?.required && !options[prompt.name]
);
const globalPromptsAns = await inquirer.prompt(globalPrompts);
options = {
Expand Down
3 changes: 0 additions & 3 deletions src/command/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { interopImportCJSDefault } from 'node-cjs-interop';
import asyncValidator from 'async-validator';
const Schema = interopImportCJSDefault(asyncValidator);

import BaseSubCommand from './baseSubCommand.js';
import { configCommandParameters, configCommandUsage, commonGlobalOptionValidatorDesc } from '../utils/constants.js';
import { logger } from '../utils/myLogger.js';
Expand Down Expand Up @@ -100,8 +99,6 @@ class ConfigCommand extends BaseSubCommand {
result = this.rc.deleteConfig(key);
this.oraInstance.succeed('Succeed!');
break;
default:
throw new Error(`${flag} is not a valid flag, must one of set, get, list, delete`);
}
} catch (e) {
this.oraInstance.fail('Failed!');
Expand Down
13 changes: 7 additions & 6 deletions src/command/dappServer/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,11 @@ class Socket {
}

serializeResult(appId, result) {
if (!this.clientConfig[appId]) {
throw new Error(`AppId ${appId} has not connected`);
}
if (this.clientConfig[appId].encryptWay === 'sign') {
// delete next line as function deserializeParams already has the logic
// if (!this.clientConfig[appId]) {
// throw new Error(`AppId ${appId} has not connected`);
// }
if (this.clientConfig[appId]?.encryptWay === 'sign') {
const originalResult = serializeMessage(result);
const signature = this.clientConfig[appId].encrypt.sign(Buffer.from(originalResult, 'base64'));
return {
Expand All @@ -263,7 +264,7 @@ class Socket {
};
}
const originalResult = serializeMessage(result);
return this.clientConfig[appId].encrypt.encrypt(originalResult);
return this.clientConfig[appId]?.encrypt.encrypt(originalResult);
}

async handleConnect(message) {
Expand Down Expand Up @@ -362,7 +363,7 @@ class Socket {
};
}

async handleInvoke(message, isReadOnly = false) {
async handleInvoke(message, isReadOnly) {
const params = await this.deserializeParams(message);
const { endpoint = this.defaultEndpoint, contractAddress, contractMethod, arguments: contractArgs } = params;
logger.info(`${isReadOnly ? 'Calling' : 'Sending'} contract ${contractAddress} method ${contractMethod}...`);
Expand Down
Loading

0 comments on commit 8faef74

Please sign in to comment.