The commitment_nft contract (contracts/commitment_nft/src/lib.rs) has a mint function that validates commitment_type via is_valid_commitment_type() (line 185-190). Only "safe", "balanced", and "aggressive" are accepted (case-sensitive exact match). Invalid values return ContractError::InvalidCommitmentType (error code #12).
Existing tests in contracts/commitment_nft/src/tests.rs cover basic minting but do not test invalid commitment_type values.
Add the following test functions to contracts/commitment_nft/src/tests.rs under a new section // Commitment Type Validation Tests:
test_mint_empty_commitment_type— Mint withcommitment_type = ""→ expectsError(Contract, #12)(InvalidCommitmentType)test_mint_invalid_commitment_type— Mint withcommitment_type = "invalid"→ expectsError(Contract, #12)test_mint_wrong_case_commitment_type— Mint withcommitment_type = "Safe"(capital S) → expectsError(Contract, #12)(confirms case-sensitivity)test_mint_safe_commitment_type— Mint withcommitment_type = "safe"→ succeedstest_mint_balanced_commitment_type— Mint withcommitment_type = "balanced"→ succeedstest_mint_aggressive_commitment_type— Mint withcommitment_type = "aggressive"→ succeeds
All tests follow the existing pattern:
- Use
setup_contract()+client.initialize(&admin) - Invalid types use
#[should_panic(expected = "Error(Contract, #12)")] - Valid types assert
token_idandtotal_supplyafter mint
Run cargo test -p commitment_nft to verify all new tests pass.
Commit changes to tests.rs on branch claude/test-nft-mint-commitment-nTayZ and push.
contracts/commitment_nft/src/tests.rs— Add 6 new test functions
The contract already correctly validates commitment_type and returns InvalidCommitmentType (error #12). No contract modifications required.