Skip to content
Open
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
72 changes: 72 additions & 0 deletions .env.e2e.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# CarbonLedger E2E Test Environment
# Copy this to .env.e2e and fill in with your test environment values

# ─────────────────────────────────────────────────────────────────────────────
# Stellar Network Configuration
# ─────────────────────────────────────────────────────────────────────────────

# Stellar RPC endpoint for Soroban operations
STELLAR_RPC_URL=https://soroban-testnet.stellar.org

# Stellar Horizon endpoint (optional, for account queries)
STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org

# Network passphrase for Testnet
NETWORK_PASSPHRASE=Test SDF Network ; September 2015

# ─────────────────────────────────────────────────────────────────────────────
# Smart Contract IDs (deployed on Stellar Testnet)
# ─────────────────────────────────────────────────────────────────────────────

# Carbon Oracle contract address
# E.g., CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4
CARBON_ORACLE_CONTRACT_ID=

# Carbon Registry contract address
# E.g., CBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4
CARBON_REGISTRY_CONTRACT_ID=

# ─────────────────────────────────────────────────────────────────────────────
# Test Accounts & Keys
# ─────────────────────────────────────────────────────────────────────────────

# Secret key of the Oracle account (authorized to submit monitoring data)
# Must be a Stellar keypair with testnet funds
# E.g., SBJC6A4D5ZWQ7R5H7YQXZ2W3X4Y5Z6A7B8C9D0E1F2G3H4I5J6K7L8
ORACLE_SECRET_KEY=

# JWT token for backend API authentication (generated during test setup)
TEST_JWT_TOKEN=

# ─────────────────────────────────────────────────────────────────────────────
# Backend Service Configuration
# ─────────────────────────────────────────────────────────────────────────────

# Backend API base URL
BACKEND_API_URL=http://localhost:3001

# JWT secret for generating test tokens
JWT_SECRET=your-secret-key-here

# Database configuration for test environment
DATABASE_URL=postgresql://carbonledger:testpass@localhost:5432/carbonledger_test

# ─────────────────────────────────────────────────────────────────────────────
# Test Configuration
# ─────────────────────────────────────────────────────────────────────────────

# Project ID to use for E2E tests
TEST_PROJECT_ID=test-project-e2e-001

# Notification webhook for test results (optional)
SLACK_WEBHOOK_URL=

# ─────────────────────────────────────────────────────────────────────────────
# External APIs (Optional)
# ─────────────────────────────────────────────────────────────────────────────

# Xpansiv CBL API key for price oracle
XPANSIV_API_KEY=

# Toucan Protocol API key for price oracle
TOUCAN_API_KEY=
150 changes: 150 additions & 0 deletions .github/workflows/e2e-oracle-soroban.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: E2E Tests - Oracle → Soroban Pipeline (Nightly)

on:
schedule:
# Run every night at 2 AM UTC
- cron: "0 2 * * *"
# Also allow manual trigger for testing
workflow_dispatch:

env:
STELLAR_NETWORK: testnet
STELLAR_RPC_URL: https://soroban-testnet.stellar.org
STELLAR_HORIZON_URL: https://horizon-testnet.stellar.org
BACKEND_API_URL: http://localhost:3001
POSTGRES_PASSWORD: testpass

jobs:
e2e-tests:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: carbonledger_test
POSTGRES_USER: carbonledger
POSTGRES_PASSWORD: testpass
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"

- name: Setup environment variables
run: |
echo "DATABASE_URL=postgresql://carbonledger:testpass@localhost:5432/carbonledger_test" >> $GITHUB_ENV
echo "REDIS_HOST=localhost" >> $GITHUB_ENV
echo "REDIS_PORT=6379" >> $GITHUB_ENV
echo "JWT_SECRET=${{ secrets.JWT_SECRET || 'test-secret-key-e2e' }}" >> $GITHUB_ENV
echo "ORACLE_SECRET_KEY=${{ secrets.TEST_ORACLE_SECRET_KEY }}" >> $GITHUB_ENV
echo "CARBON_ORACLE_CONTRACT_ID=${{ secrets.CARBON_ORACLE_CONTRACT_ID }}" >> $GITHUB_ENV
echo "CARBON_REGISTRY_CONTRACT_ID=${{ secrets.CARBON_REGISTRY_CONTRACT_ID }}" >> $GITHUB_ENV
echo "TEST_PROJECT_ID=test-project-e2e-$(date +%s)" >> $GITHUB_ENV

- name: Install backend dependencies
working-directory: ./backend
run: npm ci

- name: Run database migrations
working-directory: ./backend
run: |
npx prisma migrate deploy

- name: Start backend server (background)
working-directory: ./backend
run: |
npm run build
npm run start:prod &
sleep 5

- name: Wait for backend to be ready
run: |
for i in {1..30}; do
if curl -f http://localhost:3001/api/v1/health 2>/dev/null; then
echo "Backend is ready"
exit 0
fi
echo "Waiting for backend... ($i/30)"
sleep 2
done
echo "Backend failed to start"
exit 1

- name: Run E2E tests (Stellar Testnet)
working-directory: ./backend
run: |
npm run test:e2e -- --verbose
env:
STELLAR_NETWORK: testnet
STELLAR_RPC_URL: https://soroban-testnet.stellar.org
BACKEND_API_URL: http://localhost:3001

- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: e2e-test-results
path: backend/coverage/

- name: Post test summary to Slack (on failure)
if: failure()
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "❌ CarbonLedger E2E Tests Failed",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*E2E Tests - Oracle → Soroban Pipeline*\n*Status:* ❌ Failed\n*Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>\n*Network:* Stellar Testnet"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Post test summary to Slack (on success)
if: success()
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "✅ CarbonLedger E2E Tests Passed",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*E2E Tests - Oracle → Soroban Pipeline*\n*Status:* ✅ Passed\n*Run:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View Details>\n*Network:* Stellar Testnet"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Loading