This document describes the comprehensive upgrade path test for CarbonLedger smart contracts, testing the migration from v1 to v2 contracts on Stellar Testnet.
The upgrade path test verifies:
- ✅ v1 contract deployment and functionality
- ✅ State preservation during upgrade
- ✅ v2 contract deployment and new features
- ✅ Retired credits remain retired after upgrade
- ✅ Access control (non-admin upgrade attempts fail)
- Install Rust and Soroban CLI:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
cargo install --locked soroban-cli
cargo install stellar-cli-
Stellar Testnet Account: Fund your testnet account at https://friendbot.stellar.org/
-
Environment Variables (optional, defaults provided in script):
export ADMIN_SECRET_KEY="your_admin_secret_key"
export ORACLE_SECRET_KEY="your_oracle_secret_key"
export VERIFIER_SECRET_KEY="your_verifier_secret_key"- Basic project registration and verification
- Credit issuance and retirement
- Project lifecycle management
- Admin/verifier/oracle access control
- All v1 functionality (backward compatible)
- New Features:
certify_project()- Add credit scores and certificationget_version()- Query contract versionget_upgrade_history()- Track upgrade history- New
Certifiedproject status - Enhanced project data structure with certification fields
- Security: Upgrade restricted to admin only
Location: tests/upgrade_path_test.rs
Tests included:
test_upgrade_path_v1_to_v2()- Complete upgrade flowtest_state_preservation_after_upgrade()- Data integritytest_retired_credits_remain_retired()- Retirement persistencetest_upgrade_by_non_admin_fails()- Access controltest_new_v2_functions()- New functionality verification
Location: scripts/test_upgrade_path.sh
Automated test that:
- Builds both contract versions
- Deploys v1 to testnet
- Creates test data (projects, credits, retirements)
- Deploys v2 to testnet
- Migrates state
- Verifies all acceptance criteria
cd contracts
cargo test --package carbon_registry_v1 --package carbon_registry_v2 --package carbon_registry_v2 --test upgrade_path_test# Make script executable
chmod +x scripts/test_upgrade_path.sh
# Run the complete test
./scripts/test_upgrade_path.shThe integration script deploys both contracts to Stellar Testnet and executes all test scenarios on the live network.
- Project data structure is backward compatible
- All v1 fields preserved in v2
- Migration process maintains data integrity
- Retirement amounts are preserved during upgrade
- Additional retirement attempts respect existing retirement amounts
- Over-retirement protection maintained
upgrade_from_v1()function requires admin authentication- Non-admin attempts return
UnauthorizedUpgradeerror - Access control enforced at contract level
The test uses the following sample project:
- Project ID:
proj-upgrade-test-001 - Name: "Upgrade Test Forest Project"
- Methodology: VCS
- Country: Brazil
- Type: Forestry
- Vintage Year: 2023
- Credits Issued: 1000
- Credits Retired: 300
- Credit Score (v2): 85
Successful test execution should show:
🚀 Starting CarbonLedger Upgrade Path Test
==========================================
✅ v1 contract built successfully
✅ v2 contract built successfully
✅ v1 contract deployed: [CONTRACT_ID]
✅ v1 contract initialized
✅ Project registered in v1
✅ Project verified in v1
✅ Credits issued in v1
✅ Credits retired in v1
✅ v2 contract deployed: [CONTRACT_ID]
✅ v2 contract initialized
✅ Project migrated to v2
✅ New v2 function certify_project works
✅ Non-admin upgrade correctly rejected
✅ Over-retirement correctly rejected
🎉 Upgrade Path Test Completed Successfully!
==========================================
For manual verification, follow these steps:
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/carbon_registry_v1.wasm \
--source $ADMIN_SECRET_KEY \
--network testnetsoroban contract invoke \
--id $V1_CONTRACT_ID \
--source $ADMIN_SECRET_KEY \
--network testnet \
-- initialize \
--admin $ADMIN_ADDRESS \
--oracle $ORACLE_ADDRESS \
--verifiers "[\"$VERIFIER_ADDRESS\"]"Register project, verify, issue credits, retire credits using v1 contract.
soroban contract deploy \
--wasm target/wasm32-unknown-unknown/release/carbon_registry_v2.wasm \
--source $ADMIN_SECRET_KEY \
--network testnetInitialize v2 with same accounts and re-register/migrate project data.
- Check state preservation
- Test new v2 functions
- Verify retirement persistence
- Test access controls
- "cargo not found" - Install Rust: https://rustup.rs/
- "soroban not found" - Install Soroban CLI:
cargo install soroban-cli - "Insufficient funds" - Fund testnet account: https://friendbot.stellar.org/
- "Contract not found" - Verify contract deployment succeeded
- "Auth required" - Check secret keys and account addresses
# Check contract code
soroban contract read \
--id $CONTRACT_ID \
--network testnet
# Check account balance
stellar account balance $ACCOUNT_ADDRESS --network testnet
# Check transaction status
stellar transaction status $TRANSACTION_HASH --network testnet- Admin Keys: Keep admin secret keys secure
- Testnet Only: Never run upgrade tests on mainnet without thorough audit
- State Migration: Ensure complete state backup before production upgrades
- Access Control: Verify all admin-only functions are properly protected
After successful test completion:
- Review test results and logs
- Verify all acceptance criteria met
- Document any edge cases or issues
- Prepare for mainnet upgrade procedure
- Schedule production upgrade window
contracts/carbon_registry_v1/- v1 contract implementationcontracts/carbon_registry_v2/- v2 contract implementationtests/upgrade_path_test.rs- Unit test suitescripts/test_upgrade_path.sh- Integration test scriptUPGRADE_TEST_README.md- This documentation