Skip to main content

Guide to Using the Chromia CLI for Testing and Deploying Rell Code on Chromia

This guide will teach us how to use the Chromia CLI to write and execute pipelines for testing and deploying Rell code on the Chromia blockchain platform. The provided pipeline file defines different stages for building, testing, and deploying Rell code. We will explain each step and its corresponding actions.

Defining base image

First, we will define the base image to use in our pipelines. In this example, we are using the latest tag, but it is recommended to use a fixed version so as not to get any surprises.

image: registry.gitlab.com/chromaway/core-tools/chromia-cli/chr:latest

Building the project

In this stage, we build the blockchain configurations for all configured blockchains in our project and save them as artifacts.

We also define the stages build, test, and deploy to which we will attach our jobs later.

stages:
- build
- test
- deploy

build:
stage: build
script:
- chr build
artifacts:
when: on_success
paths:
- build/*.xml
caution

Remember that if your project has dependencies, your script must also run chr install before any other action, such as build, test, or start.

Running tests

To run unit tests, we need to add a Postgres service container. We use the Alpine version of the image since it has the expected collation settings.

We also define global variables for database properties that can be reused in the integration test job.

variables:
POSTGRES_DB: postchain
POSTGRES_USER: postchain
POSTGRES_PASSWORD: postchain
CHR_DB_URL: jdbc:postgresql://postgres/postchain

test:
stage: test
services:
- postgres:15-alpine
script: chr test --test-report
artifacts:
when: always
reports:
junit: build/reports/*.xml

In the integration test job, we start by running a test node on a background thread and wait for the messaging port 9870 to be exposed before proceeding. If your integration tests are run in TypeScript, Kotlin, or any other language than shell, using frameworks such as Testcontainers to start the test node as a sidecar is a good choice. Read the guide on how to set this up in TypeScript here.

integration-test:
stage: test
services:
- postgres:15-alpine
before_script:
- chr node start &
- while ! nc -z localhost 9870; do sleep 1; done; sleep 1
script:
- chr tx --await set_name Alice
- $([ "$(chr query hello_world)" = "\"Hello Alice!\"" ])
artifacts:
when: on_failure
paths:
- logs/*.log