-
Notifications
You must be signed in to change notification settings - Fork 1
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
test storage persistence after registry upgrade #2
Open
mdtanrikulu
wants to merge
6
commits into
mdt/fixed-storage-pattern
Choose a base branch
from
mdt/test-storage-persistence
base: mdt/fixed-storage-pattern
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
6 commits
Select commit
Hold shift + click to select a range
195f151
test storage persistence after registry upgrade
mdtanrikulu b7d1d1c
remove unnecessary creator check, since it's a part of address creati…
mdtanrikulu ea98561
implement common ITransParentVerifiableProxy interface
mdtanrikulu fb49cab
Merge branch 'mdt/fixed-storage-pattern' into mdt/test-storage-persis…
mdtanrikulu aa39c67
fix interface
mdtanrikulu 73242b9
add slot derivation test
mdtanrikulu 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
Submodule openzeppelin-contracts
updated
5 files
This file contains 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,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
interface ITransparentVerifiableProxy { | ||
function salt() external view returns (uint256); | ||
|
||
function owner() external view returns (address); | ||
|
||
function creator() external view returns (address); | ||
|
||
/// @dev See {UUPSUpgradeable-upgradeToAndCall} | ||
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable; | ||
} |
This file contains 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 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 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,72 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/TransparentVerifiableProxy.sol"; | ||
import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol"; | ||
import {MockRegistry} from "../src/mock/MockRegistry.sol"; | ||
|
||
contract TransparentVerifiableProxyTest is Test { | ||
using SlotDerivation for bytes32; | ||
|
||
TransparentVerifiableProxy proxy; | ||
|
||
address creator = address(0x1); | ||
address owner = address(0x2); | ||
address implementation = address(new MockRegistry()); | ||
uint256 salt = 12345; | ||
bytes emptyData; | ||
|
||
string internal constant _VERIFICATION_SLOT = "proxy.verifiable"; | ||
string internal constant _SALT = "salt"; | ||
string internal constant _OWNER = "owner"; | ||
|
||
function setUp() public { | ||
proxy = new TransparentVerifiableProxy(creator); | ||
} | ||
|
||
function testInitialize() public { | ||
// initialize the proxy | ||
proxy.initialize(salt, owner, implementation, emptyData); | ||
|
||
// check salt and owner values | ||
assertEq(proxy.salt(), salt, "Salt mismatch"); | ||
assertEq(proxy.owner(), owner, "Owner mismatch"); | ||
} | ||
|
||
function testSaltStorage() public { | ||
// initialize the proxy | ||
proxy.initialize(salt, owner, implementation, emptyData); | ||
|
||
// compute the base slot | ||
bytes32 baseSlot = SlotDerivation.erc7201Slot(_VERIFICATION_SLOT); | ||
|
||
// use SlotDerivation to compute the salt slot | ||
bytes32 saltSlot = baseSlot.deriveMapping(_SALT); | ||
|
||
// directly manipulate the storage for the salt | ||
uint256 newSalt = 54321; | ||
vm.store(address(proxy), saltSlot, bytes32(newSalt)); | ||
|
||
// verify the updated salt | ||
assertEq(proxy.salt(), newSalt, "Salt update failed"); | ||
} | ||
|
||
function testOwnerStorage() public { | ||
// initialize the proxy | ||
proxy.initialize(salt, owner, implementation, emptyData); | ||
|
||
// compute the base slot | ||
bytes32 baseSlot = SlotDerivation.erc7201Slot(_VERIFICATION_SLOT); | ||
|
||
// use SlotDerivation to compute the owner slot | ||
bytes32 ownerSlot = baseSlot.deriveMapping(_OWNER); | ||
|
||
// directly manipulate the storage for the owner | ||
address newOwner = address(0x4); | ||
vm.store(address(proxy), ownerSlot, bytes32(uint256(uint160(newOwner)))); | ||
|
||
// verify the updated owner | ||
assertEq(proxy.owner(), newOwner, "Owner update failed"); | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you deleted it from the interface but not from the code?
Thinking about it, it may still be useful to have; otherwise there's no way to know which factory to check if all you have is an instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the interface here is only under the
VerifiableFactory
scope, the actual creator is a public immutable variable which will have the auto-generated getter interface, do we need to have it explicitly under VerifiableFactory if not in use?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. No, but we should be having the proxy implement the same interface we use here - otherwise there could be a mismatch between what the proxy implements and the interface specifies and we wouldn't know at compile-time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surely, both salt and the owner implements exactly as stated here. Then I will create a common interface shared between Proxy contract and Factory contract, just to be sure there won't be any mismatch for the future changes.