-
Notifications
You must be signed in to change notification settings - Fork 473
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
DevEx workflow improvement #88
Comments
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) |
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 |
Sorry, I was being a numpty and didn't realize I was overlooking the cross-domain messaging 😅.
ethereum-optimism/optimism/issues/474 should fix the issue with revert reasons not being returned when using l2geth. |
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 |
Stale |
Description
@TransmissionsDev suggested that docs should more clearly advise that your tests work on jsvm and local l2geth before testing against Kovan or in a CI.
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.
There should be more emphasis on this suggestion.
Motivation
Quoting @TransmissionsDev from discord:
"That way all the existing tooling will work and you get nice revert messages.
If you use
xDomainMessenger
and other stuff, you are going to have to mock that out but it is worth it."@TransmissionsDev could you expand on what exactly to mock and give an example?
Additional motivation:
Estimated effort and complexity
Tags to related packages
l2geth
Update
Include content in docs that addresses t11s' reply below:
The text was updated successfully, but these errors were encountered: