forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: hyperledger-cacti#2577 Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
- Loading branch information
Showing
19 changed files
with
999 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: geth-all-in-one-publish | ||
|
||
on: | ||
push: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- main | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
IMAGE_NAME: cactus-geth-all-in-one | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
build-tag-push-container: | ||
runs-on: ubuntu-20.04 | ||
env: | ||
DOCKER_BUILDKIT: 1 | ||
DOCKERFILE_PATH: ./tools/docker/geth-all-in-one/Dockerfile | ||
DOCKER_BUILD_DIR: ./tools/docker/geth-all-in-one/ | ||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v3.5.2 | ||
|
||
- name: Build image | ||
run: docker build $DOCKER_BUILD_DIR --file $DOCKERFILE_PATH --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | ||
|
||
- name: Log in to registry | ||
# This is where you will update the PAT to GITHUB_TOKEN | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push image | ||
run: | | ||
SHORTHASH=$(git rev-parse --short "$GITHUB_SHA") | ||
TODAYS_DATE="$(date +%F)" | ||
DOCKER_TAG="$TODAYS_DATE-$SHORTHASH" | ||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
# Do not use the `latest` tag at all, tag with date + git short hash if there is no git tag | ||
[ "$VERSION" == "main" ] && VERSION=$DOCKER_TAG | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# `@hyperledger/cactus-test-geth-ledger` | ||
|
||
Helpers for running test `go-ethereum` ledger in test scripts. | ||
|
||
## Summary | ||
|
||
- [Getting Started](#getting-started) | ||
- [Usage](#usage) | ||
- [Runing the tests](#running-the-tests) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
- [Acknowledgments](#acknowledgments) | ||
|
||
## Getting Started | ||
|
||
Clone the git repository on your local machine. Follow these instructions that will get you a copy of the project up and running on | ||
your local machine for development and testing purposes. | ||
|
||
### Prerequisites | ||
|
||
In the root of the project to install the dependencies execute the command: | ||
|
||
```sh | ||
npm run configure | ||
``` | ||
|
||
## Usage | ||
|
||
- In order to start the new test ledger, you must import `GethTestLedger` and `start()` it. | ||
- Options can be modified by supplying constructor argument object. | ||
- See tests for more complete usage examples. | ||
|
||
```typescript | ||
import { GethTestLedger } from "@hyperledger/cactus-test-geth-ledger"; | ||
|
||
// You can supply empty object, suitable default values will be used. | ||
const options = { | ||
containerImageName: "cactus_geth_all_in_one", // geth AIO container name | ||
containerImageVersion: "local-build", // geth AIO container tag | ||
logLevel: "info" as LogLevelDesc, // log verbosity of test class, not ethereum node! | ||
emitContainerLogs: false, // will print ethereum node logs here if `true` | ||
envVars: [], // environment variables to provide when starting the ledger | ||
useRunningLedger: false, // test flag to search for already running ledger instead of starting new one (only for development) | ||
}; | ||
|
||
const ledger = new GethTestLedger(options); | ||
await ledger.start(); | ||
// await ledger.start(true); // don't pull image, use one from local storage | ||
|
||
// Use | ||
const rpcApiHttpHost = await ledger.getRpcApiHttpHost(); | ||
``` | ||
|
||
## Running the tests | ||
|
||
To check that all has been installed correctly and that the test class has no errors: | ||
|
||
- Run this command at the project's root: | ||
|
||
```sh | ||
npx jest cactus-test-geth-ledger | ||
``` | ||
|
||
## Contributing | ||
|
||
We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do! | ||
|
||
Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started. | ||
|
||
## License | ||
|
||
This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file. | ||
|
||
## Acknowledgments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"name": "@hyperledger/cactus-test-geth-ledger", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Helpers for running test go-ethereum ledger in test scripts.", | ||
"keywords": [ | ||
"Hyperledger", | ||
"Cactus", | ||
"Integration", | ||
"Blockchain", | ||
"Distributed Ledger Technology" | ||
], | ||
"homepage": "https://github.com/hyperledger/cactus#readme", | ||
"bugs": { | ||
"url": "https://github.com/hyperledger/cactus/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hyperledger/cactus.git" | ||
}, | ||
"license": "Apache-2.0", | ||
"author": { | ||
"name": "Hyperledger Cactus Contributors", | ||
"email": "cactus@lists.hyperledger.org", | ||
"url": "https://www.hyperledger.org/use/cactus" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Please add yourself to the list of contributors", | ||
"email": "your.name@example.com", | ||
"url": "https://example.com" | ||
}, | ||
{ | ||
"name": "Michal Bajer", | ||
"email": "michal.bajer@fujitsu.com", | ||
"url": "https://www.fujitsu.com/global/" | ||
} | ||
], | ||
"main": "dist/lib/main/typescript/index.js", | ||
"module": "dist/lib/main/typescript/index.js", | ||
"browser": "dist/cactus-test-geth-ledger.web.umd.js", | ||
"types": "dist/lib/main/typescript/index.d.ts", | ||
"files": [ | ||
"dist/*" | ||
], | ||
"scripts": { | ||
"watch": "npm-watch", | ||
"webpack": "npm-run-all webpack:dev", | ||
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web", | ||
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js", | ||
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js" | ||
}, | ||
"dependencies": { | ||
"@hyperledger/cactus-common": "2.0.0-alpha.1", | ||
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1", | ||
"dockerode": "3.3.0", | ||
"internal-ip": "6.2.0", | ||
"run-time-error": "1.4.0", | ||
"web3": "4.0.3", | ||
"web3-eth-accounts": "4.0.3" | ||
}, | ||
"devDependencies": { | ||
"@types/dockerode": "3.2.7" | ||
}, | ||
"engines": { | ||
"node": ">=10", | ||
"npm": ">=6" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"browserMinified": "dist/cactus-test-geth-ledger.web.umd.min.js", | ||
"mainMinified": "dist/cactus-test-geth-ledger.node.umd.min.js", | ||
"watch": {} | ||
} |
Oops, something went wrong.