Skip to content

Commit

Permalink
Adds ccip-tests directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra committed Aug 6, 2024
1 parent d963b0a commit 3e4758f
Show file tree
Hide file tree
Showing 56 changed files with 24,002 additions and 0 deletions.
70 changes: 70 additions & 0 deletions integration-tests/ccip-tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## To Override the default config, and secret config:
# example usage: make set_config override_toml=../config/config.toml secret_toml=../config/secret.toml network_config_toml=../config/network.toml
.PHONY: set_config
set_config:
if [ -s "$(override_toml)" ]; then \
echo "Overriding config with $(override_toml)"; \
echo "export BASE64_CCIP_CONFIG_OVERRIDE=$$(base64 -i $(override_toml))" > ./testconfig/override/.env; \
echo "export TEST_BASE64_CCIP_CONFIG_OVERRIDE=$$(base64 -i $(override_toml))" >> ./testconfig/override/.env; \
else \
echo "No override config found, using default config"; \
echo > ./testconfig/override/.env; \
fi
if [ -s "$(network_config_toml)" ]; then \
echo "Overriding network config with $(network_config_toml)"; \
echo "export BASE64_NETWORK_CONFIG=$$(base64 -i $(network_config_toml))" >> ./testconfig/override/.env; \
fi

@echo "setting secret config with $(secret_toml)"
@echo "export BASE64_CCIP_SECRETS_CONFIG=$$(base64 -i $(secret_toml))" >> ./testconfig/override/.env
@echo "export TEST_BASE64_CCIP_SECRETS_CONFIG=$$(base64 -i $(secret_toml))" >> ./testconfig/override/.env
@echo "BASE64_CCIP_SECRETS_CONFIG=$$(base64 -i $(secret_toml))" > ./testconfig/override/debug.env
@echo "TEST_BASE64_CCIP_SECRETS_CONFIG=$$(base64 -i $(secret_toml))" >> ./testconfig/override/debug.env


# example usage: make test_load_ccip testimage=chainlink-ccip-tests:latest testname=TestLoadCCIPStableRPS override_toml=./testconfig/override/config.toml secret_toml=./testconfig/tomls/secrets.toml network_config_toml=../config/network.toml
.PHONY: test_load_ccip
test_load_ccip: set_config
source ./testconfig/override/.env && \
DATABASE_URL=postgresql://postgres:node@localhost:5432/chainlink_test?sslmode=disable \
ENV_JOB_IMAGE=$(testimage) \
TEST_SUITE=load \
TEST_ARGS="-test.timeout 900h" \
DETACH_RUNNER=true \
RR_MEM=16Gi \
RR_CPU=4 \
go test -timeout 24h -count=1 -v -run ^$(testname)$$ ./load


# example usage: make test_smoke_ccip testimage=chainlink-ccip-tests:latest testname=TestSmokeCCIPForBidirectionalLane override_toml=../testconfig/override/config.toml secret_toml=./testconfig/tomls/secrets.toml network_config_toml=../config/network.toml
.PHONY: test_smoke_ccip
test_smoke_ccip: set_config
source ./testconfig/override/.env && \
DATABASE_URL=postgresql://postgres:node@localhost:5432/chainlink_test?sslmode=disable \
ENV_JOB_IMAGE=$(testimage) \
TEST_SUITE=smoke \
TEST_ARGS="-test.timeout 900h" \
DETACH_RUNNER=true \
go test -timeout 24h -count=1 -v -run ^$(testname)$$ ./smoke

# run ccip smoke tests with default config; explicitly sets the override config to empty
# example usage: make test_smoke_ccip_default testname=TestSmokeCCIPForBidirectionalLane secret_toml=./testconfig/tomls/secrets.toml
.PHONY: test_smoke_ccip_default
test_smoke_ccip_default: set_config
source ./testconfig/override/.env && \
DATABASE_URL=postgresql://postgres:node@localhost:5432/chainlink_test?sslmode=disable \
BASE64_CCIP_CONFIG_OVERRIDE="" \
TEST_BASE64_CCIP_CONFIG_OVERRIDE="" \
ENV_JOB_IMAGE="" \
TEST_SUITE=smoke \
TEST_ARGS="-test.timeout 900h" \
DETACH_RUNNER=true \
go test -timeout 24h -count=1 -v -run ^$(testname)$$ ./smoke


# image: the name for the chainlink image being built, example: image=chainlink
# tag: the tag for the chainlink image being built, example: tag=latest
# example usage: make build_ccip_image image=chainlink-ccip tag=latest
.PHONY: build_ccip_image
build_ccip_image:
docker build -f ../../core/chainlink.Dockerfile --build-arg COMMIT_SHA=$(git rev-parse HEAD) --build-arg CHAINLINK_USER=chainlink -t $(image):$(tag) ../../
138 changes: 138 additions & 0 deletions integration-tests/ccip-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# CCIP Tests

Here lives the integration tests for ccip, utilizing our [chainlink-testing-framework](https://github.com/smartcontractkit/chainlink-testing-framework) and [integration-tests](https://github.com/smartcontractkit/ccip/tree/ccip-develop/integration-tests)

## Setup the Tests

CCIP tests are designed to be highly configurable. Instead of writing many tests to check specific scenarios, the philosophy is to write a few unique tests and make them adjustable through the use of test inputs and configurations. There are a few different ways to set this configuration:

1. Default test input - set via TOML - If no specific input is set; the tests will run with default inputs mentioned in [default.toml](./testconfig/tomls/ccip-default.toml).
Please refer to the [testconfig README](../testconfig/README.md) for a more detailed look at how testconfig works.
2. If you want to run your test with a different config, you can override the default inputs. You can either write an [overrides.toml](../testconfig/README.md#configuration-and-overrides) file, or set the env var `BASE64_CCIP_CONFIG_OVERRIDE` containing the base64 encoded TOML file content with updated test input parameters.
For example, if you want to override the `Network` input in test and want to run your test on `avalanche testnet` and `arbitrum goerli` network, you need to:
1. Create a TOML file with the following content:

```toml
[CCIP]
[CCIP.Env]
[CCIP.Env.Network]
selected_networks= ['AVALANCHE_FUJI', 'ARBITRUM_GOERLI']
```

2. Encode it using the `base64` command
3. Set the env var `BASE64_CCIP_CONFIG_OVERRIDE` with the encoded content.

```bash
export BASE64_CCIP_CONFIG_OVERRIDE=$(base64 -i <path-to-override-toml-file>)
```

[mainnet.toml](./testconfig/override/mainnet.toml), [override.toml](./testconfig/examples/override.toml.example) are some of the sample override TOML files.

For example - In order to run the smoke test (TestSmokeCCIPForBidirectionalLane) on mainnet, run the test with following env var set:

```bash
export BASE64_CCIP_CONFIG_OVERRIDE=$(base64 -i ./testconfig/override/mainnet.toml)
```

3. Secrets - You also need to set some secrets. This is a mandatory step needed to run the tests. Please refer to [sample-secrets.toml](./testconfig/examples/secrets.toml.example) for the list of secrets that are mandatory to run the tests.
- The chainlink image and tag are required secrets for all the tests.
- If you are running tests in live networks like testnet and mainnet, you need to set the secrets (rpc urls and private keys) for the respective networks.
- If you are running tests in simulated networks no network specific secrets are required.
here is a sample secrets.toml file, for running the tests in simulated networks, with the chainlink image and tag set as secrets:

```toml
[CCIP]
[CCIP.Env]
# ChainlinkImage is mandatory for all tests.
[CCIP.Env.NewCLCluster]
[CCIP.Env.NewCLCluster.Common]
[CCIP.Env.NewCLCluster.Common.ChainlinkImage]
image = "chainlink-ccip"
version = "latest"
```

We consider secrets similar to test input overrides and encode them using `base64` command.
Once you have the secrets.toml file, you can encode it using `base64` command (similar to step 2) and set the env var `BASE64_CCIP_SECRETS_CONFIG` with the encoded content.

```bash
export BASE64_CCIP_SECRETS_CONFIG=$(base64 -i ./testconfig/tomls/secrets.toml)
```

**Please note that the secrets should NOT be checked in to the repo and should be kept locally.**

We recommend against changing the content of [sample-secrets.toml](./testconfig/examples/secrets.toml.example). Please create a new file and set it as the secrets file.
You can run the command to ignore the changes to the file.

```bash
git update-index --skip-worktree <path-to-secrets-file>
```

## Running the Tests

There are two ways to run the tests:

1. Using local docker containers
2. Using a remote kubernetes cluster

### Using Local Docker Containers

In order to run the tests locally, you need to have docker installed and running on your machine.
You can use a specific chainlink image and tag (if you already have one) for the tests. Otherwise, you can build the image using the following command:

```bash
make build_ccip_image image=chainlink-ccip tag=latest-dev # please choose the image and tag name as per your choice
```

For a local run, tests creates two private geth networks and runs the tests on them. Running tests on testnet and mainnet is not supported yet for local docker tests and must be run in a kubernetes environment.

1. [Setting the test inputs](#setup-the-tests)
1. If required, create an `override.toml` with the required test inputs. If you want to run the tests with default parameters, you can skip this step.
2. Create a TOML file with the secrets.
2. Run the following command to run the smoke tests with your custom override toml and secrets.

```bash
# mark the testimage as empty for running the tests in local docker containers
make test_smoke_ccip testimage="" testname=TestSmokeCCIPForBidirectionalLane override_toml="<the toml file with overridden config string>" secret_toml="<the toml file with secrets string>"
```

If you don't want to bother with any overrides, you can run with the default TOML settings with the below command.
```bash
make test_smoke_ccip_default testname=TestSmokeCCIPForBidirectionalLane secret_toml="<the toml file with secrets string>"
```
```mermaid
---
title: Basic Docker Test Environment
---
flowchart
subgraph SD[DON]
CL1[Node 1]
CL2[Node 2]
CL3[Node 3]
CL4[Node 4]
CL5[Node 5]
CL6[Node 6]
CL1---CL2
CL2---CL3
CL3---CL4
CL4---CL5
CL5---CL6
end
subgraph Chains
SC1[[Private Chain 1]]
SC2[[Private Chain 2]]
end
SC1<-->SD
SC2<-->SD
MS([Mock Server])
MS-->SD
TC[/Test Code\]
TC<-->MS
TC<-->Chains
TC<-->SD
```
### Using Remote Kubernetes Cluster
For running more complex and intensive tests (like load and chaos tests) you need to connect the test to a Kubernetes cluster. These tests have more complex setup and running instructions. We endeavor to make these easier to run and configure, but for the time being please seek a member of the QA/Test Tooling team if you want to run these.
Loading

0 comments on commit 3e4758f

Please sign in to comment.