test: comprehensive Foundry test suite for DeviceRegistry and LensMintERC1155#40
Open
pradhyum6144 wants to merge 2 commits intoc2siorg:mainfrom
Open
test: comprehensive Foundry test suite for DeviceRegistry and LensMintERC1155#40pradhyum6144 wants to merge 2 commits intoc2siorg:mainfrom
pradhyum6144 wants to merge 2 commits intoc2siorg:mainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DeviceRegistryandLensMintERC1155Test Coverage
DeviceRegistry.t.sol— 27 testsLensMintERC1155.t.sol— 33 testsLensMintFuzz.t.sol— 5 fuzz + 4 integrationResults
Test plan
Addresses #20