Skip to content

Commit fb4231f

Browse files
outSHpetermetz
authored andcommitted
feat(geth-all-in-one): add ethereum test image and helper class
- Add new `geth-all-in-one` test image for running ethereum tests in mainnet-like environment. Image is based on `client-go:v1.12.0` and uses Clique (PoS). There is one coinbase account with publicly available keys like in other, similar packages in cacti. - New image was introduced because currently used open-ethereum one is deprecated. - Add `geth-all-in-one-publish` CI for publishing new images. - Add `@hyperledger/cactus-test-geth-ledger` for using new geth ledger container in the tests. The class has been moved out of `cactus-test-tooling` because of conflicting `web3js` versions. Other than that, it's similar to open-ethereum test class. - Add basic tests for `@hyperledger/cactus-test-geth-ledger`. More tests are being developed right now, and should be available in subsequent PRs. Closes: #2577 Signed-off-by: Michal Bajer <[email protected]>
1 parent 7bb3957 commit fb4231f

19 files changed

+999
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: geth-all-in-one-publish
2+
3+
on:
4+
push:
5+
# Publish `main` as Docker `latest` image.
6+
branches:
7+
- main
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
17+
env:
18+
IMAGE_NAME: cactus-geth-all-in-one
19+
20+
jobs:
21+
# Push image to GitHub Packages.
22+
# See also https://docs.docker.com/docker-hub/builds/
23+
build-tag-push-container:
24+
runs-on: ubuntu-20.04
25+
env:
26+
DOCKER_BUILDKIT: 1
27+
DOCKERFILE_PATH: ./tools/docker/geth-all-in-one/Dockerfile
28+
DOCKER_BUILD_DIR: ./tools/docker/geth-all-in-one/
29+
permissions:
30+
packages: write
31+
contents: read
32+
33+
steps:
34+
- uses: actions/[email protected]
35+
36+
- name: Build image
37+
run: docker build $DOCKER_BUILD_DIR --file $DOCKERFILE_PATH --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
38+
39+
- name: Log in to registry
40+
# This is where you will update the PAT to GITHUB_TOKEN
41+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
42+
43+
- name: Push image
44+
run: |
45+
SHORTHASH=$(git rev-parse --short "$GITHUB_SHA")
46+
TODAYS_DATE="$(date +%F)"
47+
DOCKER_TAG="$TODAYS_DATE-$SHORTHASH"
48+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
49+
# Change all uppercase to lowercase
50+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
51+
# Strip git ref prefix from version
52+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
53+
# Strip "v" prefix from tag name
54+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
55+
# Do not use the `latest` tag at all, tag with date + git short hash if there is no git tag
56+
[ "$VERSION" == "main" ] && VERSION=$DOCKER_TAG
57+
echo IMAGE_ID=$IMAGE_ID
58+
echo VERSION=$VERSION
59+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
60+
docker push $IMAGE_ID:$VERSION
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# `@hyperledger/cactus-test-geth-ledger`
2+
3+
Helpers for running test `go-ethereum` ledger in test scripts.
4+
5+
## Summary
6+
7+
- [Getting Started](#getting-started)
8+
- [Usage](#usage)
9+
- [Runing the tests](#running-the-tests)
10+
- [Contributing](#contributing)
11+
- [License](#license)
12+
- [Acknowledgments](#acknowledgments)
13+
14+
## Getting Started
15+
16+
Clone the git repository on your local machine. Follow these instructions that will get you a copy of the project up and running on
17+
your local machine for development and testing purposes.
18+
19+
### Prerequisites
20+
21+
In the root of the project to install the dependencies execute the command:
22+
23+
```sh
24+
npm run configure
25+
```
26+
27+
## Usage
28+
29+
- In order to start the new test ledger, you must import `GethTestLedger` and `start()` it.
30+
- Options can be modified by supplying constructor argument object.
31+
- See tests for more complete usage examples.
32+
33+
```typescript
34+
import { GethTestLedger } from "@hyperledger/cactus-test-geth-ledger";
35+
36+
// You can supply empty object, suitable default values will be used.
37+
const options = {
38+
containerImageName: "cactus_geth_all_in_one", // geth AIO container name
39+
containerImageVersion: "local-build", // geth AIO container tag
40+
logLevel: "info" as LogLevelDesc, // log verbosity of test class, not ethereum node!
41+
emitContainerLogs: false, // will print ethereum node logs here if `true`
42+
envVars: [], // environment variables to provide when starting the ledger
43+
useRunningLedger: false, // test flag to search for already running ledger instead of starting new one (only for development)
44+
};
45+
46+
const ledger = new GethTestLedger(options);
47+
await ledger.start();
48+
// await ledger.start(true); // don't pull image, use one from local storage
49+
50+
// Use
51+
const rpcApiHttpHost = await ledger.getRpcApiHttpHost();
52+
```
53+
54+
## Running the tests
55+
56+
To check that all has been installed correctly and that the test class has no errors:
57+
58+
- Run this command at the project's root:
59+
60+
```sh
61+
npx jest cactus-test-geth-ledger
62+
```
63+
64+
## Contributing
65+
66+
We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do!
67+
68+
Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started.
69+
70+
## License
71+
72+
This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file.
73+
74+
## Acknowledgments
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@hyperledger/cactus-test-geth-ledger",
3+
"version": "2.0.0-alpha.1",
4+
"description": "Helpers for running test go-ethereum ledger in test scripts.",
5+
"keywords": [
6+
"Hyperledger",
7+
"Cactus",
8+
"Integration",
9+
"Blockchain",
10+
"Distributed Ledger Technology"
11+
],
12+
"homepage": "https://github.com/hyperledger/cactus#readme",
13+
"bugs": {
14+
"url": "https://github.com/hyperledger/cactus/issues"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/hyperledger/cactus.git"
19+
},
20+
"license": "Apache-2.0",
21+
"author": {
22+
"name": "Hyperledger Cactus Contributors",
23+
"email": "[email protected]",
24+
"url": "https://www.hyperledger.org/use/cactus"
25+
},
26+
"contributors": [
27+
{
28+
"name": "Please add yourself to the list of contributors",
29+
"email": "[email protected]",
30+
"url": "https://example.com"
31+
},
32+
{
33+
"name": "Michal Bajer",
34+
"email": "[email protected]",
35+
"url": "https://www.fujitsu.com/global/"
36+
}
37+
],
38+
"main": "dist/lib/main/typescript/index.js",
39+
"module": "dist/lib/main/typescript/index.js",
40+
"browser": "dist/cactus-test-geth-ledger.web.umd.js",
41+
"types": "dist/lib/main/typescript/index.d.ts",
42+
"files": [
43+
"dist/*"
44+
],
45+
"scripts": {
46+
"watch": "npm-watch",
47+
"webpack": "npm-run-all webpack:dev",
48+
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
49+
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js",
50+
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js"
51+
},
52+
"dependencies": {
53+
"@hyperledger/cactus-common": "2.0.0-alpha.1",
54+
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1",
55+
"dockerode": "3.3.0",
56+
"internal-ip": "6.2.0",
57+
"run-time-error": "1.4.0",
58+
"web3": "4.0.3",
59+
"web3-eth-accounts": "4.0.3"
60+
},
61+
"devDependencies": {
62+
"@types/dockerode": "3.2.7"
63+
},
64+
"engines": {
65+
"node": ">=10",
66+
"npm": ">=6"
67+
},
68+
"publishConfig": {
69+
"access": "public"
70+
},
71+
"browserMinified": "dist/cactus-test-geth-ledger.web.umd.min.js",
72+
"mainMinified": "dist/cactus-test-geth-ledger.node.umd.min.js",
73+
"watch": {}
74+
}

0 commit comments

Comments
 (0)