Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tarrencev/forge-optimism
https://github.com/tarrencev/forge-optimism
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tarrencev/forge-optimism
- Owner: tarrencev
- License: apache-2.0
- Created: 2022-01-27T15:14:52.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-05T04:55:30.000Z (over 2 years ago)
- Last Synced: 2024-04-08T22:04:35.517Z (7 months ago)
- Language: Solidity
- Size: 14.6 KB
- Stars: 56
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-foundry - Forge Optimism - Forge Optimism is a collection of helpful contracts for use with forge and foundry on Optimism. (Templates & Libraries)
README
# forge-optimism
Forge Optimism is a collection of helpful contracts for use with forge and foundry. It leverages forge's cheatcodes to allow tests to easily setup and manipulation optimism predeploys.
## Installation
```bash
forge install tarrencev/forge-optimism
```## Contracts
`src/OptimismTest.sol`
Sets up the Optimism execution context for the test.
- Configures `Proxy__OVM_L1CrossDomainMessenger` and `L2CrossDomainMessenger` to enable simulating message passing between chains.
- Implements `OptimismVm` which exposes cheat codes for manipulating the optimism execution context (values returned by predeploys).### Usage
```solidity
import {OptimismVm, OptimismTest} from "forge-optimism/Optimism.sol";
import {iOVM_L1BlockNumber} from "forge-optimism/interfaces/iOVM_L1BlockNumber.sol";
import {iOVM_CrossDomainMessenger} from "forge-optimism/interfaces/iOVM_CrossDomainMessenger.sol";
import {Lib_PredeployAddresses} from "forge-optimism/lib/Lib_PredeployAddresses.sol";contract Test is OptimismTest, DSTest {
OptimismVm internal ovm = new OptimismVm();...
function testSomething() public {
// Make a call to the L1 xCrossDomainMessenger, preconfigured to the mainnet address
l1cdm.sendMessage(target, abi.encodeWithSelector(...), 0);// Make a call to the L2 xCrossDomainMessenger
iOVM_CrossDomainMessenger(Lib_PredeployAddresses.L2_CROSS_DOMAIN_MESSENGER).sendMessage(target, abi.encodeWithSelector(...), 0);// Set the return value of OVM_L1BlockNumber.getL1BlockNumber
ovm.warp(10);
assertEq(iOVM_L1BlockNumber(Lib_PredeployAddresses.L1_BLOCK_NUMBER).getL1BlockNumber(), 10);
}
}
```