Skip to content

feat(smart-contracts): comprehensive unit and integration test covera… - #607

Open
CHKM001 wants to merge 2 commits into
Epta-Node:mainfrom
CHKM001:feat/issue-489-comprehensive-contract-test-coverage
Open

CHKM001 wants to merge 2 commits into
Epta-Node:mainfrom
CHKM001:feat/issue-489-comprehensive-contract-test-coverage

Conversation

@CHKM001

@CHKM001 CHKM001 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

PR #489 feat(smart-contracts): Comprehensive Unit and Integration Test Coverage

Branch: feat/issue-489-comprehensive-contract-test-coverage → main


Summary

This PR adds comprehensive snapshot-backed unit tests and an integration test harness across all Stellar smart contracts in the smart-contracts/ workspace. Prior to this change, only agent_registry and agent_governance had meaningful test coverage. All other contracts had minimal or no tests, blocking mainnet deployment confidence.


What Changed

New Test Files

Contract File Tests Added
agent_bidding src/tests.rs 17 unit tests
agent_marketplace src/test.rs 16 unit tests
dispute_resolution src/test.rs 16 unit tests
error-registry src/lib.rs (inline) 20 unit tests
error-resolver src/agent_errors.rs (inline) 14 unit tests
upgrade-manager src/lib.rs (inline) 9 unit tests
task_store src/lib.rs + src/types.rs Lifecycle & auth tests
Integration tests/integration/src/lib.rs Cross-contract wiring tests

Test Coverage by Contract

agent_bidding

  • Initialization (idempotency, admin/version set)
  • Auction creation: success, duplicate ID rejection, pause guard, invalid bond/price
  • Bid submission: success, errors (wrong phase, wrong caller)
  • Reveal phase: success, errors, winner selection with tie-break and reputation weighting
  • Refund: recovery from stalled auctions, idempotency guard, timing constraints
  • Admin: pause/unpause authorization, version upgrade

agent_marketplace

  • Initialization idempotency and admin assignment
  • Service listing: success, duplicate rejection, invalid price validation
  • Search: filter by max price, filter by max response time, works-when-paused
  • Booking: sufficient-payment success, insufficient-payment rejection
  • Booking completion: escrow release, error cases (wrong caller, wrong state)
  • Booking cancellation: client refund, error cases
  • Rating: score update, invalid score rejection, error cases
  • Pause: blocks listing and booking completion

dispute_resolution

  • Initialization and idempotency
  • file_dispute: success, duplicate rejection, no-jurors rejection
  • set_jurors: success and authorization guard
  • cast_vote: success, non-juror rejection, duplicate-vote rejection
  • submit_evidence: success, error cases (wrong state, wrong caller)
  • resolve_dispute: after-voting (client wins), agent-wins path
  • appeal_dispute: success within window, rejection after window, error cases
  • Pause: blocks filing and juror assignment; reads still work when paused

error-registry

  • TTL validation: zero, overflow, above-max, at-max-accepted
  • Submit: success with expires_at stored, duplicate rejection
  • Cleanup: batch cap enforced, active records skipped, mixed batch, code-index maintained, boundary timestamp semantics, noop on empty, works-when-paused
  • get_error / get_errors_by_code: hides expired records, skips expired
  • Pause: blocks submit; reads unaffected

error-resolver

  • Initialization idempotency and admin/signer set
  • Error counting: record and query, unknown agent returns zero, clear resets to zero
  • Allowlist: admin can add/remove directly, non-admin rejected
  • Multisig: signer add/remove, approve, execute with quorum, cannot approve twice, non-signer blocked
  • Timelock: execute fails before timelock expires
  • Quorum: set_quorum works
  • Audit log: operations recorded

upgrade-manager

  • Initialization and idempotency
  • Admin and authorization assignment
  • Propose and execute upgrade (semver increment enforced)
  • Downgrade rejection
  • Rollback within window and after deadline
  • Pause blocks operations
  • Execution of unvalidated proposal fails
  • Gas estimation

Integration (tests/integration)

  • Cross-contract wiring tests using soroban_sdk::testutils
  • upgrade-manager linked as rlib (no WASM exports) to avoid Windows/MinGW linker ordinal overflow

Bug Fixes Made During Test Authoring

File Fix
dispute_resolution/src/test.rs Removed invalid lifetime from Vec<Address>; fixed Error variant names to match lib.rs
error-registry/src/lib.rs Removed duplicate require_admin definition; fixed mismatched closing braces
error-resolver/src/agent_errors.rs Removed redundant require_not_paused checks on read paths; fixed orphaned brace
upgrade-manager/src/lib.rs Scoped mod tests to #[cfg(all(test, feature = "contract"))] to prevent double-export
tests/integration/Cargo.toml Changed upgrade-manager dep to default-features = false to avoid linker ordinal overflow on Windows

Test Execution

# All contracts — unit tests
cd smart-contracts

cargo test -p agent_bidding
cargo test -p agent_marketplace
cargo test -p dispute_resolution
cargo test -p error-registry
cargo test -p error-resolver --no-default-features --features std
cargo test -p upgrade-manager --features contract
cargo test -p task_store
cargo test -p agent_governance

# Integration
cargo test -p integration

All tests pass on the current workspace. Snapshots are committed alongside the test source.


Notes for Reviewers

  • Windows linker constraint: Building upgrade-manager with the contract feature in the integration harness triggers an "export ordinal too large" error under MinGW/MSVC. The integration Cargo.toml now depends on it as default-features = false (pure rlib) which resolves this. This does not affect the WASM build pipeline.
  • Snapshot files: All test_snapshots/**/*.json files are auto-generated by soroban_sdk's snapshot harness on first run. They are committed to lock expected ledger state and will fail CI if contract logic drifts.
  • error-resolver test feature flag: Run with --no-default-features --features std to avoid the WASM ABI conflicting with the test runtime linker.

Checklist

  • All new tests pass locally
  • Snapshot JSON files committed
  • No hardcoded credentials or private keys
  • Existing tests unbroken (agent_registry, agent_governance snapshots updated to reflect voting power weighting changes)
  • Conventional commit message used
  • Resolves #489 referenced

Closes #489

@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@CHKM001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

@CHKM001 is attempting to deploy a commit to the Jaja's projects Team on Vercel.

A member of the Team first needs to authorize it.

@devJaja

devJaja commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

@CHKM001

Kindly resolve the conflicts

Squashed single commit for the issue-489 branch, rebuilt on top of the
current upstream/main (1a8cb1e). Contains the branch's full contribution
plus a clean resolution of the merge against upstream:

- Comprehensive Soroban contract tests (task_store, dispute_resolution,
  upgrade-manager, oracle_manager, agent_bidding, agent_marketplace) plus
  the supporting backend/frontend changes for issue Epta-Node#489.
- agent_bidding: union of both sides — keep require_not_paused and upstream's
  payment-token helpers; DataKey gains PaymentAsset/AssetDecimals; Error enum
  keeps upstream's Asset* variants and adds MaxBiddersReached/InvalidAuditRange
  (referenced by upstream's lib.rs but undefined there) at codes 37/38.
- dispute_resolution: take upstream's appeal_dispute signature/docs; earlier
  dedupe of VoteCastEvent and estimate_gas wrapper retained.
- upgrade-manager: take upstream's is_version_newer refactor and its full
  module set; rename the inline test module to `contract_tests` to avoid the
  duplicate `mod tests` upstream ships; re-add the issue-489 coverage tests.

Known pre-existing breakage on upstream/main (out of scope, not introduced
here): upstream's upgrade-manager ships a half-committed multisig/timelock
governance feature whose helper fns and UpgradeError variants are undefined,
so the crate (and agent_registry, which depends on it) does not compile on
main. This branch merges upstream faithfully and does not make it worse.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@CHKM001
CHKM001 force-pushed the feat/issue-489-comprehensive-contract-test-coverage branch from 4035f9d to 04127ab Compare September 30, 2026 19:40
@CHKM001

CHKM001 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

DONE!

…flicts

# Conflicts:
#	smart-contracts/contracts/error-resolver/test_snapshots/agent_errors/test/clear_resets_count_to_zero.1.json
#	smart-contracts/contracts/error-resolver/test_snapshots/agent_errors/test/error_count_for_unknown_agent_is_zero.1.json
#	smart-contracts/contracts/error-resolver/test_snapshots/agent_errors/test/initialize_cannot_run_twice.1.json
#	smart-contracts/contracts/error-resolver/test_snapshots/agent_errors/test/non_admin_cannot_manage_allowlist.1.json
#	smart-contracts/contracts/error-resolver/test_snapshots/agent_errors/test/record_and_query_error_count.1.json
#	smart-contracts/contracts/error-resolver/test_snapshots/agent_errors/test/unauthorized_caller_cannot_record.1.json

This branch has not been deployed

No deployments
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.

Add comprehensive unit and integration test coverage for all contracts

2 participants