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' ...@@ -2,12 +2,7 @@ import { injectL2Context } from '@eth-optimism/core-utils'
import { Wallet, BigNumber, Contract } from 'ethers' import { Wallet, BigNumber, Contract } from 'ethers'
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import chai, { expect } from 'chai' import chai, { expect } from 'chai'
import { import { sleep, l2Provider, GWEI } from './shared/utils'
sleep,
l2Provider,
GWEI,
encodeSolidityRevertMessage,
} from './shared/utils'
import chaiAsPromised from 'chai-as-promised' import chaiAsPromised from 'chai-as-promised'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { import {
...@@ -129,12 +124,6 @@ describe('Basic RPC tests', () => { ...@@ -129,12 +124,6 @@ describe('Basic RPC tests', () => {
}) })
describe('eth_call', () => { describe('eth_call', () => {
let expectedReverterRevertData: string
before(async () => {
expectedReverterRevertData = encodeSolidityRevertMessage(revertMessage)
})
it('should correctly identify call out-of-gas', async () => { it('should correctly identify call out-of-gas', async () => {
await expect( await expect(
provider.call({ provider.call({
...@@ -145,9 +134,7 @@ describe('Basic RPC tests', () => { ...@@ -145,9 +134,7 @@ describe('Basic RPC tests', () => {
}) })
it('should correctly return solidity revert data from a call', async () => { it('should correctly return solidity revert data from a call', async () => {
const revertData = await provider.call(revertingTx) await expect(provider.call(revertingTx)).to.be.revertedWith(revertMessage)
const expectedRevertData = encodeSolidityRevertMessage(revertMessage)
expect(revertData).to.eq(expectedRevertData)
}) })
it('should produce error when called from ethers', async () => { it('should produce error when called from ethers', async () => {
...@@ -155,9 +142,9 @@ describe('Basic RPC tests', () => { ...@@ -155,9 +142,9 @@ describe('Basic RPC tests', () => {
}) })
it('should correctly return revert data from contract creation', async () => { it('should correctly return revert data from contract creation', async () => {
const revertData = await provider.call(revertingDeployTx) await expect(provider.call(revertingDeployTx)).to.be.revertedWith(
revertMessage
expect(revertData).to.eq(expectedReverterRevertData) )
}) })
it('should correctly identify contract creation out of gas', async () => { it('should correctly identify contract creation out of gas', async () => {
...@@ -172,14 +159,14 @@ describe('Basic RPC tests', () => { ...@@ -172,14 +159,14 @@ describe('Basic RPC tests', () => {
it('should return the correct error message when attempting to deploy unsafe initcode', async () => { it('should return the correct error message when attempting to deploy unsafe initcode', async () => {
// PUSH1 0x00 PUSH1 0x00 SSTORE // PUSH1 0x00 PUSH1 0x00 SSTORE
const unsafeCode = '0x6000600055' const unsafeCode = '0x6000600055'
const tx: TransactionRequest = {
await expect(
provider.call({
data: unsafeCode, data: unsafeCode,
} })
const result = await provider.call(tx) ).to.be.revertedWith(
const expected = encodeSolidityRevertMessage(
'Contract creation code contains unsafe opcodes. Did you use the right compiler or pass an unsafe constructor argument?' '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 ...@@ -1011,7 +1011,18 @@ func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNrOr
if overrides != nil { if overrides != nil {
accounts = *overrides 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 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