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
| Contract | Functions | Error Codes | Test Files | Coverage |
|---|---|---|---|---|
street.clar | 8/8 | 6/6 | 4 | 100% |
exchange.clar | 16/16 | 7/7 | 12 | 100% |
credit.clar | 6/6 | 2/2 | 4 | 100% |
rewards.clar | 10/10 | 2/2 | 7 | 100% |
genesis.clar | 11/11 | 3/3 | 7 | 100% |
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 mintingERR_ZERO_AMOUNT (600)- Zero amountERR_NOT_AUTHORIZED (603)- Unauthorized caller
credit-burn.test.ts (3 tests)
CREDIT BURN PASS- LP token burningERR_ZERO_AMOUNT (600)- Zero amountERR_NOT_AUTHORIZED (603)- Unauthorized caller
transfer.test.ts (2 tests)
CREDIT TRANSFER PASS- LP token transferSTREET TRANSFER PASS- STREET token transfer
set-token-uri.test.ts (4 tests)
CREDIT SET TOKEN URI PASS- URI modification for creditSTREET SET TOKEN URI PASS- URI modification for streetERR_NOT_CONTRACT_OWNER - CREDIT (601)- Unauthorized credit URIERR_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 caseERR_ZERO_AMOUNT - AMOUNT A (700)- Zero amount AERR_ZERO_AMOUNT - AMOUNT B (700)- Zero amount BERR_NOT_CONTRACT_OWNER (701)- Unauthorized senderERR_ALREADY_INITIALIZED (705)- Double initialization
provide-liquidity.test.ts (3 tests)
PROVIDE LIQUIDITY PASS- Success caseERR_ZERO_AMOUNT (700)- Zero amount inputERR_NOT_INITIALIZED (704)- Not initialized
remove-liquidity.test.ts (2 tests)
REMOVE LIQUIDITY PASS- Success caseERR_ZERO_AMOUNT (700)- Zero amount LP
burn-liquidity.test.ts (2 tests)
BURN LIQUIDITY PASS- LP token burningERR_ZERO_AMOUNT (700)- Zero amount LP
lock-liquidity.test.ts (3 tests)
LOCK LIQUIDITY PASS- Strategic liquidity additionERR_ZERO_AMOUNT (700)- Zero amount AERR_NOT_INITIALIZED (704)- Not initialized
swap.test.ts (7 tests)
SWAP-A-B PASS- WELSH to STREET swappingSWAP-B-A PASS- STREET to WELSH swappingPROPORTIONAL LOCKED ADJUSTMENT DURING LARGE SWAP- Advanced testingERR_ZERO_AMOUNT - SWAP-A-B (700)- Zero amount AERR_INVALID_AMOUNT - SWAP-A-B (711)- Invalid calculationERR_ZERO_AMOUNT - SWAP-B-A (700)- Zero amount BERR_INVALID_AMOUNT - SWAP-B-A (711)- Invalid calculation
set-exchange.test.ts (12 tests)
SET EXCHANGE FEE PASS- Fee modificationSET EXCHANGE REV PASS- Revenue modificationSET EXCHANGE TAX PASS- Tax modificationERR_NOT_CONTRACT_OWNER - SET EXCHANGE FEE (701)- Unauthorized feeERR_INVALID_AMOUNT - SET EXCHANGE FEE HIGH (711)- Fee too highERR_INVALID_AMOUNT - SET EXCHANGE FEE LOW (711)- Fee too lowERR_NOT_CONTRACT_OWNER - SET EXCHANGE REV (701)- Unauthorized revenueERR_INVALID_AMOUNT - SET EXCHANGE REV HIGH (711)- Revenue too highERR_INVALID_AMOUNT - SET EXCHANGE REV LOW (711)- Revenue too lowERR_NOT_CONTRACT_OWNER - SET EXCHANGE TAX (701)- Unauthorized taxERR_INVALID_AMOUNT - SET EXCHANGE TAX HIGH (711)- Tax too highERR_INVALID_AMOUNT - SET EXCHANGE TAX LOW (711)- Tax too low
set-treasury.test.ts (6 tests)
SET TREASURY ADDRESS PASS- Address modificationSET TREASURY LOCKED PASS- Lock status modificationERR_NOT_TREASURY - SET TREASURY ADDRESS (706)- Unauthorized addressERR_LOCKED_TREASURY - SET TREASURY ADDRESS (707)- Locked treasuryERR_NOT_TREASURY - SET TREASURY LOCKED (706)- Unauthorized lockERR_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 heightsGET EXCHANGE INFO- Exchange state
Genesis Contract
Contract: genesis.clar - 22 Tests
genesis-contribute.test.ts (3 tests)
GENESIS CONTRIBUTE PASS- WELSH contributionERR_NOT_ACTIVE_FUND (502)- Inactive contribution phaseERR_ZERO_AMOUNT (500)- Zero amount
genesis-claim.test.ts (3 tests)
GENESIS CLAIM PASS- Complete LGE claim flowERR_NOT_ACTIVE_FUND (502)- Inactive claim phaseERR_ZERO_AMOUNT (500)- Zero balance
genesis-withdrawal.test.ts (3 tests)
GENESIS WITHDRAWAL PASS- Owner withdrawalERR_ZERO_AMOUNT (500)- Zero balanceERR_NOT_CONTRACT_OWNER (501)- Non-owner
set-genesis.test.ts (4 tests)
SET CLAIM ACTIVE PASS- Phase toggleERR_NOT_CONTRACT_OWNER (501)- Unauthorized claim toggleSET CONTRIBUTE ACTIVE PASS- Phase toggleERR_NOT_CONTRACT_OWNER (501)- Unauthorized contribute toggle
genesis-read-only.test.ts (5 tests)
GET BLOCKS PASS- Block heightsGET CLAIM ACTIVE- Claim phase statusGET CONTRIBUTE ACTIVE- Contribution phase statusGET TOTAL CONTRIBUTION- Total WELSH contributedGET USER BALANCE- User balance and claims
setup-genesis.test.ts (4 tests)
SETUP GENESIS PASS- Genesis state setupGENESIS TRANSFORMER PASS- Token transfer utilityERR_NOT_AUTHORIZED - GENESIS TRANSFORMER- Unauthorized transferGENESIS 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 processingERR_NOT_CONTRACT_OWNER (801)- Unauthorized senderERR_EMISSION_INTERVAL (802)- Duplicate emission
update-rewards-a.test.ts (3 tests)
UPDATE REWARDS A PASS- Success through integrationERR_NOT_AUTHORIZED (803)- Unauthorized callerERR_ZERO_AMOUNT (800)- Zero amount
update-rewards-b.test.ts (3 tests)
UPDATE REWARDS B PASS- Success through integrationERR_NOT_AUTHORIZED (803)- Unauthorized callerERR_ZERO_AMOUNT (800)- Zero amount
update-user-rewards.test.ts (2 tests)
UPDATE USER REWARDS PASS- Success through integrationERR_NOT_AUTHORIZED (803)- Unauthorized caller
transformer.test.ts (2 tests)
TRANSFORMER PASS- Internal token transferTRANSFORMER ERR_NOT_AUTHORIZED- Authorization validation
rewards-read-only.test.ts (2 tests)
GET REWARD POOL INFO- Reward pool stateGET REWARD USER INFO- User reward info
get-cleanup-rewards.test.ts (2 tests)
GET CLEANUP REWARDS PASS- Cleanup calculationGET 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 caseERR_NOT_CONTRACT_OWNER (901)- Unauthorized senderERR_ZERO_AMOUNT (900)- Zero amount inputERR_EXCEEDS_MINT_CAP (907)- Exceeds mint cap
emission-mint.test.ts (3 tests)
EMISSION MINT ONCE PASS- Single emission successEMISSION MINT TWICE PASS- Multiple emissionsERR_NOT_CONTRACT_OWNER (901)- Unauthorized senderERR_EMISSION_INTERVAL (905)- Same block emissionERR_NO_LIQUIDITY (908)- No LP tokens
mine-burn-block.test.ts (2 tests)
MINE BURN BLOCK PASS- Block mining successMINE BURN BLOCK FAIL- Block mining failure
street-read-only.test.ts (2 tests)
GET CURRENT EPOCH- Current emission epoch readingGET LAST MINT BLOCK- Last mint block reading
Shared Functions - 18 Tests
set-contract-owner.test.ts (7 tests)
SET CREDIT CONTRACT OWNER- Credit ownership changeSET EXCHANGE CONTRACT OWNER- Exchange ownership changeSET REWARDS CONTRACT OWNER- Rewards ownership changeSET STREET CONTRACT OWNER- Street ownership changeUNAUTHORIZED CREDIT CONTRACT OWNER CHANGE- Unauthorized changeUNAUTHORIZED MULTI-CONTRACT OWNER CHANGES- Cross-contract validationERR_INVALID_PRINCIPAL (706)- Same principal error
shared-read-only.test.ts (9 tests)
GET BALANCE PRINCIPAL- Token balance readingGET BLOCKS PASS- Block heightsGET EXCHANGE INFO- Exchange stateGET TOTAL SUPPLY- Token supplyGET CONTRACT OWNER- Contract ownerGET DECIMALS- Token decimalsGET NAME- Token nameGET SYMBOL- Token symbolGET TOKEN URI- Token URI
setup.test.ts (2 tests)
SETUP EXCHANGE LIQUIDITY PASS- Multi-user exchange stateSETUP REWARDS PASS- Complete rewards system
Running the Tests
- Fork repository: welsh-street-contractsĀ
git clone https://github.com/welshstreet/tests.git- Install Dependencies
cd tests && npm install- Run Tests
npm run test