Skip to content

test(contracts): Add shared test-utils crate with mocks, helpers and TestEnv - #1264

Open
Damilorlar wants to merge 3 commits into
accesslayerorg:mainfrom
Damilorlar:issue/1260-shared-test-utils
Open

Damilorlar wants to merge 3 commits into
accesslayerorg:mainfrom
Damilorlar:issue/1260-shared-test-utils

Conversation

@Damilorlar

Copy link
Copy Markdown

#closed #1260

Previously, each contract test file built its own mock token, oracle and time helpers. This duplicated code and hid subtle differences between tests, so two tests that looked like they exercised the same setup could behave differently.
This PR adds a shared contracts/test-utils crate used by the contract tests, and migrates three existing test modules to it.

What changed
-Created the contracts/test-utils crate exposing MockToken, MockOracle and MockReceiver contracts.
-Added helpers: advance_ledgers(env, n), set_timestamp(env, ts) and fund(env, token, account, amount).
-Added a TestEnv builder that deploys the protocol with the default config in one call and returns typed clients.
-Added event assertion helpers such as assert_event(env, topic, data). On a mismatch they fail with a readable diff showing the expected event next to the events actually emitted.
-Migrated [module A, module B, module C] to the shared crate. Their behavior is unchanged and the tests pass as before.
-Documented every helper with examples in docs/testing.md.
-test-utils is added only under [dev-dependencies], so no production crate depends on it and it never ends up in a deployed contract.

Tests

  • The migrated modules pass unchanged in behavior.
    -[A small test for the helpers themselves, e.g. fund updates balances, advance_ledgers moves the sequence, assert_event fails on a mismatch.]

Checklist
[ ] The crate compiles as a dev-dependency across the workspace (cargo build --workspace)
[ ] cargo test --workspace passes
[ ] TestEnv deploys the protocol with one call
[ ] Docs in docs/testing.md cover each helper
[ ] No production crate lists test-utils as a dependency
[ ] Changelog fragment added, if the repo uses one

@drips-wave

drips-wave Bot commented Nov 23, 2026

Copy link
Copy Markdown

@Damilorlar 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

…dger helpers

- Created test-utils crate exposing MockToken, MockOracle and MockReceiver contracts
- Added helpers: advance_ledgers(env, n), set_timestamp(env, ts) and fund(env, account, amount)
- Added TestEnv builder deploying the protocol with default config and returning typed clients
- Added assertion helpers for events, such as assert_event(env, topic, data)

Closes accesslayerorg#1260

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Chucks1093

Copy link
Copy Markdown
Member

✅ PR Ready for Review

Due to a recent malware incident affecting our repositories, all PRs are required to pass automated security checks before being reviewed for merging.

This PR has passed all automated checks:

  • ✅ Security scan — no malicious code detected
  • ✅ No merge conflicts
  • ✅ CI checks passed

Next step: Please share this PR link in our Telegram group so a maintainer can review and merge it: https://t.me/c/accesslayerorg/8514

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.

Create shared test utilities crate with mock tokens, oracles and ledger helpers

2 participants