The testnet mode feature provides a configuration flag that enables simplified behavior for testnet and development deployments. When enabled, certain strict validations are relaxed to facilitate testing and experimentation without compromising production safety.
Testnet mode is designed for:
- Non-production deployments (testnet, devnet, local development)
- Testing edge cases and boundary conditions
- Rapid prototyping and experimentation
- Integration testing with flexible parameters
When testnet mode is enabled, the following behaviors are modified:
Normal Mode:
revenue_share_bpsmust be ≤ 10,000 (100%)- Values > 10,000 return
InvalidRevenueShareBpserror
Testnet Mode:
revenue_share_bpsvalidation is skipped- Any value is accepted, including > 10,000
- Useful for testing extreme scenarios
Normal Mode:
- If concentration limit is set with
enforce=true,report_revenuefails when reported concentration exceeds the limit - Returns
ConcentrationLimitExceedederror
Testnet Mode:
- Concentration enforcement is skipped
report_revenuesucceeds regardless of concentration- Concentration warnings are still emitted via events
- Set Admin (one-time operation):
contract.set_admin(&admin_address);- Enable Testnet Mode (admin only):
contract.set_testnet_mode(&true);- Verify Mode:
let is_testnet = contract.is_testnet_mode();- Disable Testnet Mode (when moving to production):
contract.set_testnet_mode(&false);// Enable testnet mode
contract.set_admin(&admin);
contract.set_testnet_mode(&true);
// Register offering with > 100% revenue share (for testing)
contract.register_offering(&issuer, &token, &15_000); // 150%
// This would fail in normal mode but succeeds in testnet mode// Enable testnet mode
contract.set_admin(&admin);
contract.set_testnet_mode(&true);
// Set up concentration limit with enforcement
contract.register_offering(&issuer, &token, &5_000);
contract.set_concentration_limit(&issuer, &token, &5000, &true);
// Report high concentration
contract.report_concentration(&issuer, &token, &8000); // 80% > 50% limit
// Report revenue - succeeds in testnet mode, would fail in normal mode
contract.report_revenue(&issuer, &token, &1_000_000, &1);- Only the contract admin can toggle testnet mode
- Requires
set_admin()to be called first - Admin authorization is enforced via
require_auth()
- Testnet mode is disabled by default
- Must be explicitly enabled by admin
- Can be toggled on/off at any time
- Mode changes emit events for auditability
The following operations work identically in both modes:
- Blacklist management
- Pagination
- Audit summaries
- Claim operations
- Rounding modes
- All read-only queries
Testnet mode changes emit the test_mode event:
Topic: (test_mode, admin_address)
Payload: enabled (bool)
This allows off-chain systems to track when testnet mode is toggled.
The feature includes comprehensive test coverage (95%+):
testnet_mode_disabled_by_default- Verifies default stateset_testnet_mode_requires_admin- Admin authorizationtestnet_mode_can_be_toggled- Enable/disable cyclesset_testnet_mode_emits_event- Event emission
testnet_mode_allows_bps_over_10000- BPS validation skiptestnet_mode_disabled_rejects_bps_over_10000- Normal mode enforcementtestnet_mode_skips_concentration_enforcement- Concentration skiptestnet_mode_disabled_enforces_concentration- Normal mode enforcement
testnet_mode_toggle_after_offerings_exist- Mode change with existing datatestnet_mode_affects_only_validation_not_storage- Storage integritytestnet_mode_multiple_offerings_with_varied_bps- Multiple offerings
testnet_mode_normal_operations_unaffected- Other operations worktestnet_mode_blacklist_operations_unaffected- Blacklist unchangedtestnet_mode_pagination_unaffected- Pagination unchanged
- Enable at deployment: Set admin and enable testnet mode immediately after contract deployment
- Document clearly: Mark testnet contracts in your documentation
- Monitor events: Track
test_modeevents to verify configuration - Test thoroughly: Use testnet mode to test edge cases before production
- Never enable: Keep testnet mode disabled for production contracts
- Verify state: Check
is_testnet_mode()returnsfalsebefore going live - Admin security: Protect admin keys to prevent unauthorized mode changes
- Audit trail: Review event logs to ensure mode was never enabled
- Deploy new contract instance (testnet mode disabled by default)
- Migrate data if needed
- Verify
is_testnet_mode()returnsfalse - Do not reuse testnet contracts for production
Testnet mode state is stored in persistent storage:
DataKey::TestnetMode -> bool- Storage key:
src/lib.rs-DataKey::TestnetMode - Event symbol:
src/lib.rs-EVENT_TESTNET_MODE - Functions:
src/lib.rs-set_testnet_mode(),is_testnet_mode() - Modified flows:
register_offering(),report_revenue() - Tests:
src/test.rs- Testnet mode section
-
Testnet mode does NOT affect:
- Token transfers
- Claim calculations
- Blacklist enforcement
- Freeze functionality
- Any other validation logic
-
Mode changes are immediate (no delay or grace period)
-
Existing offerings retain their parameters when mode is toggled
- v0.1.0 - Initial implementation (Issue #24)
- Admin-only toggle
- BPS validation relaxation
- Concentration enforcement skip
- Comprehensive test coverage
For questions or issues related to testnet mode:
- Check test cases in
src/test.rsfor usage examples - Review event logs for mode change history
- Verify admin configuration with
get_admin()