Added a basic versioning mechanism to the AidEscrow contract to prepare for future upgrades.
- Added
KEY_VERSIONconstant for storing version in instance storage
- Modified
init()to set version 1 on contract initialization
get_version(): Returns the current contract version (defaults to 0 if not set)migrate(env: Env, new_version: u32): Admin-only function to migrate between versions- Requires admin authentication
- Structured with match statement for version-specific migrations
- Currently no-op but ready for future data transformations
Three comprehensive tests added:
test_version_set_on_init: Verifies version is set to 1 on initializationtest_migrate_admin_only: Confirms only admin can call migrate functiontest_migrate_version_progression: Tests version can be incremented through migrations
All tests pass (19 total):
- 5 core flow tests
- 11 integration tests
- 3 versioning tests
✅ Contract compiles successfully for wasm32-unknown-unknown target ✅ All existing functionality preserved ✅ No breaking changes
// Initialize contract with version 1
client.init(&admin);
assert_eq!(client.get_version(), 1);
// Migrate to version 2 (admin only)
client.migrate(&2);
assert_eq!(client.get_version(), 2);When adding version-specific migrations, update the match statement in migrate():
match (current_version, new_version) {
(1, 2) => {
// Add v1 -> v2 migration logic here
// e.g., transform storage structures, add new keys, etc.
}
(2, 3) => {
// Add v2 -> v3 migration logic here
}
_ => {
// No-op for other transitions
}
}