Skip to content

Commit

Permalink
fix[l2geth]: fix a bug where call reverts would not be propagated (#923)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
smartcontracts committed May 20, 2021
1 parent 68d8290 commit d4c9793
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-ravens-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Fixed a bug where reverts without data would not be correctly propagated for eth_call
35 changes: 11 additions & 24 deletions integration-tests/test/rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand All @@ -145,19 +134,17 @@ 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 () => {
await expect(Reverter.doRevert()).to.be.revertedWith(revertMessage)
})

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 () => {
Expand All @@ -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)
})
})

Expand Down
13 changes: 12 additions & 1 deletion l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d4c9793

Please sign in to comment.