This document provides comprehensive testing instructions for SKALE Consensus, including unit tests, integration tests, and end-to-end testing scenarios.
Tests in the SKALE Consensus codebase follow a multi-dimensional tagging and directory structure that promotes clarity, modularity, and scalability. The tagging system is structured along three main dimensions: Component, Test Type, and Scope.
Directory Structure
Each unit test must reside in a directory named after the component it tests. For example:
rlp/for RLP-related testscrypto/for cryptographic component testsconsensus/for consensus algorithm logicnetwork/for network-level functionality
Tagging Rules:
- All tests within a given directory must be tagged with the corresponding component tag, e.g.,
[rlp],[crypto]. - Tests targeting specific internal classes or modules should include a sub-component tag, typically matching the tested class or submodule name.
Examples:
[rlp][rlp-stream]for tests inrlp/RLPStreamTests.cpp[rlp][rlp-item]for tests inrlp/RLPItemTests.cpp
These tags describe the purpose or concern of the test:
-
[correctness]: Ensures functional correctness and semantic compliance of the component under test.
Example: Validating that RLP-encoded data decodes back to the original form. -
[security]: Verifies enforcement of non-functional safety constraints that prevent potential abuse or misuse.
Example: Checking input size bounds, nesting depth limits, or overflow protections. -
[performance]: Benchmarks throughput, latency, or resource usage of specific operations.
Example: Measuring cryptographic signing speed or RLP parsing time for large inputs.
Note: Security tests focus on constraints that do not affect correctness, but are critical to system safety (e.g., limiting input data size or computational cost).
These tags define the granularity of the test:
[unit]: Isolated testing of a single component or class, independent of external systems.[integration]: Tests the interaction between multiple components or subsystems.[end-to-end]: Tests the complete consensus pipeline or system behavior under realistic or simulated conditions.
# Run all RLP correctness unit tests
./build/consensust [rlp][unit][correctness]
# Run all security RLP tests (any scope)
./build/consensust [rlp][security]
# Run all performance tests
./build/consensust [performance]
# Run all non-performance tests
./build/consensust ~[performance]End-to-end tests simulate real network conditions with multiple nodes.
cd test/onenode
sudo NO_ULIMIT_CHECK=1 TEST_TIME_S=180 TEST_TRANSACTIONS_PER_BLOCK=10 ../../build/consensust [consensus-basic]For 4-node and 16-node tests, you need to set up SGX simulation first (see SGX Simulation Testing).
# 4-node test
cd test/fournodes
sudo TEST_TIME_S=180 TEST_TRANSACTIONS_PER_BLOCK=10 ../../build/consensust [consensus-basic]
# 16-node test
cd test/sixteennodes
sudo TEST_TIME_S=180 TEST_TRANSACTIONS_PER_BLOCK=10 ../../build/consensust [consensus-basic]TEST_TIME_S- Test duration in secondsTEST_TRANSACTIONS_PER_BLOCK- Number of transactions per blockNO_ULIMIT_CHECK=1- Bypass ulimit checks (for single-node tests)
Multi-node tests require SGX wallet simulation using Docker.
Install Docker and Docker Compose:
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up the repository
echo \
"deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugincd run_sgx_test
sudo ./run.bashThe SGX wallet takes several minutes to initialize. Monitor progress:
docker logs run_sgx_test-sgxwallet-1Ready when you see:
[2025-05-20 12:49:43.323] [info] Started zmq read loop.
Found test keys.
Check that configuration files are available:
cd sgx_data
lsYou should see:
4node.json- Configuration for 4-node tests16node.json- Configuration for 16-node tests
When adding new tests:
- Use appropriate tags following the component/type/scope convention
- Place tests in correct directories matching the component tag
- Include both positive and negative test cases
- Add performance tests for critical paths
- Document any special setup requirements
For more information on contributing, see the main README.md.