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(TCK): Dockerized TCK server #1267

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions tck/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
28 changes: 28 additions & 0 deletions tck/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.21 AS builder

# Set the working directory inside the container
WORKDIR /app

# Copy the SDK files first (from parent directory)
COPY . /app/hiero-sdk-go/

# Set the working directory for the TCK files
WORKDIR /app/hiero-sdk-go/tck

# Copy go.mod and go.sum first
COPY tck/go.mod tck/go.sum ./

RUN go mod tidy
RUN go build -o server cmd/server.go


FROM alpine:3.20

WORKDIR /app
COPY --from=builder /app/hiero-sdk-go/tck/server .
RUN chmod +x /app/server

# Install necessary libraries
RUN apk add --no-cache libc6-compat

CMD ["./server"]
88 changes: 84 additions & 4 deletions tck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,92 @@

This is a server that implements the [SDK TCK specification](https://github.com/hiero-ledger/hiero-sdk-tck/) for the Go SDK.

## Running the server
# Server start up guide for Go 🛠️

To run the server you need to run
This guide will help you set up, start, and test the TCK server using Docker and Go. Follow the steps below to ensure a smooth setup.

```
## 🚀 Start the TCK Server

Run the following commands to build and start the server:

```bash
# From the tck directory
go mod tidy
go run cmd/server.go
```

This will start the server on port **80**. You can change the port by setting the `TCK_PORT` environment variable or by adding a .env file with the same variable.
This will start the server on port **8054**. You can change the port by setting the `TCK_PORT` environment variable or by adding a .env file with the same variable.

Once started, your TCK server will be up and running! 🚦

# Start all TCK tests with Docker 🐳

This section covers setting up and running TCK tests using Docker.

## Prerequisites

Before you begin, ensure you have the following installed:

- **Go**: Version 1.20 or higher
- **Docker**: Latest version
- **Docker Compose**: Latest version
- **Task**: Latest version

## 🔹 Run a specific test

```bash
task run-specific-test TEST=AccountCreate
```

This will:

- Verifies prerequisites

- Starts the TCK server

- Launches required containers

- Run only the `AccountCreate` tests

## 🔹 Run all tests

To run all tests:

```bash
task start-all-tests
```

This will:

- Verifies prerequisites

- Starts the TCK server

- Launches required containers

- Run all tests automatically

Sit back and let Docker do the work! 🚀

### ⚙️ Running Tests Against Hiero Testnet

To run tests against the Hiero Testnet, use the following command:

```bash
task run-specific-test \
NETWORK=testnet \
OPERATOR_ACCOUNT_ID=your-account-id \
OPERATOR_ACCOUNT_PRIVATE_KEY=your-private-key \
MIRROR_NODE_REST_URL=https://testnet.mirrornode.hedera.com \
MIRROR_NODE_REST_JAVA_URL=https://testnet.mirrornode.hedera.com \
# Run specific test
TEST=AccountCreate
```

### 🎉 All Done!

Your TCK server is now running inside Docker! 🚀 You can now execute tests and validate the system.

Need help? Reach out to the team! 💬👨‍💻

Happy coding! 💻✨
112 changes: 112 additions & 0 deletions tck/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
version: "3"

tasks:
check-go:
desc: "Check if Go is installed and meets the version requirement"
silent: true
cmds:
- echo "Checking Go version..."
- |
if ! command -v go &> /dev/null; then
echo "Go is not installed. Please install Go 1.20 or higher."
exit 1
fi
GO_VERSION=$(go version | awk '{print $3}' | cut -c 3-)
if [ $(echo -e "1.20\n$GO_VERSION" | sort -V | head -n1) != "1.20" ]; then
echo "Go 1.20 or higher is required. Current version: $GO_VERSION"
exit 1
fi

install-hedera-local:
desc: "Install Hedera Local Node CLI tool if not installed"
silent: true
cmds:
- echo "Checking for Hedera Local Node CLI..."
- |
if ! command -v hedera &> /dev/null; then
echo "Hedera Local Node CLI not found, installing..."
npm install @hashgraph/hedera-local -g
else
echo "Hedera Local Node CLI is already installed."
fi

start-local-node:
desc: "Start the local Hedera network"
silent: true
deps: [check-go, install-hedera-local]
cmds:
- echo "Starting local Hedera network..."
- hedera start

pull-tck-client-server:
desc: "Pull the Docker image for tck-client"
cmds:
- echo "Pulling Docker image for tck-client..."
- docker pull ivaylogarnev/tck-client

build-tck-go-server:
desc: "Build the Docker image for tck-go-server & pulling tck-client image"
deps: [pull-tck-client-server]
silent: true
dir: ../
cmds:
- echo "Building Docker image for tck-go-server..."
- docker build -t tck-go-server -f tck/Dockerfile .

run-specific-test:
desc: "Run all services with a specific test"
silent: true
deps: [start-local-node, build-tck-go-server]
vars:
TEST: '{{.TEST | default "ALL"}}'
NETWORK: '{{.NETWORK | default "local"}}'
OPERATOR_ACCOUNT_ID: "{{.OPERATOR_ACCOUNT_ID}}"
OPERATOR_ACCOUNT_PRIVATE_KEY: "{{.OPERATOR_ACCOUNT_PRIVATE_KEY}}"
MIRROR_NODE_REST_URL: "{{.MIRROR_NODE_REST_URL}}"
MIRROR_NODE_REST_JAVA_URL: "{{.MIRROR_NODE_REST_JAVA_URL}}"
cmds:
- |
export TEST={{.TEST | default "ALL"}}
export NETWORK={{.NETWORK | default "local"}}
export OPERATOR_ACCOUNT_ID={{.OPERATOR_ACCOUNT_ID}}
export OPERATOR_ACCOUNT_PRIVATE_KEY="{{.OPERATOR_ACCOUNT_PRIVATE_KEY}}"
export MIRROR_NODE_REST_URL="{{.MIRROR_NODE_REST_URL}}"
export MIRROR_NODE_REST_JAVA_URL="{{.MIRROR_NODE_REST_JAVA_URL}}"
if [ "$NETWORK" = "testnet" ]; then
if [ -z "$OPERATOR_ACCOUNT_ID" ] || [ -z "$OPERATOR_ACCOUNT_PRIVATE_KEY" ]; then
echo "Error: OPERATOR_ACCOUNT_ID and OPERATOR_ACCOUNT_PRIVATE_KEY must be provided for testnet."
exit 1
fi
fi
docker compose up

start-all-tests:
desc: "Start Docker Compose services"
silent: true
deps: [start-local-node, build-tck-go-server]
vars:
NETWORK: '{{.NETWORK | default "local"}}'
OPERATOR_ACCOUNT_ID: "{{.OPERATOR_ACCOUNT_ID}}"
OPERATOR_ACCOUNT_PRIVATE_KEY: "{{.OPERATOR_ACCOUNT_PRIVATE_KEY}}"
MIRROR_NODE_REST_URL: "{{.MIRROR_NODE_REST_URL}}"
MIRROR_NODE_REST_JAVA_URL: "{{.MIRROR_NODE_REST_JAVA_URL}}"
cmds:
- echo "Starting Docker Compose services..."
- |
export TEST={{.TEST | default "ALL"}}
export NETWORK={{.NETWORK | default "local"}}
export OPERATOR_ACCOUNT_ID={{.OPERATOR_ACCOUNT_ID}}
export OPERATOR_ACCOUNT_PRIVATE_KEY="{{.OPERATOR_ACCOUNT_PRIVATE_KEY}}"
export MIRROR_NODE_REST_URL="{{.MIRROR_NODE_REST_URL}}"
export MIRROR_NODE_REST_JAVA_URL="{{.MIRROR_NODE_REST_JAVA_URL}}"
if [ "$NETWORK" = "testnet" ]; then
if [ -z "$OPERATOR_ACCOUNT_ID" ] || [ -z "$OPERATOR_ACCOUNT_PRIVATE_KEY" ]; then
echo "Error: OPERATOR_ACCOUNT_ID and OPERATOR_ACCOUNT_PRIVATE_KEY must be provided for testnet."
exit 1
fi
fi
docker compose up
default:
desc: "Start local node and Docker Compose"
silent: true
deps: [start-all-tests]
2 changes: 1 addition & 1 deletion tck/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
http.HandleFunc("/", bridge.ServeHTTP)
port := os.Getenv("TCK_PORT")
if port == "" {
port = "80"
port = "8544"
}
log.Println("Server is listening on port: " + port)

Expand Down
34 changes: 34 additions & 0 deletions tck/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
tck-server:
image: tck-go-server
networks:
- hedera-network-node
- hedera-mirror-node
environment:
NETWORK: "${NETWORK:-local}"
build:
context: .
ports:
- "8544:8544"
tck-client:
image: ivaylogarnev/tck-client
networks:
- hedera-network-node
- hedera-mirror-node
environment:
TEST: "${TEST:-ALL}"
NETWORK: "${NETWORK:-local}"
OPERATOR_ACCOUNT_ID: "${OPERATOR_ACCOUNT_ID:-0.0.1022}"
OPERATOR_ACCOUNT_PRIVATE_KEY: "${OPERATOR_ACCOUNT_PRIVATE_KEY:-302e020100300506032b657004220420a608e2130a0a3cb34f86e757303c862bee353d9ab77ba4387ec084f881d420d4}"
JSON_RPC_SERVER_URL: "http://tck-server:8544"
NODE_IP: "network-node:50211"
MIRROR_NODE_REST_URL: "${MIRROR_NODE_REST_URL:-http://mirror-node-rest:5551}"
MIRROR_NODE_REST_JAVA_URL: "${MIRROR_NODE_REST_JAVA_URL:-http://mirror-node-rest-java:8084}"
depends_on:
- tck-server

networks:
hedera-network-node:
external: true
hedera-mirror-node:
external: true
Loading