Files
smom-dbis-138/docs/guides/TESTING_GUIDE.md
defiQUG 1fb7266469 Add Oracle Aggregator and CCIP Integration
- Introduced Aggregator.sol for Chainlink-compatible oracle functionality, including round-based updates and access control.
- Added OracleWithCCIP.sol to extend Aggregator with CCIP cross-chain messaging capabilities.
- Created .gitmodules to include OpenZeppelin contracts as a submodule.
- Developed a comprehensive deployment guide in NEXT_STEPS_COMPLETE_GUIDE.md for Phase 2 and smart contract deployment.
- Implemented Vite configuration for the orchestration portal, supporting both Vue and React frameworks.
- Added server-side logic for the Multi-Cloud Orchestration Portal, including API endpoints for environment management and monitoring.
- Created scripts for resource import and usage validation across non-US regions.
- Added tests for CCIP error handling and integration to ensure robust functionality.
- Included various new files and directories for the orchestration portal and deployment scripts.
2025-12-12 14:57:48 -08:00

6.3 KiB

Testing Guide

Last Updated: 2025-01-27
Status: Active

This guide explains the testing infrastructure and how to run tests for the DeFi Oracle Meta Mainnet project.

Table of Contents

Overview

The project includes a comprehensive testing infrastructure with multiple layers:

  • Unit Tests - Contract-level tests using Foundry
  • Integration Tests - Cross-contract and service integration tests
  • End-to-End Tests - Full system tests
  • Load Tests - Performance and stress tests
  • Security Tests - Vulnerability scanning

Test Structure

Contract Tests

Located in test/ directory:

test/
├── Aggregator.t.sol          # Oracle aggregator tests
├── AggregatorFuzz.t.sol      # Fuzz tests for aggregator
├── WETH.t.sol                # WETH9 tests
├── WETH10.t.sol              # WETH10 tests
├── Multicall.t.sol          # Multicall tests
├── CCIPWETH9Bridge.t.sol    # CCIP WETH9 bridge tests
├── CCIPWETH10Bridge.t.sol   # CCIP WETH10 bridge tests
├── TwoWayBridge.t.sol       # Two-way bridge tests
├── ccip/                     # CCIP integration tests
└── e2e/                      # End-to-end tests

Integration Tests

Located in tests/ directory:

tests/
├── e2e/                      # End-to-end test suites
├── health-check.sh           # Health check script
├── load-test.sh              # General load test
├── load-test-rpc.sh          # RPC load test
├── load-test-oracle.sh       # Oracle load test
├── load-test-ccip.sh         # CCIP load test
├── load-test-production.sh   # Production load test
├── metamask-integration.test.ts  # MetaMask integration tests
└── playwright.config.ts      # Playwright configuration

Running Tests

Contract Tests (Foundry)

# Run all contract tests
forge test

# Run specific test file
forge test --match-path test/WETH.t.sol

# Run with verbosity
forge test -vvv

# Run with gas reporting
forge test --gas-report

# Run fuzz tests
forge test --match-contract Fuzz

Integration Tests

# Run health check
./tests/health-check.sh

# Run load tests
./tests/load-test.sh

# Run RPC load test
./tests/load-test-rpc.sh

# Run oracle load test
./tests/load-test-oracle.sh

# Run CCIP load test
./tests/load-test-ccip.sh

End-to-End Tests

# Run E2E tests
cd tests/e2e
npm test

# Run with Playwright
npx playwright test

All Tests

# Run all tests using Makefile
make test

# Or run tests in parallel
make test-parallel

Writing Tests

Foundry Test Structure

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Test, console} from "forge-std/Test.sol";
import {MyContract} from "../contracts/MyContract.sol";

contract MyContractTest is Test {
    MyContract public contract;
    address public deployer;

    function setUp() public {
        deployer = address(this);
        contract = new MyContract();
    }

    function testFunction() public {
        // Arrange
        uint256 expected = 100;
        
        // Act
        uint256 result = contract.function();
        
        // Assert
        assertEq(result, expected);
    }

    function testFuzz(uint256 input) public {
        // Fuzz test
        uint256 result = contract.function(input);
        assertTrue(result >= 0);
    }
}

Integration Test Structure

#!/bin/bash
# Integration test example

set -e

# Setup
RPC_URL="${RPC_URL:-http://localhost:8545}"

# Test
echo "Testing RPC endpoint..."
response=$(curl -X POST "$RPC_URL" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}')

# Verify
if echo "$response" | grep -q "result"; then
    echo "✅ Test passed"
    exit 0
else
    echo "❌ Test failed"
    exit 1
fi

Test Types

Unit Tests

Purpose: Test individual contract functions

Location: test/*.t.sol

Example:

function testDeposit() public {
    weth.deposit{value: 1 ether}();
    assertEq(weth.balanceOf(address(this)), 1 ether);
}

Integration Tests

Purpose: Test interactions between contracts

Location: test/ccip/, test/e2e/

Example:

function testCCIPBridge() public {
    // Deploy bridge
    // Send message
    // Verify on destination
}

End-to-End Tests

Purpose: Test full system workflows

Location: tests/e2e/

Example:

  • Deploy contracts
  • Configure oracle
  • Send transactions
  • Verify results

Load Tests

Purpose: Test system under load

Location: tests/load-test*.sh

Example:

# Test RPC under load
./tests/load-test-rpc.sh --requests 1000 --concurrent 10

Fuzz Tests

Purpose: Find edge cases through random input

Location: test/*Fuzz.t.sol

Example:

function testFuzzTransfer(uint256 amount) public {
    amount = bound(amount, 1, type(uint256).max);
    // Test with random amounts
}

CI/CD Integration

GitHub Actions Example

name: Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
      - name: Run tests
        run: forge test
      - name: Run integration tests
        run: ./tests/health-check.sh

Test Best Practices

  1. Test Coverage

    • Aim for >80% coverage
    • Test happy paths
    • Test error cases
    • Test edge cases
  2. Test Organization

    • One test file per contract
    • Group related tests
    • Use descriptive names
    • Document complex tests
  3. Test Data

    • Use fixtures for complex data
    • Use fuzzing for edge cases
    • Test with realistic data
    • Test boundary conditions
  4. Test Maintenance

    • Keep tests up to date
    • Fix flaky tests
    • Remove obsolete tests
    • Review test failures

Last Updated: 2025-01-27