Commit 45642dc8 authored by Antonis Kogias's avatar Antonis Kogias

replaced l1Provider and l2Provider with env.l1Provider and env.l2Provider

parent 752a2d1f
---
'@eth-optimism/integration-tests': patch
---
Replaces l1Provider and l2Provider with env.l1Provider and env.l2Provider respectively.
...@@ -2,17 +2,11 @@ ...@@ -2,17 +2,11 @@
import { ethers } from 'hardhat' import { ethers } from 'hardhat'
import { expectApprox } from '@eth-optimism/core-utils' import { expectApprox } from '@eth-optimism/core-utils'
import { predeploys } from '@eth-optimism/contracts' import { predeploys } from '@eth-optimism/contracts'
import { asL2Provider } from '@eth-optimism/sdk'
import { Contract, BigNumber } from 'ethers' import { Contract, BigNumber } from 'ethers'
/* Imports: Internal */ /* Imports: Internal */
import { expect } from './shared/setup' import { expect } from './shared/setup'
import { import { envConfig, DEFAULT_TEST_GAS_L1 } from './shared/utils'
l2Provider,
l1Provider,
envConfig,
DEFAULT_TEST_GAS_L1,
} from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
/** /**
...@@ -21,7 +15,6 @@ import { OptimismEnv } from './shared/env' ...@@ -21,7 +15,6 @@ import { OptimismEnv } from './shared/env'
* must be equal to the blocknumber/timestamp of the L1 transaction. * must be equal to the blocknumber/timestamp of the L1 transaction.
*/ */
describe('OVM Context: Layer 2 EVM Context', () => { describe('OVM Context: Layer 2 EVM Context', () => {
const L2Provider = asL2Provider(l2Provider)
let env: OptimismEnv let env: OptimismEnv
before(async () => { before(async () => {
env = await OptimismEnv.new() env = await OptimismEnv.new()
...@@ -66,8 +59,10 @@ describe('OVM Context: Layer 2 EVM Context', () => { ...@@ -66,8 +59,10 @@ describe('OVM Context: Layer 2 EVM Context', () => {
// Get the L1 block that the enqueue transaction was in so that // Get the L1 block that the enqueue transaction was in so that
// the timestamp can be compared against the layer two contract // the timestamp can be compared against the layer two contract
const l1Block = await l1Provider.getBlock(pair.receipt.blockNumber) const l1Block = await env.l1Provider.getBlock(pair.receipt.blockNumber)
const l2Block = await l2Provider.getBlock(pair.remoteReceipt.blockNumber) const l2Block = await env.l2Provider.getBlock(
pair.remoteReceipt.blockNumber
)
// block.number should return the value of the L2 block number. // block.number should return the value of the L2 block number.
const l2BlockNumber = await OVMContextStorage.blockNumbers(i) const l2BlockNumber = await OVMContextStorage.blockNumbers(i)
...@@ -103,7 +98,7 @@ describe('OVM Context: Layer 2 EVM Context', () => { ...@@ -103,7 +98,7 @@ describe('OVM Context: Layer 2 EVM Context', () => {
}) })
await dummyTx.wait() await dummyTx.wait()
const block = await L2Provider.getBlockWithTransactions('latest') const block = await env.l2Provider.getBlockWithTransactions('latest')
const [, returnData] = await Multicall.callStatic.aggregate( const [, returnData] = await Multicall.callStatic.aggregate(
[ [
[ [
......
/* Imports: External */ /* Imports: External */
import { expectApprox, sleep } from '@eth-optimism/core-utils' import { expectApprox, sleep } from '@eth-optimism/core-utils'
import { asL2Provider } from '@eth-optimism/sdk'
import { Wallet, BigNumber, Contract, ContractFactory, constants } 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'
...@@ -11,7 +10,6 @@ import { ...@@ -11,7 +10,6 @@ import {
/* Imports: Internal */ /* Imports: Internal */
import { import {
l2Provider,
defaultTransactionFactory, defaultTransactionFactory,
fundUser, fundUser,
L2_CHAINID, L2_CHAINID,
...@@ -27,8 +25,6 @@ describe('Basic RPC tests', () => { ...@@ -27,8 +25,6 @@ describe('Basic RPC tests', () => {
let env: OptimismEnv let env: OptimismEnv
let wallet: Wallet let wallet: Wallet
const provider = asL2Provider(l2Provider)
let Reverter: Contract let Reverter: Contract
let ValueContext: Contract let ValueContext: Contract
let revertMessage: string let revertMessage: string
...@@ -86,7 +82,7 @@ describe('Basic RPC tests', () => { ...@@ -86,7 +82,7 @@ describe('Basic RPC tests', () => {
} }
await expect( await expect(
provider.sendTransaction(await wallet.signTransaction(tx)) env.l2Provider.sendTransaction(await wallet.signTransaction(tx))
).to.be.rejectedWith('invalid transaction: invalid sender') ).to.be.rejectedWith('invalid transaction: invalid sender')
}) })
...@@ -98,7 +94,7 @@ describe('Basic RPC tests', () => { ...@@ -98,7 +94,7 @@ describe('Basic RPC tests', () => {
chainId: null, // Disables EIP155 transaction signing. chainId: null, // Disables EIP155 transaction signing.
} }
const signed = await wallet.signTransaction(tx) const signed = await wallet.signTransaction(tx)
const response = await provider.sendTransaction(signed) const response = await env.l2Provider.sendTransaction(signed)
expect(response.chainId).to.equal(0) expect(response.chainId).to.equal(0)
const v = response.v const v = response.v
...@@ -114,12 +110,14 @@ describe('Basic RPC tests', () => { ...@@ -114,12 +110,14 @@ describe('Basic RPC tests', () => {
value: ethers.utils.parseEther('0.1'), value: ethers.utils.parseEther('0.1'),
} }
const balanceBefore = await provider.getBalance(env.l2Wallet.address) const balanceBefore = await env.l2Provider.getBalance(
env.l2Wallet.address
)
const result = await env.l2Wallet.sendTransaction(tx) const result = await env.l2Wallet.sendTransaction(tx)
const receipt = await result.wait() const receipt = await result.wait()
expect(receipt.status).to.deep.equal(1) expect(receipt.status).to.deep.equal(1)
const balAfter = await provider.getBalance(env.l2Wallet.address) const balAfter = await env.l2Provider.getBalance(env.l2Wallet.address)
expect(balAfter.lte(balanceBefore.sub(ethers.utils.parseEther('0.1')))).to expect(balAfter.lte(balanceBefore.sub(ethers.utils.parseEther('0.1')))).to
.be.true .be.true
}) })
...@@ -187,7 +185,7 @@ describe('Basic RPC tests', () => { ...@@ -187,7 +185,7 @@ describe('Basic RPC tests', () => {
describe('eth_call', () => { describe('eth_call', () => {
it('should correctly identify call out-of-gas', async () => { it('should correctly identify call out-of-gas', async () => {
await expect( await expect(
provider.call({ env.l2Provider.call({
...revertingTx, ...revertingTx,
gasLimit: 1, gasLimit: 1,
}) })
...@@ -195,7 +193,9 @@ describe('Basic RPC tests', () => { ...@@ -195,7 +193,9 @@ 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 () => {
await expect(provider.call(revertingTx)).to.be.revertedWith(revertMessage) await expect(env.l2Provider.call(revertingTx)).to.be.revertedWith(
revertMessage
)
}) })
it('should produce error when called from ethers', async () => { it('should produce error when called from ethers', async () => {
...@@ -203,14 +203,14 @@ describe('Basic RPC tests', () => { ...@@ -203,14 +203,14 @@ describe('Basic RPC tests', () => {
}) })
it('should correctly return revert data from contract creation', async () => { it('should correctly return revert data from contract creation', async () => {
await expect(provider.call(revertingDeployTx)).to.be.revertedWith( await expect(env.l2Provider.call(revertingDeployTx)).to.be.revertedWith(
revertMessage revertMessage
) )
}) })
it('should correctly identify contract creation out of gas', async () => { it('should correctly identify contract creation out of gas', async () => {
await expect( await expect(
provider.call({ env.l2Provider.call({
...revertingDeployTx, ...revertingDeployTx,
gasLimit: 1, gasLimit: 1,
}) })
...@@ -225,7 +225,7 @@ describe('Basic RPC tests', () => { ...@@ -225,7 +225,7 @@ describe('Basic RPC tests', () => {
// Do the call and check msg.value // Do the call and check msg.value
const data = ValueContext.interface.encodeFunctionData('getCallValue') const data = ValueContext.interface.encodeFunctionData('getCallValue')
const res = await provider.call({ const res = await env.l2Provider.call({
to: ValueContext.address, to: ValueContext.address,
from, from,
data, data,
...@@ -239,7 +239,7 @@ describe('Basic RPC tests', () => { ...@@ -239,7 +239,7 @@ describe('Basic RPC tests', () => {
it('should use address(0) as the default "from" value', async () => { it('should use address(0) as the default "from" value', async () => {
// Do the call and check msg.sender // Do the call and check msg.sender
const data = ValueContext.interface.encodeFunctionData('getCaller') const data = ValueContext.interface.encodeFunctionData('getCaller')
const res = await provider.call({ const res = await env.l2Provider.call({
to: ValueContext.address, to: ValueContext.address,
data, data,
}) })
...@@ -257,7 +257,7 @@ describe('Basic RPC tests', () => { ...@@ -257,7 +257,7 @@ describe('Basic RPC tests', () => {
// Do the call and check msg.sender // Do the call and check msg.sender
const data = ValueContext.interface.encodeFunctionData('getCaller') const data = ValueContext.interface.encodeFunctionData('getCaller')
const res = await provider.call({ const res = await env.l2Provider.call({
to: ValueContext.address, to: ValueContext.address,
from, from,
data, data,
...@@ -297,9 +297,8 @@ describe('Basic RPC tests', () => { ...@@ -297,9 +297,8 @@ describe('Basic RPC tests', () => {
} }
expect(errored).to.be.true expect(errored).to.be.true
const receipt: TransactionReceipt = await provider.getTransactionReceipt( const receipt: TransactionReceipt =
tx.hash await env.l2Provider.getTransactionReceipt(tx.hash)
)
expect(receipt.status).to.eq(0) expect(receipt.status).to.eq(0)
}) })
...@@ -320,9 +319,8 @@ describe('Basic RPC tests', () => { ...@@ -320,9 +319,8 @@ describe('Basic RPC tests', () => {
} }
expect(errored).to.be.true expect(errored).to.be.true
const receipt: TransactionReceipt = await provider.getTransactionReceipt( const receipt: TransactionReceipt =
tx.hash await env.l2Provider.getTransactionReceipt(tx.hash)
)
expect(receipt.status).to.eq(0) expect(receipt.status).to.eq(0)
}) })
...@@ -354,7 +352,9 @@ describe('Basic RPC tests', () => { ...@@ -354,7 +352,9 @@ describe('Basic RPC tests', () => {
const res = await env.l2Wallet.sendTransaction(tx) const res = await env.l2Wallet.sendTransaction(tx)
await res.wait() await res.wait()
const json = await provider.send('eth_getTransactionReceipt', [res.hash]) const json = await env.l2Provider.send('eth_getTransactionReceipt', [
res.hash,
])
expect(l1GasUsed).to.deep.equal(BigNumber.from(json.l1GasUsed)) expect(l1GasUsed).to.deep.equal(BigNumber.from(json.l1GasUsed))
expect(l1GasPrice).to.deep.equal(BigNumber.from(json.l1GasPrice)) expect(l1GasPrice).to.deep.equal(BigNumber.from(json.l1GasPrice))
...@@ -370,7 +370,9 @@ describe('Basic RPC tests', () => { ...@@ -370,7 +370,9 @@ describe('Basic RPC tests', () => {
const result = await wallet.sendTransaction(tx) const result = await wallet.sendTransaction(tx)
await result.wait() await result.wait()
const transaction = (await provider.getTransaction(result.hash)) as any const transaction = (await env.l2Provider.getTransaction(
result.hash
)) as any
expect(transaction.queueOrigin).to.equal('sequencer') expect(transaction.queueOrigin).to.equal('sequencer')
expect(transaction.transactionIndex).to.be.eq(0) expect(transaction.transactionIndex).to.be.eq(0)
expect(transaction.gasLimit).to.be.deep.eq(BigNumber.from(tx.gasLimit)) expect(transaction.gasLimit).to.be.deep.eq(BigNumber.from(tx.gasLimit))
...@@ -385,7 +387,7 @@ describe('Basic RPC tests', () => { ...@@ -385,7 +387,7 @@ describe('Basic RPC tests', () => {
const result = await wallet.sendTransaction(tx) const result = await wallet.sendTransaction(tx)
const receipt = await result.wait() const receipt = await result.wait()
const block = (await provider.getBlockWithTransactions( const block = (await env.l2Provider.getBlockWithTransactions(
receipt.blockHash receipt.blockHash
)) as any )) as any
...@@ -411,13 +413,13 @@ describe('Basic RPC tests', () => { ...@@ -411,13 +413,13 @@ describe('Basic RPC tests', () => {
'should return the same result when new transactions are not applied', 'should return the same result when new transactions are not applied',
async () => { async () => {
// Get latest block once to start. // Get latest block once to start.
const prev = await provider.getBlockWithTransactions('latest') const prev = await env.l2Provider.getBlockWithTransactions('latest')
// set wait to null to allow a deep object comparison // set wait to null to allow a deep object comparison
prev.transactions[0].wait = null prev.transactions[0].wait = null
// Over ten seconds, repeatedly check the latest block to make sure nothing has changed. // Over ten seconds, repeatedly check the latest block to make sure nothing has changed.
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
const latest = await provider.getBlockWithTransactions('latest') const latest = await env.l2Provider.getBlockWithTransactions('latest')
latest.transactions[0].wait = null latest.transactions[0].wait = null
// Check each key of the transaction individually // Check each key of the transaction individually
// for easy debugging if one field changes // for easy debugging if one field changes
...@@ -436,7 +438,7 @@ describe('Basic RPC tests', () => { ...@@ -436,7 +438,7 @@ describe('Basic RPC tests', () => {
describe('eth_getBalance', () => { describe('eth_getBalance', () => {
it('should get the OVM_ETH balance', async () => { it('should get the OVM_ETH balance', async () => {
const rpcBalance = await provider.getBalance(env.l2Wallet.address) const rpcBalance = await env.l2Provider.getBalance(env.l2Wallet.address)
const contractBalance = await env.ovmEth.balanceOf(env.l2Wallet.address) const contractBalance = await env.ovmEth.balanceOf(env.l2Wallet.address)
expect(rpcBalance).to.be.deep.eq(contractBalance) expect(rpcBalance).to.be.deep.eq(contractBalance)
}) })
...@@ -444,7 +446,7 @@ describe('Basic RPC tests', () => { ...@@ -444,7 +446,7 @@ describe('Basic RPC tests', () => {
describe('eth_chainId', () => { describe('eth_chainId', () => {
it('should get the correct chainid', async () => { it('should get the correct chainid', async () => {
const { chainId } = await provider.getNetwork() const { chainId } = await env.l2Provider.getNetwork()
expect(chainId).to.be.eq(L2_CHAINID) expect(chainId).to.be.eq(L2_CHAINID)
}) })
}) })
...@@ -453,7 +455,7 @@ describe('Basic RPC tests', () => { ...@@ -453,7 +455,7 @@ describe('Basic RPC tests', () => {
it('simple send gas estimation is deterministic', async () => { it('simple send gas estimation is deterministic', async () => {
let lastEstimate: BigNumber let lastEstimate: BigNumber
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
const estimate = await l2Provider.estimateGas({ const estimate = await env.l2Provider.estimateGas({
to: defaultTransactionFactory().to, to: defaultTransactionFactory().to,
value: 0, value: 0,
}) })
...@@ -476,7 +478,7 @@ describe('Basic RPC tests', () => { ...@@ -476,7 +478,7 @@ describe('Basic RPC tests', () => {
}) })
it('should return a gas estimate for txs with empty data', async () => { it('should return a gas estimate for txs with empty data', async () => {
const estimate = await l2Provider.estimateGas({ const estimate = await env.l2Provider.estimateGas({
to: defaultTransactionFactory().to, to: defaultTransactionFactory().to,
value: 0, value: 0,
}) })
...@@ -485,13 +487,13 @@ describe('Basic RPC tests', () => { ...@@ -485,13 +487,13 @@ describe('Basic RPC tests', () => {
}) })
it('should fail for a reverting call transaction', async () => { it('should fail for a reverting call transaction', async () => {
await expect(provider.send('eth_estimateGas', [revertingTx])).to.be await expect(env.l2Provider.send('eth_estimateGas', [revertingTx])).to.be
.reverted .reverted
}) })
it('should fail for a reverting deploy transaction', async () => { it('should fail for a reverting deploy transaction', async () => {
await expect(provider.send('eth_estimateGas', [revertingDeployTx])).to.be await expect(env.l2Provider.send('eth_estimateGas', [revertingDeployTx]))
.reverted .to.be.reverted
}) })
}) })
...@@ -510,10 +512,10 @@ describe('Basic RPC tests', () => { ...@@ -510,10 +512,10 @@ describe('Basic RPC tests', () => {
const tx = (await storage.deploy()).deployTransaction const tx = (await storage.deploy()).deployTransaction
const receipt = await tx.wait() const receipt = await tx.wait()
const txTrace = await provider.send('debug_traceTransaction', [ const txTrace = await env.l2Provider.send('debug_traceTransaction', [
receipt.transactionHash, receipt.transactionHash,
]) ])
const blockTrace = await provider.send('debug_traceBlockByHash', [ const blockTrace = await env.l2Provider.send('debug_traceBlockByHash', [
receipt.blockHash, receipt.blockHash,
]) ])
expect(txTrace).to.deep.equal(blockTrace[0].result) expect(txTrace).to.deep.equal(blockTrace[0].result)
...@@ -522,7 +524,7 @@ describe('Basic RPC tests', () => { ...@@ -522,7 +524,7 @@ describe('Basic RPC tests', () => {
describe('rollup_gasPrices', () => { describe('rollup_gasPrices', () => {
it('should return the L1 and L2 gas prices', async () => { it('should return the L1 and L2 gas prices', async () => {
const result = await provider.send('rollup_gasPrices', []) const result = await env.l2Provider.send('rollup_gasPrices', [])
const l1GasPrice = await env.gasPriceOracle.l1BaseFee() const l1GasPrice = await env.gasPriceOracle.l1BaseFee()
const l2GasPrice = await env.gasPriceOracle.gasPrice() const l2GasPrice = await env.gasPriceOracle.gasPrice()
......
...@@ -6,7 +6,6 @@ import { predeploys } from '@eth-optimism/contracts' ...@@ -6,7 +6,6 @@ import { predeploys } from '@eth-optimism/contracts'
/* Imports: Internal */ /* Imports: Internal */
import { expect } from './shared/setup' import { expect } from './shared/setup'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { l2Provider } from './shared/utils'
describe('Whitelist', async () => { describe('Whitelist', async () => {
const initialAmount = 1000 const initialAmount = 1000
...@@ -24,7 +23,7 @@ describe('Whitelist', async () => { ...@@ -24,7 +23,7 @@ describe('Whitelist', async () => {
describe('when the whitelist is disabled', () => { describe('when the whitelist is disabled', () => {
it('should be able to deploy a contract', async () => { it('should be able to deploy a contract', async () => {
await expect( await expect(
l2Provider.send('eth_call', [ env.l2Provider.send('eth_call', [
Factory__ERC20.getDeployTransaction( Factory__ERC20.getDeployTransaction(
initialAmount, initialAmount,
tokenName, tokenName,
...@@ -50,7 +49,7 @@ describe('Whitelist', async () => { ...@@ -50,7 +49,7 @@ describe('Whitelist', async () => {
it('should fail if the user is not whitelisted', async () => { it('should fail if the user is not whitelisted', async () => {
await expect( await expect(
l2Provider.send('eth_call', [ env.l2Provider.send('eth_call', [
{ {
...Factory__ERC20.getDeployTransaction( ...Factory__ERC20.getDeployTransaction(
initialAmount, initialAmount,
...@@ -77,7 +76,7 @@ describe('Whitelist', async () => { ...@@ -77,7 +76,7 @@ describe('Whitelist', async () => {
it('should succeed if the user is whitelisted', async () => { it('should succeed if the user is whitelisted', async () => {
await expect( await expect(
l2Provider.send('eth_call', [ env.l2Provider.send('eth_call', [
{ {
...Factory__ERC20.getDeployTransaction( ...Factory__ERC20.getDeployTransaction(
initialAmount, initialAmount,
......
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