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: Dockerize TCK #331

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
142 changes: 142 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
FROM node:22-slim

# Set working directory
WORKDIR /app

# Copy package files first for better caching
COPY package.json package-lock.json ./
RUN npm ci

# Environment Variables
ENV NETWORK=local \
RUNNING_IN_DOCKER=true \
TEST="ALL"

# Test Mapping
RUN echo '#!/bin/sh\n\
if [ "$NETWORK" = "testnet" ]; then\n\
if [ -z "$OPERATOR_ACCOUNT_ID" ] || [ -z "$OPERATOR_ACCOUNT_PRIVATE_KEY" ]; then\n\
echo "Error: OPERATOR_ACCOUNT_ID and OPERATOR_ACCOUNT_PRIVATE_KEY must be provided for running on testnet"\n\
exit 1\n\
fi\n\
export NODE_TYPE=testnet\n\
export NODE_TIMEOUT=30000\n\
export MIRROR_NODE_REST_URL=https://testnet.mirrornode.hedera.com\n\
export MIRROR_NODE_REST_JAVA_URL=https://testnet.mirrornode.hedera.com\n\
else\n\
export NODE_TYPE=local\n\
export NODE_IP=localhost:50211\n\
export NODE_ACCOUNT_ID=0.0.3\n\
export NODE_TIMEOUT=1000000\n\
export MIRROR_NETWORK=localhost:5600\n\
export MIRROR_NODE_REST_URL=http://localhost:5551\n\
export MIRROR_NODE_REST_JAVA_URL=http://localhost:8084\n\
export OPERATOR_ACCOUNT_ID=0.0.1022\n\
export OPERATOR_ACCOUNT_PRIVATE_KEY=302e020100300506032b657004220420a608e2130a0a3cb34f86e757303c862bee353d9ab77ba4387ec084f881d420d4\n\
fi\n\
\n\
case "$TEST" in\n\
# Crypto Service Tests\n\
"AccountCreate")\n\
TEST_PATH="src/tests/crypto-service/test-account-create-transaction.ts"\n\
;;\n\
"AccountUpdate")\n\
TEST_PATH="src/tests/crypto-service/test-account-update-transaction.ts"\n\
;;\n\
"AccountDelete")\n\
TEST_PATH="src/tests/crypto-service/test-account-delete-transaction.ts"\n\
;;\n\
"AccountAllowanceDelete")\n\
TEST_PATH="src/tests/crypto-service/test-account-allowance-delete-transaction.ts"\n\
;;\n\
"AccountAllowanceApprove")\n\
TEST_PATH="src/tests/crypto-service/test-account-allowance-approve-transaction.ts"\n\
;;\n\
# Token Service Tests\n\
"TokenCreate")\n\
TEST_PATH="src/tests/token-service/test-token-create-transaction.ts"\n\
;;\n\
"TokenUpdate")\n\
TEST_PATH="src/tests/token-service/test-token-update-transaction.ts"\n\
;;\n\
"TokenDelete")\n\
TEST_PATH="src/tests/token-service/test-token-delete-transaction.ts"\n\
;;\n\
"TokenBurn")\n\
TEST_PATH="src/tests/token-service/test-token-burn-transaction.ts"\n\
;;\n\
"TokenMint")\n\
TEST_PATH="src/tests/token-service/test-token-mint-transaction.ts"\n\
;;\n\
"TokenAssociate")\n\
TEST_PATH="src/tests/token-service/test-token-associate-transaction.ts"\n\
;;\n\
"TokenDissociate")\n\
TEST_PATH="src/tests/token-service/test-token-dissociate-transaction.ts"\n\
;;\n\
"TokenFeeScheduleUpdate")\n\
TEST_PATH="src/tests/token-service/test-token-fee-schedule-update-transaction.ts"\n\
;;\n\
"TokenGrantKyc")\n\
TEST_PATH="src/tests/token-service/test-token-grant-kyc-transaction.ts"\n\
;;\n\
"TokenRevokeKyc")\n\
TEST_PATH="src/tests/token-service/test-token-revoke-kyc-transaction.ts"\n\
;;\n\
"TokenPause")\n\
TEST_PATH="src/tests/token-service/test-token-pause-transaction.ts"\n\
;;\n\
"TokenUnpause")\n\
TEST_PATH="src/tests/token-service/test-token-unpause-transaction.ts"\n\
;;\n\
"TokenFreeze")\n\
TEST_PATH="src/tests/token-service/test-token-freeze-transaction.ts"\n\
;;\n\
"TokenUnfreeze")\n\
TEST_PATH="src/tests/token-service/test-token-unfreeze-transaction.ts"\n\
;;\n\
"ALL")\n\
TEST_PATH="src/tests/**/*.ts"\n\
;;\n\
*)\n\
echo "\
Unknown test: $TEST\n\
\n\
Available tests:\n\
Crypto Service:\n\
- AccountCreate\n\
- AccountUpdate\n\
- AccountAllowanceDelete\n\
- AccountAllowanceApprove\n\
Token Service:\n\
- TokenCreate\n\
- TokenUpdate\n\
- TokenDelete\n\
- TokenBurn\n\
- TokenMint\n\
- TokenAssociate\n\
- TokenDissociate\n\
- TokenFeeScheduleUpdate\n\
- TokenGrantKyc\n\
- TokenRevokeKyc\n\
- TokenPause\n\
- TokenUnpause\n\
- TokenFreeze\n\
- TokenUnfreeze\n\
- ALL (runs all tests)"\n\
exit 1\n\
;;\n\
esac\n\
\n\
npx mocha \
--require ts-node/register \
--require tsconfig-paths/register \
--recursive \"$TEST_PATH\" \
--reporter mochawesome \
--exit' > /app/run-tests.sh && chmod +x /app/run-tests.sh

# Copy the rest of the application
COPY . .

# Use the mapping script
CMD ["/app/run-tests.sh"]
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,79 @@ Please read our [contributing guide](https://github.com/hiero-ledger/.github/blo

Hiero uses the Linux Foundation Decentralised Trust [Code of Conduct](https://www.lfdecentralizedtrust.org/code-of-conduct).


## Docker

The TCK is also available as a Docker image, providing an easy way to run tests in an isolated environment.

### Pull the Docker Image

You can pull the pre-built Docker image from DockerHub:

```bash
docker pull ivaylogarnev/tck-client
```

### Running Tests

The Docker image supports running tests against both local and testnet environments.

#### Local Network (Default)
To run tests against a local network:
```bash
# Run specific test
docker run --network host -e TEST=AccountCreate ivaylogarnev/tck-client

# Run all tests
docker run --network host ivaylogarnev/tck-client
```

#### Testnet
To run tests against Hedera Testnet:
```bash
docker run --network host \
-e NETWORK=testnet \
-e OPERATOR_ACCOUNT_ID=your-account-id \
-e OPERATOR_ACCOUNT_PRIVATE_KEY=your-private-key \
# Run specific test
-e TEST=AccountCreate \
ivaylogarnev/tck-client
```

### Available Tests
Some of the available test options include:
- AccountCreate
- AccountUpdate
- AccountDelete
- AccountAllowanceDelete
- AccountAllowanceApprove
- TokenCreate
- TokenUpdate
- TokenDelete
- TokenBurn
- TokenMint
- TokenAssociate
- TokenDissociate
- TokenFeeScheduleUpdate
- TokenGrantKyc
- TokenRevokeKyc
- TokenPause
- TokenUnpause
- TokenFreeze
- TokenUnfreeze
- ALL (runs all tests)

Running an invalid test name will display the complete list of available tests.

### Building the Docker Image Locally

If you want to build the image locally:
```bash
docker build -t tck-client .
```

Then run it using the same commands as above, replacing `ivaylogarnev/tck-client` with `tck-client`.

## License

[Apache License 2.0](LICENSE)
[Apache License 2.0](LICENSE)
10 changes: 9 additions & 1 deletion src/services/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import "dotenv/config";
let nextID = 0;
const createID: CreateID = () => nextID++;

// Determine the host based on environment
const getHost = () => {
if (process.env.RUNNING_IN_DOCKER) {
return "http://host.docker.internal";
}
return "http://localhost";
};

// JSONRPCClient needs to know how to send a JSON-RPC request.
// Tell it by passing a function to its constructor. The function must take a JSON-RPC request and send it.
const JSONRPClient = new JSONRPCClient(
async (jsonRPCRequest): Promise<void> => {
try {
const response = await axios.post("http://localhost", jsonRPCRequest, {
const response = await axios.post(getHost(), jsonRPCRequest, {
headers: {
"Content-Type": "application/json",
},
Expand Down