Skip to content

Commit

Permalink
feat: add e2e-test package (ckb-js#431)
Browse files Browse the repository at this point in the history
* feat: add e2e-test pkg

* chore: update workflow for download docke r images

* feat: add e2e provider
  • Loading branch information
PainterPuppets authored Oct 9, 2022
1 parent 01fea3f commit 6f07ea0
Show file tree
Hide file tree
Showing 17 changed files with 937 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
run: |
yarn --ignore-engines --frozen-lockfile
yarn build
docker-compose -f ./packages/e2e-test/docker/docker-compose.yml build
- name: e2e test
run: yarn e2e-test

Expand Down
7 changes: 7 additions & 0 deletions packages/e2e-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/lib
/indexer-store*
ckb-indexer*
COPYING
nohup.out
tmp/*
!tmp/.gitkeep
15 changes: 15 additions & 0 deletions packages/e2e-test/docker/ckb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM nervos/ckb:v0.103.0

ENV CKB_CHAIN=dev
ENV BA_ARG=0x839f6f4d6fdf773d3e015f8b19fe5c4ccb07723d
ENV BA_CODE_HASH=0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8
ENV BA_HASH_TYPE=type
ENV BA_MESSAGE=0x1234

EXPOSE 8114 8115

COPY --chown=ckb ./entrypoint.sh /bin/
COPY --chown=ckb ./dev.toml /var/
COPY --chown=ckb ./ckb-miner.toml /var/

ENTRYPOINT ["/bin/entrypoint.sh"]
40 changes: 40 additions & 0 deletions packages/e2e-test/docker/ckb/ckb-miner.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Config generated by `ckb init --chain dev`

data_dir = "data"

[chain]
# Choose the kind of chains to run, possible values:
# - { file = "specs/dev.toml" }
# - { bundled = "specs/testnet.toml" }
# - { bundled = "specs/mainnet.toml" }
spec = { file = "specs/dev.toml" }

[logger]
filter = "info"
color = true
log_to_file = true
log_to_stdout = true

[sentry]
# set to blank to disable sentry error collection
dsn = ""
# if you are willing to help us to improve,
# please leave a way to contact you when we have troubles to reproduce the errors.
# org_contact = ""

# # **Experimental** Monitor memory changes.
# [memory_tracker]
# # Seconds between checking the process, 0 is disable, default is 0.
# interval = 600

[miner.client]
rpc_url = "http://127.0.0.1:8114/"
block_on_submit = true

# block template polling interval in milliseconds
poll_interval = 500

[[miner.workers]]
worker_type = "Dummy"
delay_type = "Constant"
value = 500
124 changes: 124 additions & 0 deletions packages/e2e-test/docker/ckb/dev.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name = "ckb_dev"

[genesis]
version = 0
parent_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
timestamp = 0
compact_target = 0x20010000
uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
nonce = "0x0"

[genesis.genesis_cell]
message = "ckb_dev"

[genesis.genesis_cell.lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type = "data"

# An array list paths to system cell files, which is absolute or relative to
# the directory containing this config file.
[[genesis.system_cells]]
file = { bundled = "specs/cells/secp256k1_blake160_sighash_all" }
create_type_id = true
capacity = 100_000_0000_0000
[[genesis.system_cells]]
file = { bundled = "specs/cells/dao" }
create_type_id = true
capacity = 16_000_0000_0000
[[genesis.system_cells]]
file = { bundled = "specs/cells/secp256k1_data" }
create_type_id = false
capacity = 1_048_617_0000_0000
[[genesis.system_cells]]
file = { bundled = "specs/cells/secp256k1_blake160_multisig_all" }
create_type_id = true
capacity = 100_000_0000_0000

[genesis.system_cells_lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type = "data"

# Dep group cells
[[genesis.dep_groups]]
name = "secp256k1_blake160_sighash_all"
files = [
{ bundled = "specs/cells/secp256k1_data" },
{ bundled = "specs/cells/secp256k1_blake160_sighash_all" },
]
[[genesis.dep_groups]]
name = "secp256k1_blake160_multisig_all"
files = [
{ bundled = "specs/cells/secp256k1_data" },
{ bundled = "specs/cells/secp256k1_blake160_multisig_all" },
]

# For first 11 block
[genesis.bootstrap_lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type = "type"

# Burn
[[genesis.issued_cells]]
capacity = 8_400_000_000_00000000
lock.code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
lock.args = "0x62e907b15cbf27d5425399ebf6f0fb50ebb88f18"
lock.hash_type = "data"

# alice
# issue for random generated private key:0xfd686a48908e8caf97723578bf85f746e1e1d8956cb132f6a2e92e7234a2a245
# address: ckt1qyqw8yx5hx6vwcm7eqren0d0v39wvfwdhy3q2807pp
[[genesis.issued_cells]]
capacity = 20_000_000_000_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0xe390d4b9b4c7637ec80799bdaf644ae625cdb922"
lock.hash_type = "type"

# bob
# issue for random generated private key:0x5368b818f59570b5bc078a6a564f098a191dcb8938d95c413be5065fd6c42d32
# address: ckt1qyqtdhd6s7a44a0s2wc6uk7tcl6duq68nalqvzxw09
[[genesis.issued_cells]]
capacity = 20_000_000_000_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0xb6ddba87bb5af5f053b1ae5bcbc7f4de03479f7e"
lock.hash_type = "type"

# charlie
# issue for random generated private key:0xd6013cd867d286ef84cc300ac6546013837df2b06c9f53c83b4c33c2417f6a07
# address: ckt1qyqxek9w28u3htxhjyqjd7yqzw9nptzaxq2shqlft0
[[genesis.issued_cells]]
capacity = 20_000_000_000_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0x6cd8ae51f91bacd7910126f880138b30ac5d3015"
lock.hash_type = "type"

# issue for random generated private key: 0x13b08bb054d5dd04013156dced8ba2ce4d8cc5973e10d905a228ea1abc267e60
[[genesis.issued_cells]]
capacity = 20_000_000_000_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0xcf055e9d2d50fd94120fa6d981728a9be55bff3b"
lock.hash_type = "type"

# issue for random generated private key: 0xa6b023fec4fc492c23c0e999ab03b01a6ca5524a3560725887a8de4362f9c9cc
[[genesis.issued_cells]]
capacity = 20_000_000_000_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0xafe0a2b3785bf631f19a31a4bfda90b0ddb07678"
lock.hash_type = "type"

[params]
initial_primary_epoch_reward = 1_917_808_21917808
secondary_epoch_reward = 613_698_63013698
max_block_cycles = 10_000_000_000
cellbase_maturity = 0
primary_epoch_reward_halving_interval = 8760
epoch_duration_target = 1
genesis_epoch_length = 1
# For development and testing purposes only.
# Keep difficulty be permanent if the pow is Dummy. (default: false)
permanent_difficulty_in_dummy = true

[pow]
func = "Dummy"
12 changes: 12 additions & 0 deletions packages/e2e-test/docker/ckb/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

if ! [ -f ckb.toml ]; then
/bin/ckb init --chain "$CKB_CHAIN" --import-spec /var/dev.toml --ba-arg "$BA_ARG" --ba-code-hash "$BA_CODE_HASH" --ba-hash-type "$BA_HASH_TYPE" --ba-message "$BA_MESSAGE" \
&& sed -ic 's/filter = "info"/filter = "info,ckb-script=debug"/g' ckb.toml
fi

cp /var/ckb-miner.toml /var/lib/ckb/ckb-miner.toml

exec /bin/ckb run &
sleep 3
exec /bin/ckb miner
29 changes: 29 additions & 0 deletions packages/e2e-test/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.3'
services:
ckb:
image: lumos/ckb-dev:v0.103.0
build: ckb
ports:
- '8128:8114'
networks:
- internal_network
- external_network

ckb-indexer:
image: nervos/ckb-indexer:0.4.1
ports:
- '8130:8116'
environment:
- RUST_LOG=info
command: -s /tmp/ckb-indexer-test -c http://ckb:8114 -l 0.0.0.0:8116
depends_on:
- ckb
networks:
- internal_network
- external_network

networks:
internal_network:
internal: true
external_network:

53 changes: 53 additions & 0 deletions packages/e2e-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@ckb-lumos/e2e-test",
"version": "0.19.0-alpha.3",
"description": "CKB E2E test",
"private": true,
"homepage": "https://github.com/ckb-js/lumos#readme",
"license": "MIT",
"engines": {
"node": ">=12.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ckb-js/lumos.git"
},
"directories": {
"test": "tests"
},
"dependencies": {
"@ckb-lumos/base": "^0.19.0-alpha.3",
"@ckb-lumos/bi": "^0.19.0-alpha.3",
"@ckb-lumos/ckb-indexer": "^0.19.0-alpha.3",
"@ckb-lumos/rpc": "^0.19.0-alpha.3",
"@ckb-lumos/toolkit": "^0.19.0-alpha.3",
"events": "^3.3.0"
},
"devDependencies": {
"@ckb-lumos/testkit": "^0.19.0-alpha.3",
"@types/request": "^2.48.8",
"@types/sinon": "^10.0.6",
"find-process": "^1.4.7",
"request": "^2.88.2",
"sinon": "^12.0.1",
"ts-node": "^10.4.0"
},
"scripts": {
"fmt": "prettier --write \"{src,tests,examples}/**/*.ts\" package.json",
"lint": "eslint -c ../../.eslintrc.js \"{src,tests,examples}/**/*.ts\"",
"posttest:e2e": "(nohup docker-compose -f ./docker/docker-compose.yml down)",
"pretest:e2e": "(nohup docker-compose -f ./docker/docker-compose.yml up -d)",
"test:e2e": "ava **/*.e2e.test.ts --timeout=5m"
},
"bugs": {
"url": "https://github.com/ckb-js/lumos/issues"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
}
}
11 changes: 11 additions & 0 deletions packages/e2e-test/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const CKB_RPC_URL = "http://127.0.0.1:8128/rpc";
export const INDEXER_RPC_URL = "http://127.0.0.1:8130";

// from docker/ckb/dev.toml [[genesis.system_cells]]
export const GENESIS_CELL_PRIVATEKEYS = [
"0xfd686a48908e8caf97723578bf85f746e1e1d8956cb132f6a2e92e7234a2a245",
"0x5368b818f59570b5bc078a6a564f098a191dcb8938d95c413be5065fd6c42d32",
"0xd6013cd867d286ef84cc300ac6546013837df2b06c9f53c83b4c33c2417f6a07",
"0x13b08bb054d5dd04013156dced8ba2ce4d8cc5973e10d905a228ea1abc267e60",
"0xa6b023fec4fc492c23c0e999ab03b01a6ca5524a3560725887a8de4362f9c9cc",
];
Loading

0 comments on commit 6f07ea0

Please sign in to comment.