Skip to content

test(CPL-322): add Forge tests for AccountConfig diamond contracts#349

Open
GTC6244 wants to merge 1 commit into
nextfrom
feature/cpl-322-tests-for-contracts
Open

test(CPL-322): add Forge tests for AccountConfig diamond contracts#349
GTC6244 wants to merge 1 commit into
nextfrom
feature/cpl-322-tests-for-contracts

Conversation

@GTC6244
Copy link
Copy Markdown
Contributor

@GTC6244 GTC6244 commented May 18, 2026

Summary

  • Set up Foundry side-by-side with the existing Hardhat tooling (foundry.toml, remappings, forge-std submodule). Hardhat config and deploy paths are untouched.
  • Add 39 tests across three suites for the AccountConfig diamond and its 7 facets, plus a DiamondDeploy helper that mirrors the production Rust deployer.
  • Add a contract-tests.yml CI workflow that runs forge build + forge test on push and PR.

Test coverage

  • Diamond plumbing (11): loupe routing for every facet, supportsInterface for IERC165 / IDiamondCut / IDiamondLoupe / IERC173, ownership transfer gating, diamondCut owner-only, fallback on unknown selector, direct-ETH revert, constructor-set defaults (pricing, operators, requestedApiPayerCount).
  • Writes / Views round-trips (12): ChainSecured + managed account creation, duplicate / hash-mismatch reverts, group/usage-key/action/PKP CRUD, ChainSecured conversion (apiPayer-only, second-call revert).
  • Access control (16): APIConfig and Billing gating across owner / api payer / admin api payer / config operator / pricing operator roles, plus rejection paths. Notably verifies setApiPayers rejects a regular api payer (only owner / admin api payer permitted, preventing hostile takeover).

Out of scope here (good follow-ups): per-usage-key permission flows (canCreateGroup, canAddPkpToGroup, …), Stripe-adjacent billing surface beyond credit/debit, and fuzz/invariant tests.

Test plan

  • forge build clean
  • forge test — 39 / 39 passing locally
  • CI workflow contract-tests green on this PR

🤖 Generated with Claude Code

Sets up Foundry side-by-side with the existing Hardhat tooling and adds
39 tests across three suites covering the AccountConfig diamond:

- Diamond plumbing: loupe routing, supportsInterface, ownership transfer,
  diamondCut gating, fallback + direct-ETH reverts, constructor defaults.
- Writes/Views round-trips: account creation (ChainSecured + managed),
  group/usage-key/action/PKP CRUD, ChainSecured conversion flow.
- Access control: APIConfig and Billing gating (owner / api payer /
  admin api payer / config operator / pricing operator) and rejection
  paths.

A new contract-tests.yml workflow runs forge build + forge test on push
and PR.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@GTC6244 GTC6244 requested review from a team and Copilot May 18, 2026 15:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Comment on lines +16 to +17
/// @notice Test-only helper that deploys an `AccountConfig` diamond with all
/// production facets cut in. Mirrors the production Rust `contract_deployer`.
Comment on lines +163 to +167
function test_listGroupContents_unknownAccountReverts() public {
uint256 hash = apiKeyHashOf(user);
vm.expectRevert(abi.encodeWithSelector(AppStorage.AccountDoesNotExist.selector, hash));
views_.getAccountWalletAddress(hash);
}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable
Comment on lines +52 to +54
// FunctionNotFound(bytes4) selector + arbitrary bytes4
bytes4 unknown = bytes4(0xdeadbeef);
(bool ok,) = d.diamond.call(abi.encodePacked(unknown));
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.

2 participants