diff --git a/tck/.dockerignore b/tck/.dockerignore new file mode 100644 index 000000000..b512c09d4 --- /dev/null +++ b/tck/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/tck/Dockerfile b/tck/Dockerfile new file mode 100644 index 000000000..26ee21916 --- /dev/null +++ b/tck/Dockerfile @@ -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"] \ No newline at end of file diff --git a/tck/README.md b/tck/README.md index 0f0d37da2..671d10867 100644 --- a/tck/README.md +++ b/tck/README.md @@ -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. \ No newline at end of file +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! 💻✨ diff --git a/tck/Taskfile.yml b/tck/Taskfile.yml new file mode 100644 index 000000000..735d972fc --- /dev/null +++ b/tck/Taskfile.yml @@ -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] diff --git a/tck/cmd/server.go b/tck/cmd/server.go index 3d45cc30b..58df9e324 100644 --- a/tck/cmd/server.go +++ b/tck/cmd/server.go @@ -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) diff --git a/tck/docker-compose.yml b/tck/docker-compose.yml new file mode 100644 index 000000000..242a325b1 --- /dev/null +++ b/tck/docker-compose.yml @@ -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