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

feat:add sync test #3026

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
81 changes: 80 additions & 1 deletion .github/workflows/package_for_test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Package Neuron for Test

on:
on:
issue_comment:
types: [created, edited]
push:
Expand Down Expand Up @@ -238,3 +238,82 @@ jobs:
comment-id: ${{ github.event.comment.id }}
body: Packageing failed in [${{ github.run_id }}](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). @${{ github.event.comment.user.login }}
edit-mode: append

sync-test:
if: ${{ (github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/package -test')) || github.event_name == 'push' }}
needs: [packaging]
strategy:
matrix:
node:
- 18.12.0
os:
- macos-latest
- ubuntu-20.04
- windows-2019

runs-on: ${{ matrix.os }}

name: ${{ matrix.os }}(Node.js ${{ matrix.node }})

steps:
- name: Checkout
uses: actions/checkout@v3


- name: Install libudev
if: matrix.os == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev
- name: Download Neuron App Zip(x64)
if: matrix.os == 'macos-latest'
uses: actions/download-artifact@v4
with:
name: Neuron-Mac-x64
path: packages/sync-test

- name: Download Neuron Win
if: matrix.os == 'windows-2019'
uses: actions/download-artifact@v4
with:
name: Neuron-Win
path: packages/sync-test

- name: Download Neuron Linux
if: matrix.os == 'ubuntu-20.04'
uses: actions/download-artifact@v4
with:
name: Neuron-Linux
path: packages/sync-test

- name: macos run
if: matrix.os == 'macos-latest'
run: |
cd packages/sync-test
yarn
bash scripts/prepare_neuron_macos.sh
yarn sync-test
- name: Windows run
if: matrix.os == 'windows-2019'
run: |
cd packages\sync-test
yarn
.\scripts\prepare_neuron_windows.bat
yarn sync-test
- name: ubuntu run
if: matrix.os == 'ubuntu-20.04'
run: |
cd packages/sync-test
yarn
bash scripts/prepare_neuron_linux.sh
xvfb-run --auto-servernum yarn sync-test
- name: tar result
if: always()
run: |
tar -zcvf tmp.${{ matrix.os }}.tar.gz packages/sync-test/tmp
- name: Publish reports
if: failure()
uses: actions/upload-artifact@v3
with:
name: jfoa-build-reports-${{ runner.os }}
path: tmp.${{ matrix.os }}.tar.gz
1 change: 1 addition & 0 deletions packages/sync-test/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.config.js
59 changes: 59 additions & 0 deletions packages/sync-test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
settings: {
'import/resolver': {
node: {
paths: ['src'],
extensions: ['.js', '.ts'],
},
},
},
env: {
es6: true,
node: true,
browser: true,
jest: true,
},
globals: {
BigInt: 'readonly',
},
rules: {
// TODO: Some temporarily disabled rules will be re-enabled later, considering that many files are affected and will be addressed in the future.
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'prefer-const': 'off',

// This is the configuration that was set when using eslint-plugin-prettier
// https://github.com/prettier/eslint-plugin-prettier#arrow-body-style-and-prefer-arrow-callback-issue
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',

// TypeScript support
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
},
],

// Unnecessary rules
'no-plusplus': 'off',
'max-classes-per-file': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': 'warn',
'no-console': 'off',
// Adjusted rules
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
},
overrides: [
{
files: ['*.test.ts', '*.test.tsx'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'no-console': 'off',
},
},
],
}
11 changes: 11 additions & 0 deletions packages/sync-test/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
tabWidth: 2,
useTabs: false,
printWidth: 120,
trailingComma: 'es5',
semi: false,
singleQuote: true,
// TODO: This is the previous legacy configuration, should use the default settings, considering that more files are affected, and will be dealt with later.
// https://prettier.io/blog/2020/03/21/2.0.0.html#change-default-value-for-arrowparens-to-always-7430httpsgithubcomprettierprettierpull7430-by-kachkaevhttpsgithubcomkachkaev
arrowParens: 'avoid',
}
9 changes: 9 additions & 0 deletions packages/sync-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# sync-test

notice: will remove your neuron config data

```shell
./scripts/prepare_neuron_macos.sh
yarn
yarn test
```
21 changes: 21 additions & 0 deletions packages/sync-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
process.env = Object.assign(process.env, { NODE_ENV: undefined })

module.exports = {
displayName: 'Unit Tests',
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: '(/tests/.*.(test|spec))\\.(ts?|js?)$',
transform: {
'^.+\\.ts?$': 'ts-jest',
},
roots: ['<rootDir>/src/'],
moduleDirectories: ['node_modules', 'src'],
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
// setupFiles: ['<rootDir>/tests/setup.ts'],
moduleNameMapper: {
// FIXME: module mapper causes typeorm errors
// "electron": "<rootDir>/tests/mock/electron.ts",
// "logger": "<rootDir>/tests/mock/logger",
},
testTimeout: 1800000,
}
23 changes: 23 additions & 0 deletions packages/sync-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "sync-test",
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"homepage": "https://www.nervos.org/",
"version": "0.112.0",
"private": true,
"author": {
"name": "Nervos Core Dev",
"email": "[email protected]",
"url": "https://github.com/nervosnetwork/neuron"
},
"repository": {
"type": "git",
"url": "https://github.com/nervosnetwork/neuron"
},
"scripts": {
"sync-test": "jest demo.test.ts"
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"@types/tar": "6.1.10"
}
}
7 changes: 7 additions & 0 deletions packages/sync-test/scripts/prepare_neuron_linux.sh
Keith-CY marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#wget http://github-test-logs.ckbapp.dev/neuron/sync/Neuron-v0.111.1-x86_64.AppImage
cp Neuron-*.AppImage Neuron.AppImage
chmod 777 Neuron.AppImage
./Neuron.AppImage --appimage-extract
mkdir neuron
mv squashfs-root neuron
cp -r neuron/squashfs-root/bin source/
6 changes: 6 additions & 0 deletions packages/sync-test/scripts/prepare_neuron_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#wget http://github-test-logs.ckbapp.dev/neuron/sync/Neuron-v0.111.1-mac-x64.zip
cp Neuron*.zip Neuron.zip
unzip Neuron.zip
mv Neuron.app neuron
chmod 777 neuron/Contents
cp -r neuron/Contents/bin source/
6 changes: 6 additions & 0 deletions packages/sync-test/scripts/prepare_neuron_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@REM curl -O -L http://github-test-logs.ckbapp.dev/neuron/sync/Neuron-v0.111.1-setup.exe
move .\Neuron-*.exe Neuron-setup.exe
.\Neuron-setup.exe /S /D=D:\a\neuron\neuron\packages\sync-test\neuron
mkdir ".\source\bin"
copy ".\neuron\bin\ckb.exe" ".\source\bin\ckb.exe"
copy ".\neuron\bin\ckb-light-client.exe" ".\source\bin\ckb-light-client.exe"
Binary file added packages/sync-test/source/ckb-data/db.2000.tar.gz
Binary file not shown.
47 changes: 47 additions & 0 deletions packages/sync-test/source/ckb-light-client/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# chain = "mainnet"
# chain = "testnet"
# chain = "your_path_to/dev.toml"
chain = "../ckb/specs/dev.toml"

[store]
path = "data/store"

[network]
path = "data/network"

listen_addresses = ["/ip4/0.0.0.0/tcp/8118"]
### Specify the public and routable network addresses
# public_addresses = []

# Node connects to nodes listed here to discovery other peers when there's no local stored peers.
# When chain.spec is changed, this usually should also be changed to the bootnodes in the new chain.
bootnodes = ["/ip4/127.0.0.1/tcp/8115/p2p/QmShJCAx1RzpEDFwBuQ6noqViNgNuYrYv2KCRhxmNQCe5J"]

### Whitelist-only mode
# whitelist_only = false
### Whitelist peers connecting from the given IP addresses
# whitelist_peers = []

### Enable `SO_REUSEPORT` feature to reuse port on Linux, not supported on other OS yet
# reuse_port_on_linux = true

max_peers = 125
max_outbound_peers = 2
# 2 minutes
ping_interval_secs = 120
# 20 minutes
ping_timeout_secs = 1200
connect_outbound_interval_secs = 15
# If set to true, try to register upnp
upnp = false
# If set to true, network service will add discovered local address to peer store, it's helpful for private net development
discovery_local_address = false
# If set to true, random cleanup when there are too many inbound nodes
# Ensure that itself can continue to serve as a bootnode node
bootnode_mode = false

[rpc]
# Light client rpc is designed for self hosting, exposing to public network is not recommended and may cause security issues.
# By default RPC only binds to localhost, thus it only allows accessing from the same machine.
listen_address = "127.0.0.1:9000"

29 changes: 29 additions & 0 deletions packages/sync-test/source/ckb/ckb-miner.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

data_dir = 'data'

[chain]

spec = { file = 'specs/dev.toml' }

[logger]

filter = 'info'
color = true
log_to_file = true
log_to_stdout = true

[sentry]

dsn = ''

[miner.client]

rpc_url = 'http://127.0.0.1:8114'
block_on_submit = true
poll_interval = 500

[[miner.workers]]

worker_type = 'Dummy'
delay_type = 'Constant'
value = 500
76 changes: 76 additions & 0 deletions packages/sync-test/source/ckb/ckb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

data_dir = 'data'

[chain]

spec = { file = 'specs/dev.toml' }

[logger]

filter = 'info'
color = true
log_to_file = true
log_to_stdout = true

[sentry]

dsn = ''

[db]

cache_size = 134217728
options_file = 'default.db-options'

[network]

listen_addresses = ['/ip4/0.0.0.0/tcp/8115']
bootnodes = []
max_peers = 125
max_outbound_peers = 8
ping_interval_secs = 120
ping_timeout_secs = 1200
connect_outbound_interval_secs = 15
upnp = false
discovery_local_address = true
bootnode_mode = false
support_protocols = ['Ping', 'Discovery', 'Identify', 'Feeler', 'DisconnectMessage', 'Sync', 'Relay', 'Time', 'Alert', 'LightClient', 'Filter']

[rpc]

listen_address = '127.0.0.1:8114'
max_request_body_size = 10485760
modules = [
'Net',
'Pool',
'Miner',
'Chain',
'Stats',
'Subscription',
'Experiment',
'Debug',
'Indexer',
]
reject_ill_transactions = true
enable_deprecated_rpc = false

[tx_pool]

max_tx_pool_size = 180000000
min_fee_rate = 1000
max_tx_verify_cycles = 70000000
max_ancestors_count = 25

[store]

header_cache_size = 4096
cell_data_cache_size = 128
block_proposals_cache_size = 30
block_tx_hashes_cache_size = 30
block_uncles_cache_size = 30

[block_assembler]

code_hash = '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8'
args = '0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7'
hash_type = 'type'
message = '0x'
Loading
Loading