Skip to content

Conversation

@gertsio
Copy link
Collaborator

@gertsio gertsio commented Jan 16, 2026

Summary

Closes #37

Key finding: The deterministic CREATE2 deployment was already implemented. This PR adds test coverage and documentation to verify and formalize the existing behavior.

What Was Already Done (No Changes Needed)

  • predictSafeAddress() uses Protocol Kit's predictedSafe config ✅
  • saltNonce generated per company: ${timestamp}${labelHash}
  • Safe Proxy Factory v1.4.1 used automatically by Protocol Kit ✅

What This PR Adds

Category Changes
Unit Tests 13 tests for calculateThreshold()
Integration Tests Sepolia test: predicted address === deployed address
CI Workflows ci.yml (every PR), integration-safe.yml (main/manual)
Documentation saltNonce strategy documented in code
Cleanup Removed low-value tests, refactored actions tests

Answers to Issue Questions

  1. Proxy Factory addresses? → Protocol Kit handles automatically (0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67)
  2. Library approach? → Keep @safe-global/protocol-kit (current)
  3. Default or gated? → Already default, no gating needed

Test Commands

yarn test:unit        # Unit tests (21 tests)
yarn test:integration # Sepolia deployment (requires SEPOLIA_TEST_WALLET_KEY)

CI Setup Required

Add SEPOLIA_TEST_WALLET_KEY secret in GitHub repo settings (funded Sepolia wallet).

Greptile Summary

This PR adds test coverage and documentation for the existing deterministic Safe deployment implementation. The key finding was that CREATE2 deployment was already working correctly via Protocol Kit - this PR validates and formalizes that behavior.

What was added:

  • 13 unit tests for calculateThreshold() covering edge cases (solo, 2-founder, multi-founder, cap at 5)
  • Integration test validating predicted address matches deployed address on Sepolia
  • CI workflows: ci.yml runs unit tests/typecheck/lint on every PR; integration-safe.yml runs Sepolia deployment tests on main pushes
  • Documentation in safe-factory.ts explaining saltNonce strategy: ${timestamp}${labelHash} generates unique addresses per company
  • Test refactoring: removed low-value event tests, split actions tests into focused describe blocks

Critical for production:

  • Add SEPOLIA_TEST_WALLET_KEY secret to GitHub repo settings (funded Sepolia wallet needed for integration tests)
  • Integration tests deploy real Safes on Sepolia (~0.01 ETH per run)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it adds test coverage without changing production code
  • Score reflects that this is purely additive (tests + docs + CI), with no changes to the core safe-factory.ts implementation beyond documentation. The integration test validates the critical property that predicted addresses match deployed addresses.
  • No files require special attention - check that SEPOLIA_TEST_WALLET_KEY secret is configured before integration tests run

Important Files Changed

Filename Overview
src/lib/blockchain/safe-factory.ts Added comprehensive docs explaining CREATE2 deterministic deployment strategy with saltNonce
src/lib/blockchain/safe-factory.test.ts Comprehensive unit tests for calculateThreshold and getThresholdDescription covering all edge cases
src/lib/blockchain/safe-factory.integration.test.ts Validates prediction matches deployed address on Sepolia (requires SEPOLIA_TEST_WALLET_KEY secret)
.github/workflows/ci.yml Standard CI setup with unit tests, typecheck, and lint jobs on every PR
.github/workflows/integration-safe.yml Integration test workflow that runs on main push or manually, tests actual Safe deployment on Sepolia

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant GH as GitHub PR
    participant CI as CI Workflow
    participant Unit as Unit Tests
    participant Int as Integration Tests
    participant Sepolia as Sepolia Testnet
    
    Dev->>GH: Push PR
    GH->>CI: Trigger ci.yml
    CI->>Unit: yarn test:unit
    Unit->>Unit: Test calculateThreshold()
    Unit->>Unit: Test getThresholdDescription()
    Unit-->>CI: ✓ 13 tests pass
    
    CI->>CI: yarn tsc --noEmit
    CI-->>GH: ✓ Typecheck pass
    
    CI->>CI: yarn lint
    CI-->>GH: ✓ Lint pass
    
    alt On main branch push or manual trigger
        GH->>Int: Trigger integration-safe.yml
        Int->>Int: Load SEPOLIA_TEST_WALLET_KEY
        Int->>Sepolia: predictSafeAddress(owners, saltNonce)
        Sepolia-->>Int: 0xPredictedAddress
        Int->>Sepolia: deploySafe(owners, saltNonce)
        Sepolia-->>Int: 0xDeployedAddress
        Int->>Int: Assert predicted === deployed
        Int-->>GH: ✓ Addresses match (CREATE2 works)
    end
    
    GH-->>Dev: All checks pass ✓
Loading

@vercel
Copy link

vercel bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
startupchain Ready Ready Preview, Comment Jan 16, 2026 7:29pm

@greptile-apps
Copy link

greptile-apps bot commented Jan 16, 2026

Greptile found no issues!

From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

- ci.yml: unit tests, typecheck, lint on every PR
- integration-safe.yml: Safe deployment tests on main/manual
- vitest.config.ts: load .env for integration tests
- .gitignore: ignore test-results/
- Test threshold calculation for 1-100 founders
- Verify ceil(n/2) formula for 3-5 founders
- Verify cap at 5 for 6+ founders
- Test error on 0 or negative owners
- Verify predictSafeAddress() matches actual deployed address
- Verify different saltNonce produces different addresses
- Requires SEPOLIA_TEST_WALLET_KEY env var
- Split monolithic actions test into focused unit tests
- Remove complex mock-heavy registration flow test
- Delete get-company-events.test.ts (low value, just tests mapping)
- Keep: availability, cost, owner action tests
- Explain saltNonce uniqueness per company
- Document threshold presets
- Clarify Safe Protocol Kit usage
@gertsio
Copy link
Collaborator Author

gertsio commented Jan 16, 2026

@greptileai

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage and CI workflows for the existing deterministic (CREATE2) Safe deployment functionality. The implementation was already working correctly, and this PR purely adds tests, documentation, and automation without modifying any business logic.

Changes:

  • Added 13 unit tests for Safe threshold calculation logic
  • Added Sepolia integration tests to verify predicted addresses match deployed addresses
  • Added CI workflows for automated testing and quality checks
  • Refactored existing test suite for better organization and maintainability
  • Added vitest configuration for environment variable loading

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/lib/blockchain/safe-factory.ts Added comprehensive documentation for CREATE2 deployment and saltNonce usage
src/lib/blockchain/safe-factory.test.ts Added unit tests for calculateThreshold() and getThresholdDescription() functions
src/lib/blockchain/safe-factory.integration.test.ts Added Sepolia integration tests for deterministic Safe deployment
src/app/(app)/dashboard/setup/actions.test.ts Refactored tests into focused describe blocks, removed unnecessary mocks
src/lib/blockchain/get-company-events.test.ts Deleted low-value test file
vitest.config.ts Added configuration for environment variable loading
package.json Added packageManager field for Yarn 4.12.0
.gitignore Added test-results directory to gitignore
.github/workflows/ci.yml Added CI workflow for unit tests, type checking, and linting
.github/workflows/integration-safe.yml Added Safe deployment integration test workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gertsio gertsio merged commit b189ac7 into main Jan 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use deterministic proxy (CREATE2) for Safe deployments instead of Singleton Factory

1 participant