Skip to content

feat(contracts): Implement contract state dump and restore helper for local testnet migration (Closes #1372) - #1417

Closed
camesenin wants to merge 1 commit into
FinesseStudioLab:mainfrom
camesenin:feat/contract-state-migration-1372
Closed

camesenin wants to merge 1 commit into
FinesseStudioLab:mainfrom
camesenin:feat/contract-state-migration-1372

Conversation

@camesenin

Copy link
Copy Markdown

Description

Resolves #1372

Implements contract persistent and instance storage dump and restore capabilities for the Trivela campaign contract, enabling offline state inspection, local testnet seeding, and deterministic migration workflows.

Summary of Changes

  • Soroban Smart Contract (contracts/campaign/src/lib.rs):

    • Defined CampaignStateDump struct with #[contracttype] exporting complete configuration parameters and active persistent participants.
    • Implemented dump_state(env: Env) -> CampaignStateDump to export contract state and persistent participant records.
    • Implemented
      estore_state(env: Env, caller: Address, dump: CampaignStateDump) -> Result<(), Error> with strict authentication validation, schedule window invariants, capacity boundaries, and event emission (
      estore).
    • Added seed_participants(env: Env, admin: Address, nonce: u64, participants: Vec) -> Result<u32, Error> for batch seeding persistent participant entries.
    • Updated ABI snapshot in contracts/snapshots/campaign.json.
  • Unit & Integration Test Suite (contracts/campaign/src/test.rs):

    • est_dump_and_restore_state_roundtrip: Verifies state extraction from an active campaign and successful restoration onto a freshly deployed contract.
      
    • est_restore_state_unauthorized: Verifies rejection of unauthorized callers attempting state restoration.
      
    • est_restore_state_validates_window: Verifies strict invariant checking on time and ledger windows.
      
    • est_seed_participants_batch: Verifies batch seeding persistent entries and registry updates.
      
  • Developer Tooling & Migration Helper (scripts/contract-state-migration.mjs & cli/src/commands/contracts.js):

    • Added standalone Node.js migration helper supporting dump,
      estore, seed, and �erify with schema validation and --dry-run simulation.
    • Added rivela contracts dump-state and rivela contracts restore-state subcommands to the Trivela CLI.

Verification

  • Tested locally via cargo test on Soroban SDK with 4/4 new dedicated tests passing cleanly.
  • Verified CLI script execution with dry-run and JSON schema validation.

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.

feat(contracts): Implement contract state dump and restore helper for local testnet migration

2 participants