Comments (5)
Contracts can interact with this "cross domain messenger" with the same interface as is given by the l2geth precompile but the mock simplifies relaying the message (and doesn't actually do any "cross domain" calls as everything is happening in the jsvm)
Sorry, I was being a numpty and didn't realize I was overlooking the cross-domain messaging 😅.
l2geth doesn't give revert messages, will only show gas estimations for l2 contracts with solidity-gas-reporter (even if you have l1 contracts you interact with in your tests) and is incompatible with
solidity-coverage
.
ethereum-optimism/optimism/issues/474 should fix the issue with revert reasons not being returned when using l2geth.
from community-hub.
Per this comment on ethereum-optimism/optimism/issues/474, the fix for revert reasons issue will not be pushed to production until 05/03/21
from community-hub.
Stale
from community-hub.
could you expand on what exactly to mock and give an example?
Basically any Optimism precompiles that you use when running your tests on l2geth (OVM_ETH, cross domain messengers, etc, etc) need to be manually deployed in the jsvm (where as on L2 geth they are assigned addresses at geth startup and useable without setup in tests).
However some of those contracts are pretty complex to setup manually on L1 and require external relayers, etc so for some I would recommend writing a custom "mock" version.
Here's my extremely insecure (but simple) implementation of a mock "cross domain messenger":
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.7.6;
contract MockCrossDomainMessenger {
struct xDomainMessage {
address _target;
bytes _message;
uint32 _gasLimit;
address sender;
}
xDomainMessage currentMessage;
function xDomainMessageSender() external view returns (address) {
return currentMessage.sender;
}
function sendMessage(
address _target,
bytes memory _message,
uint32 _gasLimit
) external {
uint256 startingGas = gasleft();
uint256 gasToConsume = _gasLimit / 32;
currentMessage = xDomainMessage(_target, _message, _gasLimit, msg.sender);
// Mimic enqueue gas burn (https://github.com/ethereum-optimism/optimism/blob/master/packages/contracts/contracts/optimistic-ethereum/OVM/chain/OVM_CanonicalTransactionChain.sol)
uint256 i;
while (startingGas - gasleft() < gasToConsume) {
i++;
}
}
function relayCurrentMessage() external {
(bool success, bytes memory result) = currentMessage._target.call(currentMessage._message);
require(success, _getRevertMsg(result));
delete currentMessage;
}
function _getRevertMsg(bytes memory _returnData) private pure returns (string memory) {
// If the _res length is less than 68, then the transaction failed silently (without a revert message)
if (_returnData.length < 68) return "Transaction reverted silently";
assembly {
// Slice the sighash.
_returnData := add(_returnData, 0x04)
}
return abi.decode(_returnData, (string)); // All that remains is the revert string
}
}
Contracts can interact with this "cross domain messenger" with the same interface as is given by the l2geth precompile but the mock simplifies relaying the message (and doesn't actually do any "cross domain" calls as everything is happening in the jsvm)
from community-hub.
It can also be more explicit that debugging first with the jsvm and local l2geth is far easier than against Kovan or in a CI.
Mainly was emphasizing that debugging with jsvm specifically is much easier than l2geth. l2geth doesn't give revert messages, will only show gas estimations for l2 contracts with solidity-gas-reporter
(even if you have l1 contracts you interact with in your tests) and is incompatible with solidity-coverage
. You also can't use hardhat's console.sol
with l2geth of course.
from community-hub.
Related Issues (20)
- 404: Sequencing documentation 😔 HOT 2
- Add a native faucet into the facet page. HOT 2
- Run a node link is for an archived github repo HOT 1
- False information in the docs? HOT 7
- Why doesn't the op have its own currency? I see that online and test chain transactions are displayed with eth? HOT 1
- L1 to L2 Deposit Example Link is broken
- Order network providers in providers.md alphabetically HOT 1
- Typo in "How is this going to be governed?" HOT 1
- Suggest a wallet HOT 2
- dead links in attestation docs HOT 2
- I'd love to see a wallet that is like a widget. similar to Samsung galaxy edge panel, a drawer type navigation bar widget.
- Gas fee increasing HOT 1
- I proceed
- Pre-bedrock protocol specs need to be updated throughout the docs
- Running a node without Docker docs requires more detail about l1kind HOT 1
- typo error ----Running an OP Mainnet or testnet node HOT 1
- Help joining new to community
- I agree please release
- Add LlamaNodes to - Node & API Providers
- Fix Broken Links HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from community-hub.