Commit 8c722a0a authored by Indeavr's avatar Indeavr

(integration-tests): Added tests checking msg.sender value of eth_call

parent 3e3c07a3
module.exports = {
...require('../.prettierrc.js'),
}
../.prettierrc.json
\ No newline at end of file
...@@ -23,6 +23,10 @@ contract ValueContext { ...@@ -23,6 +23,10 @@ contract ValueContext {
function getCallValue() public payable returns(uint256) { function getCallValue() public payable returns(uint256) {
return msg.value; return msg.value;
} }
function getCaller() external view returns (address){
return msg.sender;
}
} }
contract ValueCalls is ValueContext { contract ValueCalls is ValueContext {
......
import { expect } from './shared/setup' import { expect } from './shared/setup'
import { expectApprox, injectL2Context } from '@eth-optimism/core-utils' 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 { serialize } from '@ethersproject/transactions'
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { import {
...@@ -233,6 +233,53 @@ describe('Basic RPC tests', () => { ...@@ -233,6 +233,53 @@ describe('Basic RPC tests', () => {
expect(res).to.eq(BigNumber.from(value)) 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', () => { describe('eth_getTransactionReceipt', () => {
......
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