Skip to content

Add comprehensive test coverage for factory contract edge cases #20

Description

@prodbycorne

Overview

The factory contract's test.rs is missing tests for several critical paths. The following scenarios are untested and could mask regressions:

Missing Test Cases

initialize

  • Double-initialization returns Err(FactoryError::AlreadyInitialized) — not just that it errors, but that the error code matches
  • pool_count is exactly 0 immediately after init

transfer_admin

  • Non-admin address calling transfer_admin is rejected
  • After transfer, old admin can no longer call create_pool
  • adm_xfr event emitted with correct (old, new) payload
  • New admin can immediately call create_pool

create_pool

  • Non-admin calling create_pool is rejected
  • Pool addresses are deterministic — same factory + same pool_id always yields the same address
  • pool_count increments by 1 for each created pool
  • pool_crtd event includes correct asset, daily_rate, min_lock_period payload
  • Pool created at ID 0, then ID 1 — get_pool(0) still returns ID 0's data
  • Zero daily_rate pool created — pool record stores 0 correctly

get_pool

  • pool_id beyond pool_count returns Err(FactoryError::PoolNotFound)
  • TTL is bumped on every get_pool call (verify via storage TTL inspection)

pool_wasm_hash

  • Returns the exact hash passed at initialization

Setup Note

Use soroban_sdk::testutils::EnvBuilder with register_at to install a mock WASM hash for pool deployment tests.

Acceptance Criteria

  • All test cases above implemented in factory/src/test.rs
  • Each test uses a descriptive #[test] function name
  • No unwrap() in test assertions — use assert_eq! with Ok(...)\ / Err(...)`
  • Tests run in < 5 seconds with cargo test

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignfactoryFactory contracttestingTests and test coverage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions