🎯 Objective
Design and implement a comprehensive suite of unit and integration tests to ensure the reliability, correctness, and security of the NFT-Fungible Batch Distribution Contract, built using OpenZeppelin’s Stellar contracts and designed for Starshop.
🧪 Scope
Test the following modules and behaviors:
nft-fungible-batch-contract/src/
mint.rs // Batch minting functionality
transfer.rs // Token transfer logic
roles.rs // Access control behavior
storage.rs // Ownership and token state
events.rs // Event emission validation
lib.rs // Initialization and entry point
✅ Test Categories & Cases
1. Initialization
- ✅ Should allow contract to be initialized only once
- ✅ Should assign
DEFAULT_ADMIN_ROLE correctly
- ✅ Should prevent double initialization (revert)
- ✅ Event
ContractInitialized must be emitted once
2. Role Management
- ✅ Only
ADMIN_ROLE can assign MINTER_ROLE
- ✅ Cannot mint without correct role (should revert)
- ✅ Should emit
RoleGranted and RoleRevoked events
- ✅ Role checking must be accurate for all privileged operations
3. Minting Logic
- ✅ Should allow authorized minters to call
mint_batch(recipient, quantity)
- ✅ Revert if
quantity == 0
- ✅ Revert if caller lacks
MINTER_ROLE
- ✅ Revert if recipient is invalid (optional)
- ✅ Generate correct number of token entries in storage
- ✅ Emit
NFTMinted for each token and one NFTBatchMinted event
4. Token Transfer
- ✅ Owner can transfer token to another valid address
- ✅ Cannot transfer token if caller is not owner
- ✅ Ownership must update correctly after transfer
- ✅ Emit
Transfer(from, to, token_id) for each successful transfer
5. Storage Integrity
- ✅ Token ownership and balances are updated properly
- ✅ No overwrite of previous tokens
- ✅ No token ID reuse
- ✅ Keys are scoped and isolated (no collisions)
6. Events & Logging
🧰 Tooling & Environment
- Use
soroban-sdk test utilities
- Leverage OpenZeppelin's test helpers where available
- Write tests in Rust using
#[test] and testutils
- Use mock addresses for users (
admin, minter, buyer1, buyer2)
📌 Additional Recommendations
- Include negative test cases (unauthorized mint, transfer without ownership, double init)
- Use helper functions to simulate batch minting
- Use assertions to check state changes after every action
- Structure tests into modules by feature (mint, transfer, roles)
🔗 References
🎯 Objective
Design and implement a comprehensive suite of unit and integration tests to ensure the reliability, correctness, and security of the NFT-Fungible Batch Distribution Contract, built using OpenZeppelin’s Stellar contracts and designed for Starshop.
🧪 Scope
Test the following modules and behaviors:
✅ Test Categories & Cases
1. Initialization
DEFAULT_ADMIN_ROLEcorrectlyContractInitializedmust be emitted once2. Role Management
ADMIN_ROLEcan assignMINTER_ROLERoleGrantedandRoleRevokedevents3. Minting Logic
mint_batch(recipient, quantity)quantity == 0MINTER_ROLENFTMintedfor each token and oneNFTBatchMintedevent4. Token Transfer
Transfer(from, to, token_id)for each successful transfer5. Storage Integrity
6. Events & Logging
✅ Verify all relevant events are emitted:
ContractInitializedNFTMintedNFTBatchMintedTransferRoleGranted,RoleRevoked✅ Event payloads contain expected values
🧰 Tooling & Environment
soroban-sdktest utilities#[test]andtestutilsadmin,minter,buyer1,buyer2)📌 Additional Recommendations
🔗 References