Commit d4c9793e authored by smartcontracts's avatar smartcontracts Committed by GitHub

fix[l2geth]: fix a bug where call reverts would not be propagated (#923)

* fix[l2geth]: fix a bug where call reverts would not be propagated

* chore: add changeset

* fix: remove outdated testing logic

* Update integration-tests/test/rpc.spec.ts

* lint: fix
parent 68d8290b
---
'@eth-optimism/l2geth': patch
---
Fixed a bug where reverts without data would not be correctly propagated for eth_call
......@@ -2,12 +2,7 @@ import { injectL2Context } from '@eth-optimism/core-utils'
import { Wallet, BigNumber, Contract } from 'ethers'
import { ethers } from 'hardhat'
import chai, { expect } from 'chai'
import {
sleep,
l2Provider,
GWEI,
encodeSolidityRevertMessage,
} from './shared/utils'
import { sleep, l2Provider, GWEI } from './shared/utils'
import chaiAsPromised from 'chai-as-promised'
import { OptimismEnv } from './shared/env'
import {
......@@ -129,12 +124,6 @@ describe('Basic RPC tests', () => {
})
describe('eth_call', () => {
let expectedReverterRevertData: string
before(async () => {
expectedReverterRevertData = encodeSolidityRevertMessage(revertMessage)
})
it('should correctly identify call out-of-gas', async () => {
await expect(
provider.call({
......@@ -145,9 +134,7 @@ describe('Basic RPC tests', () => {
})
it('should correctly return solidity revert data from a call', async () => {
const revertData = await provider.call(revertingTx)
const expectedRevertData = encodeSolidityRevertMessage(revertMessage)
expect(revertData).to.eq(expectedRevertData)
await expect(provider.call(revertingTx)).to.be.revertedWith(revertMessage)
})
it('should produce error when called from ethers', async () => {
......@@ -155,9 +142,9 @@ describe('Basic RPC tests', () => {
})
it('should correctly return revert data from contract creation', async () => {
const revertData = await provider.call(revertingDeployTx)
expect(revertData).to.eq(expectedReverterRevertData)
await expect(provider.call(revertingDeployTx)).to.be.revertedWith(
revertMessage
)
})
it('should correctly identify contract creation out of gas', async () => {
......@@ -172,14 +159,14 @@ describe('Basic RPC tests', () => {
it('should return the correct error message when attempting to deploy unsafe initcode', async () => {
// PUSH1 0x00 PUSH1 0x00 SSTORE
const unsafeCode = '0x6000600055'
const tx: TransactionRequest = {
data: unsafeCode,
}
const result = await provider.call(tx)
const expected = encodeSolidityRevertMessage(
await expect(
provider.call({
data: unsafeCode,
})
).to.be.revertedWith(
'Contract creation code contains unsafe opcodes. Did you use the right compiler or pass an unsafe constructor argument?'
)
expect(result).to.eq(expected)
})
})
......
......@@ -1011,7 +1011,18 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
if overrides != nil {
accounts = *overrides
}
result, _, _, err := DoCall(ctx, s.b, args, blockNrOrHash, accounts, vm.Config{}, 5*time.Second, s.b.RPCGasCap())
result, _, failed, err := DoCall(ctx, s.b, args, blockNrOrHash, accounts, vm.Config{}, 5*time.Second, s.b.RPCGasCap())
if err != nil {
return nil, err
}
if failed {
reason, errUnpack := abi.UnpackRevert(result)
err := errors.New("execution reverted")
if errUnpack == nil {
err = fmt.Errorf("execution reverted: %v", reason)
}
return (hexutil.Bytes)(result), err
}
return (hexutil.Bytes)(result), err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment