Skip to content
Draft
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
81 changes: 81 additions & 0 deletions Contributing/Overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Contributing Guide

Thank you for your interest in contributing to the Chainlink Testing Framework (CTF)! We welcome contributions from the community to improve the framework, add features, fix bugs, and enhance documentation.

---

## How to Contribute

1. **Fork the repository** and create your branch from `main`.
2. **Open an issue** to discuss your proposed change if it's non-trivial.
3. **Write clear, maintainable code** and add tests for new features or bug fixes.
4. **Document your changes** in the code and/or wiki as appropriate.
5. **Open a Pull Request (PR)** with a clear description of your changes and link to any relevant issues.
6. **Participate in code review** and address feedback promptly.

---

## Code of Conduct

We are committed to fostering a welcoming and inclusive environment. Please read and follow our [Code of Conduct](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/CODE_OF_CONDUCT.md).

---

## Development Setup

1. **Clone the repository**
```bash
git clone https://github.com/smartcontractkit/chainlink-testing-framework.git
cd chainlink-testing-framework
```
2. **Install dependencies**
- [Go](https://go.dev/doc/install) 1.21+
- [Docker](https://www.docker.com/)
- [direnv](https://direnv.net/) (optional, for environment management)
- [nix](https://nixos.org/manual/nix/stable/installation/installation.html) (optional, for dev environments)
3. **Set up your environment**
```bash
cp Getting-Started/Installation.md .
# Follow the installation instructions for your OS
```
4. **Run tests locally**
```bash
CTF_CONFIGS=smoke.toml go test -v
```
5. **Lint and format your code**
```bash
go fmt ./...
go vet ./...
golangci-lint run
```

---

## Pull Request Process

1. **Open a draft PR** early to get feedback.
2. **Ensure all tests pass** and code is linted.
3. **Describe your changes** clearly in the PR description.
4. **Link to any related issues** (e.g., `Closes #123`).
5. **Request review** from maintainers or relevant code owners.
6. **Address review comments** and update your PR as needed.
7. **Wait for approval and merge** (maintainers will handle merging).

---

## Getting Help

- **Search issues**: [GitHub Issues](https://github.com/smartcontractkit/chainlink-testing-framework/issues)
- **Ask in discussions**: [GitHub Discussions](https://github.com/smartcontractkit/chainlink-testing-framework/discussions)
- **Open a new issue** for bugs, feature requests, or questions
- **Contact maintainers** via GitHub if you need further assistance

---

## Resources
- [Home](../Home)
- [Installation Guide](../Getting-Started/Installation)
- [API Reference](../Reference/API-Reference)
- [Troubleshooting](../Reference/Troubleshooting)
- [Code of Conduct](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/CODE_OF_CONDUCT.md)
- [LICENSE](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/LICENSE)
179 changes: 179 additions & 0 deletions Examples/Advanced-Examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Advanced Examples

This page provides advanced and real-world test scenarios using the Chainlink Testing Framework (CTF). These examples demonstrate how to leverage CTF for complex, production-like workflows.

---

## 1. Multi-Chain Integration Test

Test a system that interacts with multiple blockchains (e.g., Ethereum and Solana) and verifies cross-chain data flow.

```toml
[ethereum]
type = "geth"
image = "ethereum/client-go"
tag = "v1.12.0"
pull_image = true

[solana]
type = "solana"
image = "solanalabs/solana"
tag = "v1.16.0"
pull_image = true

[chainlink_node]
image = "public.ecr.aws/chainlink/chainlink"
tag = "2.7.0"
pull_image = true
```

```go
func TestMultiChainIntegration(t *testing.T) {
type Config struct {
Ethereum *blockchain.Input `toml:"ethereum" validate:"required"`
Solana *blockchain.Input `toml:"solana" validate:"required"`
ChainlinkNode *clnode.Input `toml:"chainlink_node" validate:"required"`
}
in, err := framework.Load[Config](t)
require.NoError(t, err)
eth, err := blockchain.NewBlockchainNetwork(in.Ethereum)
require.NoError(t, err)
sol, err := blockchain.NewBlockchainNetwork(in.Solana)
require.NoError(t, err)
cl, err := clnode.NewChainlinkNode(in.ChainlinkNode)
require.NoError(t, err)
// ... deploy contracts, set up jobs, verify cross-chain data
}
```

---

## 2. Upgrade and Migration Test

Test that a Chainlink node or contract can be upgraded without breaking existing functionality.

```toml
[chainlink_node]
image = "public.ecr.aws/chainlink/chainlink"
tag = "2.6.0"
pull_image = true
```

```go
func TestUpgrade(t *testing.T) {
// Deploy with old version
in, err := framework.Load[Config](t)
require.NoError(t, err)
cl, err := clnode.NewChainlinkNode(in.ChainlinkNode)
require.NoError(t, err)
// ... run smoke test

// Upgrade node
in.ChainlinkNode.Tag = "2.7.0"
clUpgraded, err := clnode.NewChainlinkNode(in.ChainlinkNode)
require.NoError(t, err)
// ... verify data, jobs, and state are preserved
}
```

---

## 3. Chaos Engineering Test

Inject failures and network issues to test system resilience using Havoc.

```go
func TestChaosResilience(t *testing.T) {
in, err := framework.Load[Config](t)
require.NoError(t, err)
cl, err := clnode.NewChainlinkNode(in.ChainlinkNode)
require.NoError(t, err)
// Start chaos experiment
client, err := havoc.NewClient()
require.NoError(t, err)
chaos, err := havoc.NewChaos(client, createNetworkChaos())
require.NoError(t, err)
err = chaos.Create(context.Background())
require.NoError(t, err)
// ... run test logic while chaos is active
chaos.Delete(context.Background())
}
```

---

## 4. Performance and Load Test

Use WASP to generate load and measure system performance under stress.

```go
func TestPerformance(t *testing.T) {
profile := wasp.NewProfile()
generator := wasp.NewGenerator(&wasp.Config{
T: 60 * time.Second,
RPS: 100,
LoadType: wasp.RPS,
Schedule: wasp.Plain(100, 60*time.Second),
})
generator.AddRequestFn(func(ctx context.Context) error {
// Simulate contract call or API request
return nil
})
profile.Add(generator)
_, err := profile.Run(true)
require.NoError(t, err)
}
```

---

## 5. End-to-End Oracle Test

Test the full workflow from contract deployment to job fulfillment and data reporting.

```go
func TestOracleE2E(t *testing.T) {
in, err := framework.Load[Config](t)
require.NoError(t, err)
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
require.NoError(t, err)
cl, err := clnode.NewChainlinkNode(in.ChainlinkNode)
require.NoError(t, err)
// Deploy oracle contract
// Register job on Chainlink node
// Send request and verify fulfillment
}
```

---

## 6. Real-World: Staging Environment Reuse

Reuse cached components and substitute staging URLs for persistent environment testing.

```toml
[blockchain_a]
type = "anvil"
use_cache = true
external_url = "https://staging-eth.example.com"

[chainlink_node]
use_cache = true
external_url = "https://staging-cl.example.com"
```

```go
func TestStagingReuse(t *testing.T) {
in, err := framework.Load[Config](t)
require.NoError(t, err)
// Use staging URLs for integration tests
}
```

---

## More Examples
- [WASP Load Testing](../Libraries/WASP)
- [Havoc Chaos Testing](../Libraries/Havoc)
- [Seth Ethereum Client](../Libraries/Seth)
- [Framework Examples Directory](https://github.com/smartcontractkit/chainlink-testing-framework/tree/main/framework/examples/myproject)
107 changes: 107 additions & 0 deletions Examples/Use-Cases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Real-World Use Cases

This page highlights real-world scenarios where the Chainlink Testing Framework (CTF) is used to ensure reliability, performance, and security in production systems.

---

## 1. Production-Grade End-to-End Testing

**Scenario:**
- A Chainlink-integrated DeFi protocol needs to verify that price feeds, job fulfillment, and contract upgrades work as expected across multiple networks.

**How CTF Helps:**
- Deploys ephemeral or persistent test environments that mirror production.
- Runs full workflows: contract deployment, job registration, data requests, and fulfillment.
- Validates on-chain and off-chain integration.

---

## 2. CI/CD Pipeline Integration

**Scenario:**
- Every pull request must pass a suite of integration, performance, and chaos tests before merging.

**How CTF Helps:**
- Runs in GitHub Actions or other CI systems.
- Uses caching to speed up repeated test runs.
- Fails fast on regressions, configuration errors, or performance degradations.
- Exposes logs and metrics for debugging failed builds.

---

## 3. Protocol Upgrade and Migration Testing

**Scenario:**
- A new Chainlink node version or smart contract upgrade must be validated for backward compatibility and data integrity.

**How CTF Helps:**
- Spins up old and new versions side-by-side.
- Runs upgrade and migration scripts.
- Verifies that jobs, data, and state persist across upgrades.
- Detects breaking changes before they reach production.

---

## 4. Cross-Chain and Multi-Network Testing

**Scenario:**
- A dApp or oracle service operates across Ethereum, Solana, and other chains, requiring cross-chain data flow validation.

**How CTF Helps:**
- Deploys multiple blockchains in parallel.
- Simulates cross-chain requests and data propagation.
- Validates data consistency and latency across networks.

---

## 5. Oracle Network Resilience and Chaos Engineering

**Scenario:**
- The reliability of a Chainlink DON (Decentralized Oracle Network) must be tested under network partitions, node failures, and resource exhaustion.

**How CTF Helps:**
- Uses Havoc to inject network latency, pod failures, and resource limits.
- Monitors system health and recovery.
- Validates that the DON continues to serve data or recovers gracefully.

---

## 6. Performance Benchmarking and Load Testing

**Scenario:**
- A new Chainlink job type or protocol feature must be benchmarked for throughput and latency under load.

**How CTF Helps:**
- Uses WASP to generate synthetic or user-based load.
- Collects metrics via Prometheus and visualizes in Grafana.
- Identifies bottlenecks and regression points.

---

## 7. Staging Environment Validation

**Scenario:**
- Before a mainnet release, the team wants to validate the full stack in a persistent staging environment.

**How CTF Helps:**
- Reuses cached components and substitutes staging URLs.
- Runs upgrade, chaos, and performance tests against the staging stack.
- Ensures production readiness with minimal manual intervention.

---

## 8. Custom Component and Plugin Testing

**Scenario:**
- A team develops a custom Chainlink external adapter or plugin and needs to validate it in a realistic environment.

**How CTF Helps:**
- Easily adds custom components to the test config.
- Runs integration and chaos tests with the new plugin.
- Validates compatibility with existing Chainlink nodes and contracts.

---

## More Use Cases
- [Chainlink Blog: Testing at Scale](https://blog.chain.link/)
- [Framework Examples Directory](https://github.com/smartcontractkit/chainlink-testing-framework/tree/main/framework/examples/myproject)
Loading
Loading