diff --git a/integration-tests/.prettierrc.js b/integration-tests/.prettierrc.js new file mode 100644 index 000000000000..0d9f53f687c7 --- /dev/null +++ b/integration-tests/.prettierrc.js @@ -0,0 +1,3 @@ +module.exports = { + ...require('../.prettierrc.js'), +} diff --git a/integration-tests/.prettierrc.json b/integration-tests/.prettierrc.json deleted file mode 120000 index 0e9207b84613..000000000000 --- a/integration-tests/.prettierrc.json +++ /dev/null @@ -1 +0,0 @@ -../.prettierrc.json \ No newline at end of file diff --git a/integration-tests/contracts/ValueCalls.sol b/integration-tests/contracts/ValueCalls.sol index 9817024eb98e..101d4d3a4874 100644 --- a/integration-tests/contracts/ValueCalls.sol +++ b/integration-tests/contracts/ValueCalls.sol @@ -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 { diff --git a/integration-tests/test/rpc.spec.ts b/integration-tests/test/rpc.spec.ts index 737904d8a878..b02dc0ac487e 100644 --- a/integration-tests/test/rpc.spec.ts +++ b/integration-tests/test/rpc.spec.ts @@ -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 { @@ -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', () => {