Skip to content

Add tests for init idempotency, schema-version stamping, and the double-init guard #102

Description

@mikewheeleer

Test the init lifecycle and CURRENT_SCHEMA stamping

Description

init in contracts/escrow/src/lib.rs stores the admin, stamps DataKey::SchemaVersion with CURRENT_SCHEMA (2), requires admin.require_auth(), and panics AlreadyInitialized (#1) on a second call. contracts/escrow/src/test.rs does not assert that init stamps the current schema version, that a second init (even with the same admin) is rejected, or that get_admin reflects the stored admin. This issue locks the initialization lifecycle down.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-contracts only.
  • Cover: after init(admin), get_admin returns Some(admin) and get_schema_version returns CURRENT_SCHEMA (2) — proving a fresh v2 deploy is not mistaken for pre-migration v1.
  • Cover: a second init (same or different admin) panics #1; the double-init guard cannot be bypassed.
  • Cover: an admin-gated entrypoint before init panics NotInitialized (#3).
  • Cover the documented interaction: migrate_v1_to_v2 on a freshly init-ed contract panics MigrationVersionMismatch (#11); use #[should_panic(expected = "...")] matching the existing conventions; test-only change unless a genuine bug surfaces.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/contracts-init-lifecycle-tests
  • Implement changes
    • Write code in: contracts/escrow/src/lib.rs — no changes expected; only touch if a bug is found.
    • Write comprehensive tests in: contracts/escrow/src/test.rs — the init, schema-stamp, double-init, and migrate-rejection scenarios above.
    • Add documentation: note the covered lifecycle in the test module header comment.
    • Include NatSpec-style doc comments (///) on any test helpers.
    • Validate security: the contract cannot be re-initialized to seize admin.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases: double init same admin, double init different admin, pre-init admin call, migrate on fresh deploy.
  • Include the full cargo test output and a short security notes section in the PR description.

Example commit message

test: cover init idempotency and CURRENT_SCHEMA stamping

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions