Skip to content

[Tests] Unit & Integration Tests for OpenZeppelin-Based NFT-Fungible Batch Distribution Contract #115

@aguilar1x

Description

@aguilar1x

🎯 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

  • ✅ Verify all relevant events are emitted:

    • ContractInitialized
    • NFTMinted
    • NFTBatchMinted
    • Transfer
    • RoleGranted, RoleRevoked
  • ✅ Event payloads contain expected values


🧰 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


Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions