Skip to content

Commit

Permalink
(integration-tests): Added tests checking msg.sender value of eth_call
Browse files Browse the repository at this point in the history
  • Loading branch information
indeavr committed Jan 12, 2022
1 parent 3e3c07a commit 8c722a0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions integration-tests/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('../.prettierrc.js'),
}
1 change: 0 additions & 1 deletion integration-tests/.prettierrc.json

This file was deleted.

4 changes: 4 additions & 0 deletions integration-tests/contracts/ValueCalls.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ contract ValueContext {
function getCallValue() public payable returns(uint256) {
return msg.value;
}

function getCaller() external view returns (address){
return msg.sender;
}
}

contract ValueCalls is ValueContext {
Expand Down
49 changes: 48 additions & 1 deletion integration-tests/test/rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from './shared/setup'

import { expectApprox, injectL2Context } from '@eth-optimism/core-utils'
import { Wallet, BigNumber, Contract, ContractFactory } from 'ethers'
import { Wallet, BigNumber, Contract, ContractFactory, constants } from 'ethers'
import { serialize } from '@ethersproject/transactions'
import { ethers } from 'hardhat'
import {
Expand Down Expand Up @@ -233,6 +233,53 @@ describe('Basic RPC tests', () => {

expect(res).to.eq(BigNumber.from(value))
})

// https://github.com/ethereum-optimism/optimism/issues/1998
it('should use address(0) as the default "from" value', async () => {
// Deploy a contract to check msg.caller
const Factory__ValueContext: ContractFactory =
await ethers.getContractFactory('ValueContext', wallet)
const ValueContext: Contract = await Factory__ValueContext.deploy()
await ValueContext.deployTransaction.wait()

// Do the call and check msg.sender
const data = ValueContext.interface.encodeFunctionData('getCaller')
const res = await provider.call({
to: ValueContext.address,
data,
})

const [paddedRes] = ValueContext.interface.decodeFunctionResult(
'getCaller',
res
)

expect(paddedRes).to.eq(constants.AddressZero)
})

it('should correctly use the "from" value', async () => {
// Deploy a contract to check msg.caller
const Factory__ValueContext: ContractFactory =
await ethers.getContractFactory('ValueContext', wallet)
const ValueContext: Contract = await Factory__ValueContext.deploy()
await ValueContext.deployTransaction.wait()

const from = wallet.address

// Do the call and check msg.sender
const data = ValueContext.interface.encodeFunctionData('getCaller')
const res = await provider.call({
to: ValueContext.address,
from,
data,
})

const [paddedRes] = ValueContext.interface.decodeFunctionResult(
'getCaller',
res
)
expect(paddedRes).to.eq(from)
})
})

describe('eth_getTransactionReceipt', () => {
Expand Down

0 comments on commit 8c722a0

Please sign in to comment.