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
edb93245
Unverified
Commit
edb93245
authored
Jul 14, 2023
by
refcell.eth
Committed by
GitHub
Jul 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for PreimageOracle (#6293)
parent
533ee802
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
2 deletions
+66
-2
preimageoracle_more.go
op-bindings/bindings/preimageoracle_more.go
+1
-1
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+3
-0
PreimageOracle.sol
...ges/contracts-bedrock/contracts/cannon/PreimageOracle.sol
+1
-1
PreimageOracle.t.sol
...ges/contracts-bedrock/contracts/test/PreimageOracle.t.sol
+61
-0
No files found.
op-bindings/bindings/preimageoracle_more.go
View file @
edb93245
This diff is collapsed.
Click to expand it.
packages/contracts-bedrock/.gas-snapshot
View file @
edb93245
...
...
@@ -331,6 +331,9 @@ OptimismPortal_Test:test_receive_succeeds() (gas: 127513)
OptimismPortal_Test:test_simple_isOutputFinalized_succeeds() (gas: 32971)
OptimismPortal_Test:test_unpause_onlyGuardian_reverts() (gas: 46098)
OptimismPortal_Test:test_unpause_succeeds() (gas: 31756)
PreimageOracle_Test:test_computePreimageKey_succeeds() (gas: 6267)
PreimageOracle_Test:test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() (gas: 9025)
PreimageOracle_Test:test_loadKeccak256PreimagePart_succeeds() (gas: 77552)
ProxyAdmin_Test:test_chugsplashChangeProxyAdmin_succeeds() (gas: 35586)
ProxyAdmin_Test:test_chugsplashGetProxyAdmin_succeeds() (gas: 15675)
ProxyAdmin_Test:test_chugsplashGetProxyImplementation_succeeds() (gas: 51084)
...
...
packages/contracts-bedrock/contracts/cannon/PreimageOracle.sol
View file @
edb93245
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
pragma solidity
^
0.8.15;
/// @title PreimageOracle
/// @notice A contract for storing permissioned pre-images.
...
...
packages/contracts-bedrock/contracts/test/PreimageOracle.t.sol
0 → 100644
View file @
edb93245
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import { Test } from "forge-std/Test.sol";
import { PreimageOracle } from "../cannon/PreimageOracle.sol";
contract PreimageOracle_Test is Test {
PreimageOracle oracle;
/// @notice Sets up the testing suite.
function setUp() public {
oracle = new PreimageOracle();
vm.label(address(oracle), "PreimageOracle");
}
/// @notice Test the pre-image key computation with a known pre-image.
function test_computePreimageKey_succeeds() public {
bytes memory preimage = hex"deadbeef";
bytes32 key = oracle.computePreimageKey(preimage);
bytes32 known = 0x02fd4e189132273036449fc9e11198c739161b4c0116a9a2dccdfa1c492006f1;
assertEq(key, known);
}
/// @notice Tests that a pre-image is correctly set.
function test_loadKeccak256PreimagePart_succeeds() public {
// Set the pre-image
bytes memory preimage = hex"deadbeef";
bytes32 key = oracle.computePreimageKey(preimage);
uint256 offset = 0;
oracle.loadKeccak256PreimagePart(offset, preimage);
// Validate the pre-image part
bytes32 part = oracle.preimageParts(key, offset);
bytes32 expectedPart = 0x0000000000000004deadbeef0000000000000000000000000000000000000000;
assertEq(part, expectedPart);
// Validate the pre-image length
uint256 length = oracle.preimageLengths(key);
assertEq(length, preimage.length);
// Validate that the pre-image part is set
bool ok = oracle.preimagePartOk(key, offset);
assertTrue(ok);
}
/// @notice Tests that a pre-image cannot be set with an out-of-bounds offset.
function test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() public {
bytes memory preimage = hex"deadbeef";
uint256 offset = preimage.length + 9;
vm.expectRevert();
oracle.loadKeccak256PreimagePart(offset, preimage);
}
/// @notice Reading a pre-image part that has not been set should revert.
function testFuzz_readPreimage_missingPreimage_reverts(bytes32 key, uint256 offset) public {
vm.expectRevert("pre-image must exist");
oracle.readPreimage(key, offset);
}
}
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