Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
afcc51a4
Unverified
Commit
afcc51a4
authored
Sep 06, 2024
by
Matt Solomon
Committed by
GitHub
Sep 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: more blueprint tests (#11782)
* test: more blueprint tests * address PR feedback
parent
ccf9d3e2
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
228 additions
and
26 deletions
+228
-26
Blueprint.sol
packages/contracts-bedrock/src/libraries/Blueprint.sol
+11
-7
Blueprint.t.sol
packages/contracts-bedrock/test/libraries/Blueprint.t.sol
+217
-19
No files found.
packages/contracts-bedrock/src/libraries/Blueprint.sol
View file @
afcc51a4
...
@@ -28,7 +28,7 @@ library Blueprint {
...
@@ -28,7 +28,7 @@ library Blueprint {
/// @notice Thrown when parsing a blueprint preamble and the preamble data is not empty.
/// @notice Thrown when parsing a blueprint preamble and the preamble data is not empty.
/// We do not use the preamble data, so it's expected to be empty.
/// We do not use the preamble data, so it's expected to be empty.
error UnexpectedPreambleData();
error UnexpectedPreambleData(
bytes data
);
/// @notice Thrown during deployment if the ERC version is not supported.
/// @notice Thrown during deployment if the ERC version is not supported.
error UnsupportedERCVersion(uint8 version);
error UnsupportedERCVersion(uint8 version);
...
@@ -37,6 +37,9 @@ library Blueprint {
...
@@ -37,6 +37,9 @@ library Blueprint {
/// which will deploy a corresponding blueprint contract (with no data section). Based on the
/// which will deploy a corresponding blueprint contract (with no data section). Based on the
/// reference implementation in https://eips.ethereum.org/EIPS/eip-5202.
/// reference implementation in https://eips.ethereum.org/EIPS/eip-5202.
function blueprintDeployerBytecode(bytes memory _initcode) internal pure returns (bytes memory) {
function blueprintDeployerBytecode(bytes memory _initcode) internal pure returns (bytes memory) {
// Check that the initcode is not empty.
if (_initcode.length == 0) revert EmptyInitcode();
bytes memory blueprintPreamble = hex"FE7100"; // ERC-5202 preamble.
bytes memory blueprintPreamble = hex"FE7100"; // ERC-5202 preamble.
bytes memory blueprintBytecode = bytes.concat(blueprintPreamble, _initcode);
bytes memory blueprintBytecode = bytes.concat(blueprintPreamble, _initcode);
...
@@ -89,12 +92,18 @@ library Blueprint {
...
@@ -89,12 +92,18 @@ library Blueprint {
return Preamble(ercVersion, preambleData, initcode);
return Preamble(ercVersion, preambleData, initcode);
}
}
/// @notice Parses the code at the given `_target` as a blueprint and deploys the resulting initcode.
/// This version of `deployFrom` is used when the initcode requires no constructor arguments.
function deployFrom(address _target, bytes32 _salt) internal returns (address) {
return deployFrom(_target, _salt, new bytes(0));
}
/// @notice Parses the code at the given `_target` as a blueprint and deploys the resulting initcode
/// @notice Parses the code at the given `_target` as a blueprint and deploys the resulting initcode
/// with the given `_data` appended, i.e. `_data` is the ABI-encoded constructor arguments.
/// with the given `_data` appended, i.e. `_data` is the ABI-encoded constructor arguments.
function deployFrom(address _target, bytes32 _salt, bytes memory _data) internal returns (address newContract_) {
function deployFrom(address _target, bytes32 _salt, bytes memory _data) internal returns (address newContract_) {
Preamble memory preamble = parseBlueprintPreamble(address(_target).code);
Preamble memory preamble = parseBlueprintPreamble(address(_target).code);
if (preamble.ercVersion != 0) revert UnsupportedERCVersion(preamble.ercVersion);
if (preamble.ercVersion != 0) revert UnsupportedERCVersion(preamble.ercVersion);
if (preamble.preambleData.length != 0) revert UnexpectedPreambleData();
if (preamble.preambleData.length != 0) revert UnexpectedPreambleData(
preamble.preambleData
);
bytes memory initcode = bytes.concat(preamble.initcode, _data);
bytes memory initcode = bytes.concat(preamble.initcode, _data);
assembly ("memory-safe") {
assembly ("memory-safe") {
...
@@ -103,11 +112,6 @@ library Blueprint {
...
@@ -103,11 +112,6 @@ library Blueprint {
if (newContract_ == address(0)) revert DeploymentFailed();
if (newContract_ == address(0)) revert DeploymentFailed();
}
}
/// @notice Parses the code at the given `_target` as a blueprint and deploys the resulting initcode.
function deployFrom(address _target, bytes32 _salt) internal returns (address) {
return deployFrom(_target, _salt, new bytes(0));
}
/// @notice Convert a bytes array to a uint256.
/// @notice Convert a bytes array to a uint256.
function bytesToUint(bytes memory _b) internal pure returns (uint256) {
function bytesToUint(bytes memory _b) internal pure returns (uint256) {
if (_b.length > 32) revert BytesArrayTooLong();
if (_b.length > 32) revert BytesArrayTooLong();
...
...
packages/contracts-bedrock/test/libraries/Blueprint.t.sol
View file @
afcc51a4
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment