-
Notifications
You must be signed in to change notification settings - Fork 2
test: fixtures out of the src mirror, and one conforming ICloneableV2 #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thedavidmeister
wants to merge
3
commits into
main
Choose a base branch
from
2026-08-24-test-fixtures-out-of-src-mirror
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
File renamed without changes.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // SPDX-License-Identifier: LicenseRef-DCL-1.0 | ||
| // SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {ICloneableV2} from "src/interface/ICloneableV2.sol"; | ||
|
|
||
| /// Thrown by a second call to `TestCloneable.initialize`. `ICloneableV2` says | ||
| /// the implementation MUST ensure `initialize` can NOT be called more than | ||
| /// once; this is how this fixture ensures it. | ||
| error TestCloneableAlreadyInitialized(); | ||
|
|
||
| /// @title TestCloneable | ||
| /// @notice THE conforming `ICloneableV2` fixture. Every test that needs a | ||
| /// clone that initializes successfully uses this one, so there is a single | ||
| /// place where "what a correct `ICloneableV2` does" is written down, and every | ||
| /// flow test in the suite is run against something that actually honours the | ||
| /// interface rather than against the minimum the factory happens to check. | ||
| /// | ||
| /// Three properties, each load bearing: | ||
| /// | ||
| /// - It stores whatever `data` it was initialized with in the public `sData`, | ||
| /// so a test can prove the bytes reached the clone verbatim. | ||
| /// - `initialize` can NOT be called more than once — the interface's first | ||
| /// normative MUST. The flag is written before the data so a re-entrant call | ||
| /// cannot slip past the guard. | ||
| /// - It returns the success sentinel written out from the LITERAL STRING | ||
| /// `ICloneableV2` names, NOT the imported `ICLONEABLE_V2_SUCCESS`. Importing | ||
| /// the constant would put both sides of the library's comparison in | ||
| /// lockstep: change the constant and every clone still initializes, because | ||
| /// the fixture changed with it. A third party implementing `ICloneableV2` | ||
| /// has no such luxury — the interface tells them to return | ||
| /// `keccak256("ICloneableV2.initialize")` and they hard-code that value — so | ||
| /// the fixture hard-codes it too, and a drift in the constant surfaces as a | ||
| /// real `InitializationFailed` through a real factory. | ||
| /// | ||
| /// It also carries the RECOMMENDED typed overload, which the interface | ||
| /// requires to revert `InitializeSignatureFn` always. | ||
| contract TestCloneable is ICloneableV2 { | ||
| /// The data this clone was initialized with. Set once. | ||
| bytes public sData; | ||
|
|
||
| /// Whether `initialize` has already run on this clone. Storage lives on | ||
| /// the clone, not the implementation, because the factory reaches this | ||
| /// code through an EIP-1167 `DELEGATECALL` proxy. | ||
| bool public sInitialized; | ||
|
|
||
| /// @inheritdoc ICloneableV2 | ||
| function initialize(bytes memory data) external returns (bytes32) { | ||
| if (sInitialized) { | ||
| revert TestCloneableAlreadyInitialized(); | ||
| } | ||
| sInitialized = true; | ||
| sData = data; | ||
| // Deliberately the literal, not `ICLONEABLE_V2_SUCCESS`. See the | ||
| // contract notice. | ||
| return keccak256("ICloneableV2.initialize"); | ||
| } | ||
|
|
||
| /// The RECOMMENDED typed overload of `initialize`, which exists only so an | ||
| /// initialization config type appears in the ABI. `ICloneableV2` requires | ||
| /// it to revert `InitializeSignatureFn` ALWAYS, so that it is never | ||
| /// accidentally called in place of the generic `initialize(bytes)` the | ||
| /// factory calls. The parameter is unnamed because it is never read. | ||
| /// @return Never returns; the declared return type only exists so the | ||
| /// overload has the shape a real typed `initialize` would. | ||
| function initialize(uint256) external pure returns (bytes32) { | ||
| revert InitializeSignatureFn(); | ||
| } | ||
| } |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.