Skip to content

Conversation

@aguilar1x
Copy link

Overview

This PR implements a comprehensive mock token contract to support testing of crowdfunding campaigns and payment distributions in the Nevo platform. The mock token follows Soroban standards and provides all essential token functionality needed for development and testing.

Changes

Core Contract Implementation

New Files:

  • contract/contract/src/mock_token.rs - Main mock token contract implementation
  • contract/contract/test/mock_token_test.rs - Comprehensive test suite (16 test cases)

Modified Files:

  • contract/contract/src/base/errors.rs - Added token-specific errors
  • contract/contract/src/base/events.rs - Added token operation events
  • contract/contract/src/base/types.rs - Extended StorageKey enum for token data
  • contract/contract/src/lib.rs - Added mock_token module declaration
  • contract/contract/test/mod.rs - Included mock_token_test module

Token Features Implemented

  1. Token Initialization

    • Set token name, symbol, and decimals
    • Admin assignment and authorization
    • Single initialization enforcement
  2. Token Minting

    • Admin-only token creation
    • Amount validation (positive values only)
    • Total supply tracking
    • Balance updates for recipients
    • Mint event emission
  3. Token Transfers

    • Address-to-address token movement
    • Balance validation (insufficient funds check)
    • Authorization verification (sender approval required)
    • Transfer event emission
  4. Token Queries

    • Balance checking by address
    • Total supply retrieval
    • Token metadata access (name, symbol, decimals)

Error Handling

Added three new error types to handle token operations:

  • InsufficientBalance - Transfer attempts with inadequate funds
  • InvalidAmount - Negative or zero amount operations
  • UnauthorizedMinting - Mint attempts by non-admin addresses

Events

Implemented two token event types:

  • token_minted - Emitted on successful token minting
  • token_transferred - Emitted on successful token transfers

Testing Coverage

Comprehensive test suite covering:

  • Token initialization and metadata
  • Minting operations and authorization
  • Transfer operations and validation
  • Balance and supply tracking
  • Edge cases (zero amounts, insufficient balance, unauthorized operations)
  • Error condition handling

Technical Details

Storage Design

The contract uses Soroban's instance storage for:

  • Token metadata (name, symbol, decimals, admin)
  • Total supply tracking
  • Individual address balances

Security Features

  • Admin authorization for minting operations
  • Amount validation for all token operations
  • Balance verification before transfers
  • Single initialization pattern

Compliance

The mock token follows Soroban contract patterns and integrates seamlessly with the existing Nevo crowdfunding infrastructure.

Testing Results

All tests pass successfully:

  • 45 total tests (29 existing crowdfunding + 16 new mock token)
  • 100% test coverage for implemented functionality
  • No regressions in existing functionality

Usage

The mock token contract can be used for:

  • Testing crowdfunding campaign contributions
  • Payment distribution simulations
  • Token balance management in development
  • Integration testing with Nevo platform features

Acceptance Criteria Met

  • Mock token contract created in src/mock_token.rs
  • All standard token functions implemented (initialize, mint, transfer, balance, total_supply)
  • Token initialization with name, symbol, and decimals
  • Token minting to addresses with proper authorization
  • Token transfers between addresses with validation
  • Balance tracking and total supply updates
  • Comprehensive test suite with edge cases
  • Contract compiles without errors
  • All tests pass successfully

Future Considerations

This mock token provides a foundation for more advanced token features that may be needed as the Nevo platform evolves, such as:

  • Token approvals and allowances
  • Batch operations
  • Token burning functionality
  • Integration with external token standards

- Add InsufficientBalance, InvalidAmount, and UnauthorizedMinting errors
- Extend StorageKey enum with token-related keys (TokenName, TokenSymbol, TokenDecimals, TotalSupply)
- Add token_minted event for token minting operations
- Add token_transferred event for token transfer operations
- Create MockTokenContract implementing Soroban token standards
- Include initialize, mint, transfer, balance, total_supply functions
- Add proper authorization, validation, and error handling
- Emit events for token operations
- Create mock_token_test.rs with 16 test cases
- Test token initialization, minting, transfers, and balances
- Include edge cases and error conditions
- Verify total supply tracking and authorization
- Add mock_token module to lib.rs
- Include mock_token_test in test module declarations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a mock token contract to be used for testing crowdfunding campaigns and payment distributions

1 participant