Skip to Content

Testing Coverage

Methodology

The Welsh Street Exchange employs a comprehensive testing framework that validates every contract function and error condition. The testing approach prioritizes complete coverage through dedicated test files for each function, systematic error validation, and chain state verification.

Testing Architecture

The testing system utilizes a modular design with separate helper functions and test files:

  • Test files (*.test.ts): Contain test scenarios and expectations
  • Helper functions (*-helper-functions.ts): Handle contract interactions and validation logic
  • Setup functions: Establish complex contract states for testing scenarios

Validation Approach

Each test validates actual blockchain state rather than reiterating expected values. Helper functions calculate expected outcomes and compare them against chain state, ensuring accurate bug detection. This methodology replaces legacy testing patterns that failed to detect state inconsistencies.

Coverage Principles

  • Function Coverage: Every public function has a dedicated test suite
  • Error Coverage: Each error code is tested independently
  • State Isolation: Tests run with fresh simnet state to prevent interference
  • Integration Testing: Contract-to-contract calls validated through integration scenarios

Metrics

Current Status: 124 tests passing across 34 test files (Duration: 2.97s)

Coverage Statistics

  • Contracts Tested: 5 of 5 (100%)
  • Functions Tested: 52 of 52 (100%)
  • Error Codes Tested: 20 of 20 (100%)
  • Test Files: 34
  • Total Test Cases: 124

Contract Coverage

ContractFunctionsError CodesTest FilesCoverage
street.clar8/86/64100%
exchange.clar16/167/712100%
credit.clar6/62/24100%
rewards.clar10/102/27100%
genesis.clar11/113/37100%

Note: welshcorgicoin.clar is excluded from testing as it exists on mainnet. An exact copy was used to replicate production environment conditions.

Testing Infrastructure

Test Categories

Function Tests: 89 tests covering all public functions Error Tests: 35 tests covering all error conditions Read-Only Tests: 20 tests covering state query functions Integration Tests: Cross-contract interaction validation Setup Tests: Complex state establishment verification

Specialized Testing

Contract-to-Contract Calls: Functions restricted to authorized contracts tested through integration scenarios Kill-Switch Testing: Emergency mechanisms tested with special contract configurations Supply Limit Testing: Token supply boundaries validated with modified emission constants Access Control: Authorization mechanisms tested across all privilege levels

Contract Inventory

Credit Token

  • Contract: credit.clar
  • Functions: 6 (mint, burn, transfer, SIP-010 functions)
  • Error codes: 2 (authorization, amounts)
  • Test files: 4 (credit-mint, credit-burn, transfer, ownership)

Exchange Contract

  • Contract: exchange.clar
  • Functions: 16 (liquidity operations, swaps, parameters, treasury)
  • Error codes: 7 (initialization, amounts, authorization, calculations)
  • Test files: 12 (liquidity operations, swaps, parameters, read-only, scenarios)

Genesis Contract

  • Contract: genesis.clar
  • Functions: 11 (contribution, claiming, withdrawal, phase management, queries)
  • Error codes: 3 (authorization, phases, amounts)
  • Test files: 7 (contribute, claim, withdrawal, phase controls, read-only)

Rewards Contract

  • Contract: rewards.clar
  • Functions: 10 (claiming, donations, updates, cleanup, queries)
  • Error codes: 2 (authorization, amounts)
  • Test files: 7 (rewards operations, user updates, cleanup, read-only)

Street Token

  • Contract: street.clar
  • Functions: 8 (minting, emission, kill-switch, transfers, queries)
  • Error codes: 6 (authorization, limits, intervals, supply)
  • Test files: 4 (street-mint, emission-mint, mine-burn-block, street-read-only)

Test Execution

All tests execute in isolated simnet environments with fresh state per test case. The testing framework validates contract behavior under normal operations, error conditions, and edge cases to ensure system reliability and security.

Test Inventory

Credit Token

Contract: credit.clar - 12 Tests

credit-mint.test.ts (3 tests)

  • CREDIT MINT PASS - LP token minting
  • ERR_ZERO_AMOUNT (600) - Zero amount
  • ERR_NOT_AUTHORIZED (603) - Unauthorized caller

credit-burn.test.ts (3 tests)

  • CREDIT BURN PASS - LP token burning
  • ERR_ZERO_AMOUNT (600) - Zero amount
  • ERR_NOT_AUTHORIZED (603) - Unauthorized caller

transfer.test.ts (2 tests)

  • CREDIT TRANSFER PASS - LP token transfer
  • STREET TRANSFER PASS - STREET token transfer

set-token-uri.test.ts (4 tests)

  • CREDIT SET TOKEN URI PASS - URI modification for credit
  • STREET SET TOKEN URI PASS - URI modification for street
  • ERR_NOT_CONTRACT_OWNER - CREDIT (601) - Unauthorized credit URI
  • ERR_NOT_CONTRACT_OWNER - STREET (901) - Unauthorized street URI

Exchange Contract

Contract: exchange.clar - 43 Tests

provide-initial-liquidity.test.ts (5 tests)

  • PROVIDE INITIAL LIQUIDITY PASS - Success case
  • ERR_ZERO_AMOUNT - AMOUNT A (700) - Zero amount A
  • ERR_ZERO_AMOUNT - AMOUNT B (700) - Zero amount B
  • ERR_NOT_CONTRACT_OWNER (701) - Unauthorized sender
  • ERR_ALREADY_INITIALIZED (705) - Double initialization

provide-liquidity.test.ts (3 tests)

  • PROVIDE LIQUIDITY PASS - Success case
  • ERR_ZERO_AMOUNT (700) - Zero amount input
  • ERR_NOT_INITIALIZED (704) - Not initialized

remove-liquidity.test.ts (2 tests)

  • REMOVE LIQUIDITY PASS - Success case
  • ERR_ZERO_AMOUNT (700) - Zero amount LP

burn-liquidity.test.ts (2 tests)

  • BURN LIQUIDITY PASS - LP token burning
  • ERR_ZERO_AMOUNT (700) - Zero amount LP

lock-liquidity.test.ts (3 tests)

  • LOCK LIQUIDITY PASS - Strategic liquidity addition
  • ERR_ZERO_AMOUNT (700) - Zero amount A
  • ERR_NOT_INITIALIZED (704) - Not initialized

swap.test.ts (7 tests)

  • SWAP-A-B PASS - WELSH to STREET swapping
  • SWAP-B-A PASS - STREET to WELSH swapping
  • PROPORTIONAL LOCKED ADJUSTMENT DURING LARGE SWAP - Advanced testing
  • ERR_ZERO_AMOUNT - SWAP-A-B (700) - Zero amount A
  • ERR_INVALID_AMOUNT - SWAP-A-B (711) - Invalid calculation
  • ERR_ZERO_AMOUNT - SWAP-B-A (700) - Zero amount B
  • ERR_INVALID_AMOUNT - SWAP-B-A (711) - Invalid calculation

set-exchange.test.ts (12 tests)

  • SET EXCHANGE FEE PASS - Fee modification
  • SET EXCHANGE REV PASS - Revenue modification
  • SET EXCHANGE TAX PASS - Tax modification
  • ERR_NOT_CONTRACT_OWNER - SET EXCHANGE FEE (701) - Unauthorized fee
  • ERR_INVALID_AMOUNT - SET EXCHANGE FEE HIGH (711) - Fee too high
  • ERR_INVALID_AMOUNT - SET EXCHANGE FEE LOW (711) - Fee too low
  • ERR_NOT_CONTRACT_OWNER - SET EXCHANGE REV (701) - Unauthorized revenue
  • ERR_INVALID_AMOUNT - SET EXCHANGE REV HIGH (711) - Revenue too high
  • ERR_INVALID_AMOUNT - SET EXCHANGE REV LOW (711) - Revenue too low
  • ERR_NOT_CONTRACT_OWNER - SET EXCHANGE TAX (701) - Unauthorized tax
  • ERR_INVALID_AMOUNT - SET EXCHANGE TAX HIGH (711) - Tax too high
  • ERR_INVALID_AMOUNT - SET EXCHANGE TAX LOW (711) - Tax too low

set-treasury.test.ts (6 tests)

  • SET TREASURY ADDRESS PASS - Address modification
  • SET TREASURY LOCKED PASS - Lock status modification
  • ERR_NOT_TREASURY - SET TREASURY ADDRESS (706) - Unauthorized address
  • ERR_LOCKED_TREASURY - SET TREASURY ADDRESS (707) - Locked treasury
  • ERR_NOT_TREASURY - SET TREASURY LOCKED (706) - Unauthorized lock
  • ERR_LOCKED_TREASURY - SET TREASURY LOCKED (707) - Already locked

liquidity-scenarios.test.ts (1 test)

  • PROVIDE INITIAL LIQUIDITY, REMOVAL ALL LIQUIDITY, PROVIDE LIQUIDITY - Scenario testing

exchange-read-only.test.ts (2 tests)

  • GET BLOCKS PASS - Block heights
  • GET EXCHANGE INFO - Exchange state

Genesis Contract

Contract: genesis.clar - 22 Tests

genesis-contribute.test.ts (3 tests)

  • GENESIS CONTRIBUTE PASS - WELSH contribution
  • ERR_NOT_ACTIVE_FUND (502) - Inactive contribution phase
  • ERR_ZERO_AMOUNT (500) - Zero amount

genesis-claim.test.ts (3 tests)

  • GENESIS CLAIM PASS - Complete LGE claim flow
  • ERR_NOT_ACTIVE_FUND (502) - Inactive claim phase
  • ERR_ZERO_AMOUNT (500) - Zero balance

genesis-withdrawal.test.ts (3 tests)

  • GENESIS WITHDRAWAL PASS - Owner withdrawal
  • ERR_ZERO_AMOUNT (500) - Zero balance
  • ERR_NOT_CONTRACT_OWNER (501) - Non-owner

set-genesis.test.ts (4 tests)

  • SET CLAIM ACTIVE PASS - Phase toggle
  • ERR_NOT_CONTRACT_OWNER (501) - Unauthorized claim toggle
  • SET CONTRIBUTE ACTIVE PASS - Phase toggle
  • ERR_NOT_CONTRACT_OWNER (501) - Unauthorized contribute toggle

genesis-read-only.test.ts (5 tests)

  • GET BLOCKS PASS - Block heights
  • GET CLAIM ACTIVE - Claim phase status
  • GET CONTRIBUTE ACTIVE - Contribution phase status
  • GET TOTAL CONTRIBUTION - Total WELSH contributed
  • GET USER BALANCE - User balance and claims

setup-genesis.test.ts (4 tests)

  • SETUP GENESIS PASS - Genesis state setup
  • GENESIS TRANSFORMER PASS - Token transfer utility
  • ERR_NOT_AUTHORIZED - GENESIS TRANSFORMER - Unauthorized transfer
  • GENESIS SET CONTRACT OWNER - Ownership transfer

Rewards Contract

Contract: rewards.clar - 20 Tests

claim-rewards.test.ts (1 test)

  • CLAIM REWARDS PASS - Complete reward claiming

donate-rewards.test.ts (1 test)

  • DONATE REWARDS PASS - Reward donation

cleanup-rewards.test.ts (1 test)

  • CLEANUP REWARDS PASS - Reward cleanup

update-emission-rewards.test.ts (3 tests)

  • UPDATE EMISSION REWARDS PASS - Emission processing
  • ERR_NOT_CONTRACT_OWNER (801) - Unauthorized sender
  • ERR_EMISSION_INTERVAL (802) - Duplicate emission

update-rewards-a.test.ts (3 tests)

  • UPDATE REWARDS A PASS - Success through integration
  • ERR_NOT_AUTHORIZED (803) - Unauthorized caller
  • ERR_ZERO_AMOUNT (800) - Zero amount

update-rewards-b.test.ts (3 tests)

  • UPDATE REWARDS B PASS - Success through integration
  • ERR_NOT_AUTHORIZED (803) - Unauthorized caller
  • ERR_ZERO_AMOUNT (800) - Zero amount

update-user-rewards.test.ts (2 tests)

  • UPDATE USER REWARDS PASS - Success through integration
  • ERR_NOT_AUTHORIZED (803) - Unauthorized caller

transformer.test.ts (2 tests)

  • TRANSFORMER PASS - Internal token transfer
  • TRANSFORMER ERR_NOT_AUTHORIZED - Authorization validation

rewards-read-only.test.ts (2 tests)

  • GET REWARD POOL INFO - Reward pool state
  • GET REWARD USER INFO - User reward info

get-cleanup-rewards.test.ts (2 tests)

  • GET CLEANUP REWARDS PASS - Cleanup calculation
  • GET CLEANUP REWARDS AFTER CLEANUP - Post-cleanup state

Street Token

Contract: street.clar - 9 Tests

street-mint.test.ts (4 tests)

  • STREET MINT WITH AUTHORIZED SENDER - Success case
  • ERR_NOT_CONTRACT_OWNER (901) - Unauthorized sender
  • ERR_ZERO_AMOUNT (900) - Zero amount input
  • ERR_EXCEEDS_MINT_CAP (907) - Exceeds mint cap

emission-mint.test.ts (3 tests)

  • EMISSION MINT ONCE PASS - Single emission success
  • EMISSION MINT TWICE PASS - Multiple emissions
  • ERR_NOT_CONTRACT_OWNER (901) - Unauthorized sender
  • ERR_EMISSION_INTERVAL (905) - Same block emission
  • ERR_NO_LIQUIDITY (908) - No LP tokens

mine-burn-block.test.ts (2 tests)

  • MINE BURN BLOCK PASS - Block mining success
  • MINE BURN BLOCK FAIL - Block mining failure

street-read-only.test.ts (2 tests)

  • GET CURRENT EPOCH - Current emission epoch reading
  • GET LAST MINT BLOCK - Last mint block reading

Shared Functions - 18 Tests

set-contract-owner.test.ts (7 tests)

  • SET CREDIT CONTRACT OWNER - Credit ownership change
  • SET EXCHANGE CONTRACT OWNER - Exchange ownership change
  • SET REWARDS CONTRACT OWNER - Rewards ownership change
  • SET STREET CONTRACT OWNER - Street ownership change
  • UNAUTHORIZED CREDIT CONTRACT OWNER CHANGE - Unauthorized change
  • UNAUTHORIZED MULTI-CONTRACT OWNER CHANGES - Cross-contract validation
  • ERR_INVALID_PRINCIPAL (706) - Same principal error

shared-read-only.test.ts (9 tests)

  • GET BALANCE PRINCIPAL - Token balance reading
  • GET BLOCKS PASS - Block heights
  • GET EXCHANGE INFO - Exchange state
  • GET TOTAL SUPPLY - Token supply
  • GET CONTRACT OWNER - Contract owner
  • GET DECIMALS - Token decimals
  • GET NAME - Token name
  • GET SYMBOL - Token symbol
  • GET TOKEN URI - Token URI

setup.test.ts (2 tests)

  • SETUP EXCHANGE LIQUIDITY PASS - Multi-user exchange state
  • SETUP REWARDS PASS - Complete rewards system

Running the Tests

  1. Fork repository: welsh-street-contractsĀ 
terminal
git clone https://github.com/welshstreet/tests.git
  1. Install Dependencies
terminal
cd tests && npm install
  1. Run Tests
terminal
npm run test
Last updated on