Closes #687
Implements the configure_arena function that allows arena administrators to update arena parameters (entry fee, max players, join deadline) after initialization but before the game starts. This provides operational flexibility without requiring contract redeployment.
- contracts/arena/src/lib.rs - Main contract with
configure_arenafunction - contracts/arena/src/types.rs - ArenaConfig and GameState types
- contracts/arena/src/storage.rs - Storage management utilities
- contracts/arena/src/errors.rs - Error definitions
- contracts/arena/src/events.rs - Event emission utilities
- contracts/arena/src/test.rs - Comprehensive test suite (20 tests)
- contracts/arena/Cargo.toml - Package configuration
- contracts/Cargo.toml - Workspace configuration
- contracts/arena/.cargo/config.toml - Build configuration
- contracts/arena/README.md - Contract documentation
- contracts/.gitignore - Ignore build artifacts
- IMPLEMENTATION_SUMMARY.md - Detailed implementation notes
- 12 files changed
- 1,195 insertions
- 542 lines of tests
- 20 test cases
pub fn configure_arena(
env: Env,
new_entry_fee: Option<i128>,
new_max_players: Option<u32>,
new_join_deadline: Option<u64>,
) -> Result<(), ArenaError>✅ Admin-only access - Requires admin authentication
✅ State validation - Only works when GameState is Open
✅ Partial updates - Update any combination of parameters
✅ Entry fee validation - Must be positive (> 0)
✅ Deadline validation - Must be in the future
✅ Event emission - Emits arena_configured event
✅ Comprehensive tests - 20 test cases covering all scenarios
configure_arena(env, None, None, Some(original_deadline + 86400))configure_arena(env, Some(50_000_000), None, None)configure_arena(env, None, Some(200), None)configure_arena(env, None, Some(0), None)configure_arena(
env,
Some(75_000_000),
Some(150),
Some(current_time + 172800)
)- ✅ Valid configuration update (all parameters)
- ✅ Partial update - entry fee only
- ✅ Partial update - max players only
- ✅ Partial update - deadline only
- ✅ Authorization failure (non-admin)
- ✅ State validation - InProgress
- ✅ State validation - Finished
- ✅ Invalid entry fee - zero
- ✅ Invalid entry fee - negative
- ✅ Invalid deadline - past
- ✅ Invalid deadline - current time
- ✅ Valid deadline - future
- ✅ Multiple updates
- ✅ Event emission
- ✅ No-op configuration (all None)
- ✅ Configure after players joined
- ✅ Configure then start game
- ✅ Initialize with invalid entry fee
- ✅ Initialize with past deadline
- ✅ Edge case - set max players to zero
| Error | Code | Condition |
|---|---|---|
ConfigNotFound |
1 | Arena not initialized |
InvalidEntryFee |
2 | Entry fee <= 0 |
DeadlineTooSoon |
3 | Deadline <= current time |
ArenaAlreadyStarted |
4 | Game not in Open state |
InvalidStateTransition |
5 | Invalid state change |
ArenaFull |
6 | Max players reached |
DeadlinePassed |
7 | Join deadline passed |
✅ Admin Authentication - Strict enforcement via require_auth()
✅ State Integrity - No updates during active game
✅ Economic Protection - Entry fee validation prevents zero/negative fees
✅ Time Validation - Deadline must be in future
✅ No Breaking Changes - Purely additive functionality
cd contracts/arena
cargo build --target wasm32-unknown-unknown --releasecargo testNote: Tests require proper Rust toolchain setup. On Windows, you may need MinGW/MSYS2 for full build support.
✅ configure_arena updates the specified parameters
✅ Requires admin auth
✅ Rejected if the game has already started (InProgress or Finished state)
✅ Validates new values (fee > 0, deadline in future)
✅ Emits a arena_configured event
✅ Tests cover: valid update, update after start (should fail), invalid values
- ✅ Inline code comments
- ✅ Function-level documentation
- ✅ README with usage examples
- ✅ Error code documentation
- ✅ Test documentation
- ✅ Implementation summary
Ready for deployment to Soroban testnet:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/arena_contract.wasm \
--source <YOUR_SECRET_KEY> \
--rpc-url https://soroban-testnet.stellar.org:443 \
--network-passphrase "Test SDF Network ; September 2015"- Code follows project style guidelines
- Self-review completed
- Code commented, particularly complex areas
- Documentation updated
- No new warnings generated
- Tests added covering new functionality
- All tests pass locally
- No breaking changes
- Security considerations addressed
N/A - Smart contract implementation (no UI changes)
This implementation follows the Soroban smart contract best practices and is based on the detailed specification in docs/CONFIGURE_ARENA_SPEC.md. The contract is ready for integration with the frontend and backend systems.
Please pay special attention to:
- Admin authentication enforcement
- State validation logic
- Parameter validation (entry fee, deadline)
- Test coverage completeness
- Error handling patterns
- Issue #687: Add configure_arena function for admin to update parameters before game starts