Skip to content

test: comprehensive Foundry test suite for DeviceRegistry and LensMintERC1155#40

Open
pradhyum6144 wants to merge 2 commits intoc2siorg:mainfrom
pradhyum6144:test/comprehensive-foundry-suite
Open

test: comprehensive Foundry test suite for DeviceRegistry and LensMintERC1155#40
pradhyum6144 wants to merge 2 commits intoc2siorg:mainfrom
pradhyum6144:test/comprehensive-foundry-suite

Conversation

@pradhyum6144
Copy link
Copy Markdown

Summary

  • Adds 69 new tests across 3 test files covering all public functions, revert paths, events, and cross-contract interactions for both DeviceRegistry and LensMintERC1155
  • Includes 5 fuzz tests (256 iterations each) for property-based testing of edition minting, batch operations, and maxEditions enforcement
  • Includes 4 integration tests covering full lifecycle flows across both contracts

Test Coverage

DeviceRegistry.t.sol — 27 tests

Category Tests What's covered
Registration 4 Happy path, events, multiple devices, active-by-default
Registration reverts 6 Zero address, empty publicKey/deviceId/cameraId, duplicate address, duplicate deviceId
Update 3 By registrar, by device itself, event emission
Update reverts 2 Unregistered device, unauthorized stranger
Deactivate 3 By registrar, by self, event emission
Deactivate reverts 2 Unregistered, unauthorized
Query functions 5 getDeviceByDeviceId, isDeviceActive, getTotalDevices, getAllDevices, empty returns
Reactivation 1 Deactivate then update(active=true) then verify

LensMintERC1155.t.sol — 33 tests

Category Tests What's covered
Constructor 2 State initialization, zero registry revert
mintOriginal 6 Token ID sequencing, metadata storage, recipient balance, edition count init, events, multi-device
mintOriginal reverts 2 Inactive device, unregistered device
mintEdition 5 Success + balance, metadata linking, events, maxEditions limit, unlimited (max=0)
mintEdition reverts 2 Nonexistent token, edition-of-edition
batchMintEditions 6 Success, maxEditions, atomic revert on partial fill, qty=0, nonexistent, edition token
URI 2 Correct format, nonexistent token revert
setBaseURI 3 Owner success, event, non-owner revert
canDeviceMint 3 Active, inactive, unregistered
Edge cases 2 Missing token metadata, missing edition count

LensMintFuzz.t.sol — 5 fuzz + 4 integration

Test Type What's covered
testFuzz_mintEditionQuantity Fuzz Random qty (1-50) editions, verify counts
testFuzz_batchMintEditions Fuzz Random batch qty, verify all balances
testFuzz_maxEditionsEnforced Fuzz Random maxEditions (2-30), verify exact enforcement
testFuzz_batchMintRevertsWhenExceedingMax Fuzz Random max + over-request, verify revert
testFuzz_uniqueImageHash Fuzz Random image hashes produce unique tokens
testIntegration_fullLifecycle Integration Register, mint, editions, deactivate, verify state
testIntegration_multiDeviceMinting Integration Two devices mint originals, cross-mint editions
testIntegration_firmwareUpdate Integration Firmware update does not break minting
testIntegration_deactivateReactivate Integration Deactivate, reactivate, mint resumes

Results

87 tests passed, 0 failed, 0 skipped
Fuzz: 256 runs per fuzz test

Test plan

  • forge test — all 87 tests pass
  • Fuzz tests run 256 iterations each with no failures
  • Integration tests cover multi-contract lifecycle flows

Addresses #20

…ion to mintOriginal

The mintOriginal() function previously accepted a plain string signature
parameter and stored it without any on-chain verification, allowing anyone
with an active device address to mint with a fake signature. This commit
adds cryptographic proof that the device actually signed the mint request.

Changes:
- Inherit OpenZeppelin EIP712 in LensMintERC1155 with domain "LensMintERC1155" v1
- Add ECDSA.recover verification against EIP-712 typed data digest in mintOriginal()
- Add mapping(bytes32 => bool) usedImageHashes to prevent replay of the same image
- Add per-device nonce tracking for additional replay protection
- Change mintOriginal() signature to accept (bytes32 imageHash, uint8 v, bytes32 r, bytes32 s)
- Expose domainSeparator() view for off-chain signing compatibility
- Add 15 Foundry tests covering valid signing, replay rejection, tampered params,
  wrong signer, wrong nonce, unregistered/deactivated device scenarios
- Update existing MintEditionDebug tests to use EIP-712 vm.sign flow
- Update web3Service.js with EIP-712 signTypedData and new contract ABI
- Fix evm_version paris -> cancun in foundry.toml (resolves mcopy errors)

Closes c2siorg#2
…sMintERC1155

Add 69 new tests (27 unit + 33 unit + 5 fuzz + 4 integration) covering
all public functions, revert paths, events, and cross-contract flows.

DeviceRegistry.t.sol (27 tests):
- Registration: happy path, events, multiple devices, active-by-default
- Registration reverts: zero address, empty fields, duplicate address/deviceId
- Update: by registrar, by self, events
- Update reverts: unregistered device, unauthorized caller
- Deactivate: by registrar, by self, events
- Deactivate reverts: unregistered, unauthorized
- Query functions: getDeviceByDeviceId, isDeviceActive, getTotalDevices, getAllDevices
- Reactivation after deactivate

LensMintERC1155.t.sol (33 tests):
- Constructor: state initialization, zero registry revert
- mintOriginal: token ID increment, metadata storage, recipient balance,
  edition count init, event emission, multi-device minting
- mintOriginal reverts: inactive device, unregistered device
- mintEdition: success, metadata linking, events, maxEditions enforcement,
  unlimited editions (maxEditions=0)
- mintEdition reverts: nonexistent token, edition-of-edition
- batchMintEditions: success with count verification, maxEditions enforcement,
  atomic revert on partial fill, quantity=0, nonexistent token, edition token
- URI: correct format, nonexistent token revert
- setBaseURI: owner-only, event, non-owner revert
- canDeviceMint: active, inactive, unregistered
- Edge cases: missing token metadata, missing edition count

LensMintFuzz.t.sol (5 fuzz + 4 integration):
- Fuzz: random edition quantity (1-50), batch quantity, maxEditions enforcement,
  batch revert when exceeding max, unique image hashes
- Integration: full lifecycle (register → mint → editions → deactivate),
  multi-device cross-minting, firmware update, deactivate-reactivate cycle

All 87 tests pass (256 fuzz iterations each).

Addresses c2siorg#20
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.

1 participant