Commit 5e0a3285 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2199 from tonykogias/remove-contract-references-in-integration-tests

Remove unnecessary contract references in integration-tests
parents 8f5b1d81 a4198a4a
---
'@eth-optimism/integration-tests': patch
---
Replaces contract references in integration tests with SDK CrossChainMessenger objects.
...@@ -63,7 +63,10 @@ describe('Bridged tokens', () => { ...@@ -63,7 +63,10 @@ describe('Bridged tokens', () => {
await L2__ERC20.deployed() await L2__ERC20.deployed()
// Approve the L1 ERC20 to spend our money // Approve the L1 ERC20 to spend our money
const tx = await L1__ERC20.approve(env.l1Bridge.address, 1000000) const tx = await L1__ERC20.approve(
env.messenger.contracts.l1.L1StandardBridge.address,
1000000
)
await tx.wait() await tx.wait()
}) })
......
...@@ -5,13 +5,17 @@ import { predeploys, getContractFactory } from '@eth-optimism/contracts' ...@@ -5,13 +5,17 @@ import { predeploys, getContractFactory } from '@eth-optimism/contracts'
/* Imports: Internal */ /* Imports: Internal */
import { expect } from './shared/setup' import { expect } from './shared/setup'
import { hardhatTest } from './shared/utils' import { hardhatTest, gasPriceOracleWallet } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
const setPrices = async (env: OptimismEnv, value: number | BigNumber) => { const setPrices = async (env: OptimismEnv, value: number | BigNumber) => {
const gasPrice = await env.gasPriceOracle.setGasPrice(value) const gasPrice = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).setGasPrice(value)
await gasPrice.wait() await gasPrice.wait()
const baseFee = await env.gasPriceOracle.setL1BaseFee(value) const baseFee = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).setL1BaseFee(value)
await baseFee.wait() await baseFee.wait()
} }
...@@ -28,13 +32,18 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -28,13 +32,18 @@ describe('Fee Payment Integration Tests', async () => {
async () => { async () => {
const assertGasPrice = async () => { const assertGasPrice = async () => {
const gasPrice = await env.l2Wallet.getGasPrice() const gasPrice = await env.l2Wallet.getGasPrice()
const oracleGasPrice = await env.gasPriceOracle.gasPrice() const oracleGasPrice =
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).gasPrice()
expect(gasPrice).to.deep.equal(oracleGasPrice) expect(gasPrice).to.deep.equal(oracleGasPrice)
} }
await assertGasPrice() await assertGasPrice()
// update the gas price // update the gas price
const tx = await env.gasPriceOracle.setGasPrice(1000) const tx = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).setGasPrice(1000)
await tx.wait() await tx.wait()
await assertGasPrice() await assertGasPrice()
...@@ -47,7 +56,7 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -47,7 +56,7 @@ describe('Fee Payment Integration Tests', async () => {
const amount = utils.parseEther('0.0000001') const amount = utils.parseEther('0.0000001')
const balanceBefore = await env.l2Wallet.getBalance() const balanceBefore = await env.l2Wallet.getBalance()
const feeVaultBalanceBefore = await env.l2Wallet.provider.getBalance( const feeVaultBalanceBefore = await env.l2Wallet.provider.getBalance(
env.sequencerFeeVault.address env.messenger.contracts.l2.OVM_SequencerFeeVault.address
) )
expect(balanceBefore.gt(amount)) expect(balanceBefore.gt(amount))
...@@ -66,7 +75,9 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -66,7 +75,9 @@ describe('Fee Payment Integration Tests', async () => {
data: unsigned.data, data: unsigned.data,
}) })
const l1Fee = await env.gasPriceOracle.getL1Fee(raw) const l1Fee = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).getL1Fee(raw)
const tx = await env.l2Wallet.sendTransaction(unsigned) const tx = await env.l2Wallet.sendTransaction(unsigned)
const receipt = await tx.wait() const receipt = await tx.wait()
...@@ -74,7 +85,7 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -74,7 +85,7 @@ describe('Fee Payment Integration Tests', async () => {
const balanceAfter = await env.l2Wallet.getBalance() const balanceAfter = await env.l2Wallet.getBalance()
const feeVaultBalanceAfter = await env.l2Wallet.provider.getBalance( const feeVaultBalanceAfter = await env.l2Wallet.provider.getBalance(
env.sequencerFeeVault.address env.messenger.contracts.l2.OVM_SequencerFeeVault.address
) )
const l2Fee = receipt.gasUsed.mul(tx.gasPrice) const l2Fee = receipt.gasUsed.mul(tx.gasPrice)
...@@ -124,7 +135,9 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -124,7 +135,9 @@ describe('Fee Payment Integration Tests', async () => {
data: unsigned.data, data: unsigned.data,
}) })
const l1Fee = await OVM_GasPriceOracle.getL1Fee(raw) const l1Fee = await OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).getL1Fee(raw)
const tx = await env.l2Wallet.sendTransaction(unsigned) const tx = await env.l2Wallet.sendTransaction(unsigned)
const receipt = await tx.wait() const receipt = await tx.wait()
...@@ -142,30 +155,33 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -142,30 +155,33 @@ describe('Fee Payment Integration Tests', async () => {
}) })
it('should not be able to withdraw fees before the minimum is met', async () => { it('should not be able to withdraw fees before the minimum is met', async () => {
await expect(env.sequencerFeeVault.withdraw()).to.be.rejected await expect(env.messenger.contracts.l2.OVM_SequencerFeeVault.withdraw()).to
.be.rejected
}) })
hardhatTest( hardhatTest(
'should be able to withdraw fees back to L1 once the minimum is met', 'should be able to withdraw fees back to L1 once the minimum is met',
async () => { async () => {
const l1FeeWallet = await env.sequencerFeeVault.l1FeeWallet() const l1FeeWallet =
await env.messenger.contracts.l2.OVM_SequencerFeeVault.l1FeeWallet()
const balanceBefore = await env.l1Wallet.provider.getBalance(l1FeeWallet) const balanceBefore = await env.l1Wallet.provider.getBalance(l1FeeWallet)
const withdrawalAmount = const withdrawalAmount =
await env.sequencerFeeVault.MIN_WITHDRAWAL_AMOUNT() await env.messenger.contracts.l2.OVM_SequencerFeeVault.MIN_WITHDRAWAL_AMOUNT()
// Transfer the minimum required to withdraw. // Transfer the minimum required to withdraw.
const tx = await env.l2Wallet.sendTransaction({ const tx = await env.l2Wallet.sendTransaction({
to: env.sequencerFeeVault.address, to: env.messenger.contracts.l2.OVM_SequencerFeeVault.address,
value: withdrawalAmount, value: withdrawalAmount,
gasLimit: 500000, gasLimit: 500000,
}) })
await tx.wait() await tx.wait()
const vaultBalance = await env.ovmEth.balanceOf( const vaultBalance = await env.messenger.contracts.l2.OVM_ETH.balanceOf(
env.sequencerFeeVault.address env.messenger.contracts.l2.OVM_SequencerFeeVault.address
) )
const withdrawTx = await env.sequencerFeeVault.withdraw() const withdrawTx =
await env.messenger.contracts.l2.OVM_SequencerFeeVault.withdraw()
// Wait for the withdrawal to be relayed to L1. // Wait for the withdrawal to be relayed to L1.
await withdrawTx.wait() await withdrawTx.wait()
......
...@@ -123,8 +123,10 @@ describe('Native ETH value integration tests', () => { ...@@ -123,8 +123,10 @@ describe('Native ETH value integration tests', () => {
'geth RPC does not match ovmSELFBALANCE' 'geth RPC does not match ovmSELFBALANCE'
) )
// query ovmSELFBALANCE() opcode via eth_call as another check // query ovmSELFBALANCE() opcode via eth_call as another check
const ovmEthBalanceOf0 = await env.ovmEth.balanceOf(ValueCalls0.address) const ovmEthBalanceOf0 =
const ovmEthBalanceOf1 = await env.ovmEth.balanceOf(ValueCalls1.address) await env.messenger.contracts.l2.OVM_ETH.balanceOf(ValueCalls0.address)
const ovmEthBalanceOf1 =
await env.messenger.contracts.l2.OVM_ETH.balanceOf(ValueCalls1.address)
expect(ovmEthBalanceOf0).to.deep.eq( expect(ovmEthBalanceOf0).to.deep.eq(
BigNumber.from(expectedBalances[0]), BigNumber.from(expectedBalances[0]),
'geth RPC does not match OVM_ETH.balanceOf' 'geth RPC does not match OVM_ETH.balanceOf'
......
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
DEFAULT_TEST_GAS_L2, DEFAULT_TEST_GAS_L2,
envConfig, envConfig,
withdrawalTest, withdrawalTest,
gasPriceOracleWallet,
} from './shared/utils' } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
...@@ -30,7 +31,7 @@ describe('Native ETH Integration Tests', async () => { ...@@ -30,7 +31,7 @@ describe('Native ETH Integration Tests', async () => {
const l2BobBalance = await l2Bob.getBalance() const l2BobBalance = await l2Bob.getBalance()
const l1BridgeBalance = await _env.l1Wallet.provider.getBalance( const l1BridgeBalance = await _env.l1Wallet.provider.getBalance(
_env.l1Bridge.address _env.messenger.contracts.l1.L1StandardBridge.address
) )
return { return {
...@@ -51,12 +52,13 @@ describe('Native ETH Integration Tests', async () => { ...@@ -51,12 +52,13 @@ describe('Native ETH Integration Tests', async () => {
describe('estimateGas', () => { describe('estimateGas', () => {
it('Should estimate gas for ETH withdraw', async () => { it('Should estimate gas for ETH withdraw', async () => {
const amount = utils.parseEther('0.0000001') const amount = utils.parseEther('0.0000001')
const gas = await env.l2Bridge.estimateGas.withdraw( const gas =
predeploys.OVM_ETH, await env.messenger.contracts.l2.L2StandardBridge.estimateGas.withdraw(
amount, predeploys.OVM_ETH,
0, amount,
'0xFFFF' 0,
) '0xFFFF'
)
// Expect gas to be less than or equal to the target plus 1% // Expect gas to be less than or equal to the target plus 1%
expectApprox(gas, 6700060, { absoluteUpperDeviation: 1000 }) expectApprox(gas, 6700060, { absoluteUpperDeviation: 1000 })
}) })
...@@ -67,7 +69,7 @@ describe('Native ETH Integration Tests', async () => { ...@@ -67,7 +69,7 @@ describe('Native ETH Integration Tests', async () => {
const preBalances = await getBalances(env) const preBalances = await getBalances(env)
const { tx, receipt } = await env.waitForXDomainTransaction( const { tx, receipt } = await env.waitForXDomainTransaction(
env.l1Wallet.sendTransaction({ env.l1Wallet.sendTransaction({
to: env.l1Bridge.address, to: env.messenger.contracts.l1.L1StandardBridge.address,
value: depositAmount, value: depositAmount,
gasLimit: DEFAULT_TEST_GAS_L1, gasLimit: DEFAULT_TEST_GAS_L1,
}) })
...@@ -91,10 +93,14 @@ describe('Native ETH Integration Tests', async () => { ...@@ -91,10 +93,14 @@ describe('Native ETH Integration Tests', async () => {
const depositAmount = 10 const depositAmount = 10
const preBalances = await getBalances(env) const preBalances = await getBalances(env)
const { tx, receipt } = await env.waitForXDomainTransaction( const { tx, receipt } = await env.waitForXDomainTransaction(
env.l1Bridge.depositETH(DEFAULT_TEST_GAS_L2, '0xFFFF', { env.messenger.contracts.l1.L1StandardBridge.depositETH(
value: depositAmount, DEFAULT_TEST_GAS_L2,
gasLimit: DEFAULT_TEST_GAS_L1, '0xFFFF',
}) {
value: depositAmount,
gasLimit: DEFAULT_TEST_GAS_L1,
}
)
) )
const l1FeePaid = receipt.gasUsed.mul(tx.gasPrice) const l1FeePaid = receipt.gasUsed.mul(tx.gasPrice)
...@@ -115,10 +121,15 @@ describe('Native ETH Integration Tests', async () => { ...@@ -115,10 +121,15 @@ describe('Native ETH Integration Tests', async () => {
const depositAmount = 10 const depositAmount = 10
const preBalances = await getBalances(env) const preBalances = await getBalances(env)
const depositReceipts = await env.waitForXDomainTransaction( const depositReceipts = await env.waitForXDomainTransaction(
env.l1Bridge.depositETHTo(l2Bob.address, DEFAULT_TEST_GAS_L2, '0xFFFF', { env.messenger.contracts.l1.L1StandardBridge.depositETHTo(
value: depositAmount, l2Bob.address,
gasLimit: DEFAULT_TEST_GAS_L1, DEFAULT_TEST_GAS_L2,
}) '0xFFFF',
{
value: depositAmount,
gasLimit: DEFAULT_TEST_GAS_L1,
}
)
) )
const l1FeePaid = depositReceipts.receipt.gasUsed.mul( const l1FeePaid = depositReceipts.receipt.gasUsed.mul(
...@@ -145,10 +156,14 @@ describe('Native ETH Integration Tests', async () => { ...@@ -145,10 +156,14 @@ describe('Native ETH Integration Tests', async () => {
// to allow for encoding and other arguments // to allow for encoding and other arguments
const data = `0x` + 'ab'.repeat(MAX_ROLLUP_TX_SIZE - 500) const data = `0x` + 'ab'.repeat(MAX_ROLLUP_TX_SIZE - 500)
const { tx, receipt } = await env.waitForXDomainTransaction( const { tx, receipt } = await env.waitForXDomainTransaction(
env.l1Bridge.depositETH(ASSUMED_L2_GAS_LIMIT, data, { env.messenger.contracts.l1.L1StandardBridge.depositETH(
value: depositAmount, ASSUMED_L2_GAS_LIMIT,
gasLimit: 4_000_000, data,
}) {
value: depositAmount,
gasLimit: 4_000_000,
}
)
) )
const l1FeePaid = receipt.gasUsed.mul(tx.gasPrice) const l1FeePaid = receipt.gasUsed.mul(tx.gasPrice)
...@@ -169,9 +184,13 @@ describe('Native ETH Integration Tests', async () => { ...@@ -169,9 +184,13 @@ describe('Native ETH Integration Tests', async () => {
const data = `0x` + 'ab'.repeat(MAX_ROLLUP_TX_SIZE + 1) const data = `0x` + 'ab'.repeat(MAX_ROLLUP_TX_SIZE + 1)
await expect( await expect(
env.l1Bridge.depositETH(DEFAULT_TEST_GAS_L2, data, { env.messenger.contracts.l1.L1StandardBridge.depositETH(
value: depositAmount, DEFAULT_TEST_GAS_L2,
}) data,
{
value: depositAmount,
}
)
).to.be.reverted ).to.be.reverted
}) })
...@@ -183,12 +202,13 @@ describe('Native ETH Integration Tests', async () => { ...@@ -183,12 +202,13 @@ describe('Native ETH Integration Tests', async () => {
'Cannot run withdrawal test before any deposits...' 'Cannot run withdrawal test before any deposits...'
) )
const transaction = await env.l2Bridge.withdraw( const transaction =
predeploys.OVM_ETH, await env.messenger.contracts.l2.L2StandardBridge.withdraw(
withdrawAmount, predeploys.OVM_ETH,
DEFAULT_TEST_GAS_L2, withdrawAmount,
'0xFFFF' DEFAULT_TEST_GAS_L2,
) '0xFFFF'
)
await transaction.wait() await transaction.wait()
await env.relayXDomainMessages(transaction) await env.relayXDomainMessages(transaction)
const receipts = await env.waitForXDomainTransaction(transaction) const receipts = await env.waitForXDomainTransaction(transaction)
...@@ -224,13 +244,14 @@ describe('Native ETH Integration Tests', async () => { ...@@ -224,13 +244,14 @@ describe('Native ETH Integration Tests', async () => {
'Cannot run withdrawal test before any deposits...' 'Cannot run withdrawal test before any deposits...'
) )
const transaction = await env.l2Bridge.withdrawTo( const transaction =
predeploys.OVM_ETH, await env.messenger.contracts.l2.L2StandardBridge.withdrawTo(
l1Bob.address, predeploys.OVM_ETH,
withdrawAmount, l1Bob.address,
DEFAULT_TEST_GAS_L2, withdrawAmount,
'0xFFFF' DEFAULT_TEST_GAS_L2,
) '0xFFFF'
)
await transaction.wait() await transaction.wait()
await env.relayXDomainMessages(transaction) await env.relayXDomainMessages(transaction)
...@@ -248,7 +269,9 @@ describe('Native ETH Integration Tests', async () => { ...@@ -248,7 +269,9 @@ describe('Native ETH Integration Tests', async () => {
data: transaction.data, data: transaction.data,
}) })
const l1Fee = await env.gasPriceOracle.getL1Fee(raw) const l1Fee = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).getL1Fee(raw)
const fee = l2Fee.add(l1Fee) const fee = l2Fee.add(l1Fee)
const postBalances = await getBalances(env) const postBalances = await getBalances(env)
...@@ -275,10 +298,14 @@ describe('Native ETH Integration Tests', async () => { ...@@ -275,10 +298,14 @@ describe('Native ETH Integration Tests', async () => {
// 1. deposit // 1. deposit
const amount = utils.parseEther('1') const amount = utils.parseEther('1')
await env.waitForXDomainTransaction( await env.waitForXDomainTransaction(
env.l1Bridge.depositETH(DEFAULT_TEST_GAS_L2, '0xFFFF', { env.messenger.contracts.l1.L1StandardBridge.depositETH(
value: amount, DEFAULT_TEST_GAS_L2,
gasLimit: DEFAULT_TEST_GAS_L1, '0xFFFF',
}) {
value: amount,
gasLimit: DEFAULT_TEST_GAS_L1,
}
)
) )
// 2. transfer to another address // 2. transfer to another address
...@@ -295,9 +322,10 @@ describe('Native ETH Integration Tests', async () => { ...@@ -295,9 +322,10 @@ describe('Native ETH Integration Tests', async () => {
// 3. do withdrawal // 3. do withdrawal
const withdrawnAmount = utils.parseEther('0.95') const withdrawnAmount = utils.parseEther('0.95')
const transaction = await env.l2Bridge const transaction =
.connect(other) await env.messenger.contracts.l2.L2StandardBridge.connect(
.withdraw( other
).withdraw(
predeploys.OVM_ETH, predeploys.OVM_ETH,
withdrawnAmount, withdrawnAmount,
DEFAULT_TEST_GAS_L1, DEFAULT_TEST_GAS_L1,
...@@ -308,16 +336,19 @@ describe('Native ETH Integration Tests', async () => { ...@@ -308,16 +336,19 @@ describe('Native ETH Integration Tests', async () => {
const receipts = await env.waitForXDomainTransaction(transaction) const receipts = await env.waitForXDomainTransaction(transaction)
// Compute the L1 portion of the fee // Compute the L1 portion of the fee
const l1Fee = await env.gasPriceOracle.getL1Fee( const l1Fee =
serialize({ await await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
nonce: transaction.nonce, gasPriceOracleWallet
value: transaction.value, ).getL1Fee(
gasPrice: transaction.gasPrice, serialize({
gasLimit: transaction.gasLimit, nonce: transaction.nonce,
to: transaction.to, value: transaction.value,
data: transaction.data, gasPrice: transaction.gasPrice,
}) gasLimit: transaction.gasLimit,
) to: transaction.to,
data: transaction.data,
})
)
// check that correct amount was withdrawn and that fee was charged // check that correct amount was withdrawn and that fee was charged
const l2Fee = receipts.tx.gasPrice.mul(receipts.receipt.gasUsed) const l2Fee = receipts.tx.gasPrice.mul(receipts.receipt.gasUsed)
......
...@@ -44,14 +44,15 @@ describe('OVM Context: Layer 2 EVM Context', () => { ...@@ -44,14 +44,15 @@ describe('OVM Context: Layer 2 EVM Context', () => {
for (let i = 0; i < numTxs; i++) { for (let i = 0; i < numTxs; i++) {
// Send a transaction from L1 to L2. This will automatically update the L1 contextual // Send a transaction from L1 to L2. This will automatically update the L1 contextual
// information like the L1 block number and L1 timestamp. // information like the L1 block number and L1 timestamp.
const tx = await env.l1Messenger.sendMessage( const tx =
OVMContextStorage.address, await env.messenger.contracts.l1.L1CrossDomainMessenger.sendMessage(
'0x', OVMContextStorage.address,
2_000_000, '0x',
{ 2_000_000,
gasLimit: DEFAULT_TEST_GAS_L1, {
} gasLimit: DEFAULT_TEST_GAS_L1,
) }
)
// Wait for the transaction to be sent over to L2. // Wait for the transaction to be sent over to L2.
await tx.wait() await tx.wait()
......
...@@ -26,14 +26,15 @@ describe('Queue Ingestion', () => { ...@@ -26,14 +26,15 @@ describe('Queue Ingestion', () => {
// the transaction to Layer 1 // the transaction to Layer 1
const txs = [] const txs = []
for (let i = 0; i < numTxs; i++) { for (let i = 0; i < numTxs; i++) {
const tx = await env.l1Messenger.sendMessage( const tx =
`0x${`${i}`.repeat(40)}`, await env.messenger.contracts.l1.L1CrossDomainMessenger.sendMessage(
`0x0${i}`, `0x${`${i}`.repeat(40)}`,
1_000_000, `0x0${i}`,
{ 1_000_000,
gasLimit: DEFAULT_TEST_GAS_L1, {
} gasLimit: DEFAULT_TEST_GAS_L1,
) }
)
await tx.wait() await tx.wait()
txs.push(tx) txs.push(tx)
} }
...@@ -46,10 +47,11 @@ describe('Queue Ingestion', () => { ...@@ -46,10 +47,11 @@ describe('Queue Ingestion', () => {
receipt.remoteTx.hash receipt.remoteTx.hash
)) as any )) as any
const params = env.l2Messenger.interface.decodeFunctionData( const params =
'relayMessage', env.messenger.contracts.l2.L2CrossDomainMessenger.interface.decodeFunctionData(
l2Tx.data 'relayMessage',
) l2Tx.data
)
expect(params._sender.toLowerCase()).to.equal( expect(params._sender.toLowerCase()).to.equal(
env.l1Wallet.address.toLowerCase() env.l1Wallet.address.toLowerCase()
...@@ -57,7 +59,9 @@ describe('Queue Ingestion', () => { ...@@ -57,7 +59,9 @@ describe('Queue Ingestion', () => {
expect(params._target).to.equal('0x' + `${i}`.repeat(40)) expect(params._target).to.equal('0x' + `${i}`.repeat(40))
expect(l2Tx.queueOrigin).to.equal('l1') expect(l2Tx.queueOrigin).to.equal('l1')
expect(l2Tx.l1TxOrigin.toLowerCase()).to.equal( expect(l2Tx.l1TxOrigin.toLowerCase()).to.equal(
applyL1ToL2Alias(env.l1Messenger.address).toLowerCase() applyL1ToL2Alias(
env.messenger.contracts.l1.L1CrossDomainMessenger.address
).toLowerCase()
) )
expect(l2Tx.l1BlockNumber).to.equal(l1TxReceipt.blockNumber) expect(l2Tx.l1BlockNumber).to.equal(l1TxReceipt.blockNumber)
} }
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
isHardhat, isHardhat,
hardhatTest, hardhatTest,
envConfig, envConfig,
gasPriceOracleWallet,
} from './shared/utils' } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
...@@ -149,8 +150,12 @@ describe('Basic RPC tests', () => { ...@@ -149,8 +150,12 @@ describe('Basic RPC tests', () => {
const isHH = await isHardhat() const isHH = await isHardhat()
let gasPrice let gasPrice
if (isHH) { if (isHH) {
gasPrice = await env.gasPriceOracle.gasPrice() gasPrice = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
await env.gasPriceOracle.setGasPrice(1000) gasPriceOracleWallet
).gasPrice()
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).setGasPrice(1000)
} }
const tx = { const tx = {
...@@ -164,12 +169,17 @@ describe('Basic RPC tests', () => { ...@@ -164,12 +169,17 @@ describe('Basic RPC tests', () => {
if (isHH) { if (isHH) {
// Reset the gas price to its original price // Reset the gas price to its original price
await env.gasPriceOracle.setGasPrice(gasPrice) await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).setGasPrice(gasPrice)
} }
}) })
it('should reject a transaction with too high of a fee', async () => { it('should reject a transaction with too high of a fee', async () => {
const gasPrice = await env.gasPriceOracle.gasPrice() const gasPrice =
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).gasPrice()
const largeGasPrice = gasPrice.mul(10) const largeGasPrice = gasPrice.mul(10)
const tx = { const tx = {
...defaultTransactionFactory(), ...defaultTransactionFactory(),
...@@ -341,11 +351,25 @@ describe('Basic RPC tests', () => { ...@@ -341,11 +351,25 @@ describe('Basic RPC tests', () => {
data: tx.data, data: tx.data,
}) })
const l1Fee = await env.gasPriceOracle.getL1Fee(raw) const l1Fee = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
const l1GasPrice = await env.gasPriceOracle.l1BaseFee() gasPriceOracleWallet
const l1GasUsed = await env.gasPriceOracle.getL1GasUsed(raw) ).getL1Fee(raw)
const scalar = await env.gasPriceOracle.scalar() const l1GasPrice =
const decimals = await env.gasPriceOracle.decimals() await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).l1BaseFee()
const l1GasUsed =
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).getL1GasUsed(raw)
const scalar =
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).scalar()
const decimals =
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).decimals()
const scaled = scalar.toNumber() / 10 ** decimals.toNumber() const scaled = scalar.toNumber() / 10 ** decimals.toNumber()
...@@ -439,7 +463,8 @@ describe('Basic RPC tests', () => { ...@@ -439,7 +463,8 @@ 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 env.l2Provider.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.messenger.contracts.l2.OVM_ETH.balanceOf(env.l2Wallet.address)
expect(rpcBalance).to.be.deep.eq(contractBalance) expect(rpcBalance).to.be.deep.eq(contractBalance)
}) })
}) })
...@@ -525,9 +550,14 @@ describe('Basic RPC tests', () => { ...@@ -525,9 +550,14 @@ 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 env.l2Provider.send('rollup_gasPrices', []) const result = await env.l2Provider.send('rollup_gasPrices', [])
const l1GasPrice = await env.gasPriceOracle.l1BaseFee() const l1GasPrice =
const l2GasPrice = await env.gasPriceOracle.gasPrice() await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).l1BaseFee()
const l2GasPrice =
await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
gasPriceOracleWallet
).gasPrice()
expect(BigNumber.from(result.l1GasPrice)).to.deep.eq(l1GasPrice) expect(BigNumber.from(result.l1GasPrice)).to.deep.eq(l1GasPrice)
expect(BigNumber.from(result.l2GasPrice)).to.deep.eq(l2GasPrice) expect(BigNumber.from(result.l2GasPrice)).to.deep.eq(l2GasPrice)
}) })
......
/* Imports: External */ /* Imports: External */
import { Contract, utils, Wallet, providers, Transaction } from 'ethers' import { utils, Wallet, providers, Transaction } from 'ethers'
import { import {
TransactionResponse, TransactionResponse,
TransactionReceipt, TransactionReceipt,
} from '@ethersproject/providers' } from '@ethersproject/providers'
import { getContractFactory, predeploys } from '@eth-optimism/contracts'
import { sleep } from '@eth-optimism/core-utils' import { sleep } from '@eth-optimism/core-utils'
import { import {
CrossChainMessenger, CrossChainMessenger,
...@@ -14,18 +13,13 @@ import { ...@@ -14,18 +13,13 @@ import {
/* Imports: Internal */ /* Imports: Internal */
import { import {
getAddressManager,
l1Provider, l1Provider,
l2Provider, l2Provider,
replicaProvider, replicaProvider,
verifierProvider, verifierProvider,
l1Wallet, l1Wallet,
l2Wallet, l2Wallet,
gasPriceOracleWallet,
fundUser, fundUser,
getOvmEth,
getL1Bridge,
getL2Bridge,
envConfig, envConfig,
} from './utils' } from './utils'
...@@ -38,21 +32,6 @@ export interface CrossDomainMessagePair { ...@@ -38,21 +32,6 @@ export interface CrossDomainMessagePair {
/// Helper class for instantiating a test environment with a funded account /// Helper class for instantiating a test environment with a funded account
export class OptimismEnv { export class OptimismEnv {
// L1 Contracts
addressManager: Contract
l1Bridge: Contract
l1Messenger: Contract
l1BlockNumber: Contract
ctc: Contract
scc: Contract
// L2 Contracts
ovmEth: Contract
l2Bridge: Contract
l2Messenger: Contract
gasPriceOracle: Contract
sequencerFeeVault: Contract
// The wallets // The wallets
l1Wallet: Wallet l1Wallet: Wallet
l2Wallet: Wallet l2Wallet: Wallet
...@@ -65,15 +44,6 @@ export class OptimismEnv { ...@@ -65,15 +44,6 @@ export class OptimismEnv {
verifierProvider: providers.JsonRpcProvider verifierProvider: providers.JsonRpcProvider
constructor(args: any) { constructor(args: any) {
this.addressManager = args.addressManager
this.l1Bridge = args.l1Bridge
this.l1Messenger = args.l1Messenger
this.l1BlockNumber = args.l1BlockNumber
this.ovmEth = args.ovmEth
this.l2Bridge = args.l2Bridge
this.l2Messenger = args.l2Messenger
this.gasPriceOracle = args.gasPriceOracle
this.sequencerFeeVault = args.sequencerFeeVault
this.l1Wallet = args.l1Wallet this.l1Wallet = args.l1Wallet
this.l2Wallet = args.l2Wallet this.l2Wallet = args.l2Wallet
this.messenger = args.messenger this.messenger = args.messenger
...@@ -81,68 +51,15 @@ export class OptimismEnv { ...@@ -81,68 +51,15 @@ export class OptimismEnv {
this.l2Provider = args.l2Provider this.l2Provider = args.l2Provider
this.replicaProvider = args.replicaProvider this.replicaProvider = args.replicaProvider
this.verifierProvider = args.verifierProvider this.verifierProvider = args.verifierProvider
this.ctc = args.ctc
this.scc = args.scc
} }
static async new(): Promise<OptimismEnv> { static async new(): Promise<OptimismEnv> {
const network = await l1Provider.getNetwork() const network = await l1Provider.getNetwork()
const addressManager = getAddressManager(l1Wallet)
const l1Bridge = await getL1Bridge(l1Wallet, addressManager)
const l1MessengerAddress = await addressManager.getAddress(
'Proxy__OVM_L1CrossDomainMessenger'
)
const l2MessengerAddress = await addressManager.getAddress(
'L2CrossDomainMessenger'
)
const l1Messenger = getContractFactory('L1CrossDomainMessenger')
.connect(l1Wallet)
.attach(l1MessengerAddress)
const ovmEth = getOvmEth(l2Wallet)
const l2Bridge = await getL2Bridge(l2Wallet)
const l2Messenger = getContractFactory('L2CrossDomainMessenger')
.connect(l2Wallet)
.attach(l2MessengerAddress)
const ctcAddress = await addressManager.getAddress(
'CanonicalTransactionChain'
)
const ctc = getContractFactory('CanonicalTransactionChain')
.connect(l1Wallet)
.attach(ctcAddress)
const gasPriceOracle = getContractFactory('OVM_GasPriceOracle')
.connect(gasPriceOracleWallet)
.attach(predeploys.OVM_GasPriceOracle)
const sccAddress = await addressManager.getAddress('StateCommitmentChain')
const scc = getContractFactory('StateCommitmentChain')
.connect(l1Wallet)
.attach(sccAddress)
const sequencerFeeVault = getContractFactory('OVM_SequencerFeeVault')
.connect(l2Wallet)
.attach(predeploys.OVM_SequencerFeeVault)
const l1BlockNumber = getContractFactory('iOVM_L1BlockNumber')
.connect(l2Wallet)
.attach(predeploys.OVM_L1BlockNumber)
const messenger = new CrossChainMessenger({ const messenger = new CrossChainMessenger({
l1SignerOrProvider: l1Wallet, l1SignerOrProvider: l1Wallet,
l2SignerOrProvider: l2Wallet, l2SignerOrProvider: l2Wallet,
l1ChainId: network.chainId, l1ChainId: network.chainId,
contracts: {
l1: {
AddressManager: envConfig.ADDRESS_MANAGER,
L1CrossDomainMessenger: l1Messenger.address,
L1StandardBridge: l1Bridge.address,
StateCommitmentChain: sccAddress,
CanonicalTransactionChain: ctcAddress,
BondManager: await addressManager.getAddress('BondManager'),
},
},
}) })
// fund the user if needed // fund the user if needed
...@@ -154,17 +71,6 @@ export class OptimismEnv { ...@@ -154,17 +71,6 @@ export class OptimismEnv {
} }
return new OptimismEnv({ return new OptimismEnv({
addressManager,
l1Bridge,
ctc,
scc,
l1Messenger,
l1BlockNumber,
ovmEth,
gasPriceOracle,
sequencerFeeVault,
l2Bridge,
l2Messenger,
l1Wallet, l1Wallet,
l2Wallet, l2Wallet,
messenger, messenger,
......
...@@ -37,19 +37,19 @@ export const executeL1ToL2Transaction = async ( ...@@ -37,19 +37,19 @@ export const executeL1ToL2Transaction = async (
) => { ) => {
const signer = wallet.connect(env.l1Wallet.provider) const signer = wallet.connect(env.l1Wallet.provider)
const receipt = await retryOnNonceError(async () => const receipt = await retryOnNonceError(async () =>
env.l1Messenger env.messenger.contracts.l1.L1CrossDomainMessenger.connect(
.connect(signer) signer
.sendMessage( ).sendMessage(
tx.contract.address, tx.contract.address,
tx.contract.interface.encodeFunctionData( tx.contract.interface.encodeFunctionData(
tx.functionName, tx.functionName,
tx.functionParams tx.functionParams
), ),
MESSAGE_GAS, MESSAGE_GAS,
{ {
gasPrice: await gasPriceForL1(), gasPrice: await gasPriceForL1(),
} }
) )
) )
await env.waitForXDomainTransaction(receipt) await env.waitForXDomainTransaction(receipt)
} }
...@@ -61,19 +61,19 @@ export const executeL2ToL1Transaction = async ( ...@@ -61,19 +61,19 @@ export const executeL2ToL1Transaction = async (
) => { ) => {
const signer = wallet.connect(env.l2Wallet.provider) const signer = wallet.connect(env.l2Wallet.provider)
const receipt = await retryOnNonceError(() => const receipt = await retryOnNonceError(() =>
env.l2Messenger env.messenger.contracts.l2.L2CrossDomainMessenger.connect(
.connect(signer) signer
.sendMessage( ).sendMessage(
tx.contract.address, tx.contract.address,
tx.contract.interface.encodeFunctionData( tx.contract.interface.encodeFunctionData(
tx.functionName, tx.functionName,
tx.functionParams tx.functionParams
), ),
MESSAGE_GAS, MESSAGE_GAS,
{ {
gasPrice: gasPriceForL2(), gasPrice: gasPriceForL2(),
} }
) )
) )
await env.relayXDomainMessages(receipt) await env.relayXDomainMessages(receipt)
......
/* Imports: External */ /* Imports: External */
import { import { Wallet, providers, BigNumber, utils } from 'ethers'
Contract, import { predeploys } from '@eth-optimism/contracts'
Wallet,
constants,
providers,
BigNumber,
utils,
} from 'ethers'
import {
getContractFactory,
getContractInterface,
predeploys,
} from '@eth-optimism/contracts'
import { remove0x } from '@eth-optimism/core-utils' import { remove0x } from '@eth-optimism/core-utils'
import { import {
CrossChainMessenger, CrossChainMessenger,
...@@ -71,9 +60,6 @@ const procEnv = cleanEnv(process.env, { ...@@ -71,9 +60,6 @@ const procEnv = cleanEnv(process.env, {
default: default:
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
}), }),
ADDRESS_MANAGER: str({
default: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
}),
GAS_PRICE_ORACLE_PRIVATE_KEY: str({ GAS_PRICE_ORACLE_PRIVATE_KEY: str({
default: default:
'0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba', '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba',
...@@ -152,39 +138,6 @@ export const OVM_ETH_ADDRESS = predeploys.OVM_ETH ...@@ -152,39 +138,6 @@ export const OVM_ETH_ADDRESS = predeploys.OVM_ETH
export const L2_CHAINID = procEnv.L2_CHAINID export const L2_CHAINID = procEnv.L2_CHAINID
export const getAddressManager = (provider: any) => {
return getContractFactory('Lib_AddressManager')
.connect(provider)
.attach(procEnv.ADDRESS_MANAGER)
}
// Gets the bridge contract
export const getL1Bridge = async (wallet: Wallet, AddressManager: Contract) => {
const l1BridgeInterface = getContractInterface('L1StandardBridge')
const ProxyBridgeAddress = await AddressManager.getAddress(
'Proxy__OVM_L1StandardBridge'
)
if (
!utils.isAddress(ProxyBridgeAddress) ||
ProxyBridgeAddress === constants.AddressZero
) {
throw new Error('Proxy__OVM_L1StandardBridge not found')
}
return new Contract(ProxyBridgeAddress, l1BridgeInterface, wallet)
}
export const getL2Bridge = async (wallet: Wallet) => {
const L2BridgeInterface = getContractInterface('L2StandardBridge')
return new Contract(predeploys.L2StandardBridge, L2BridgeInterface, wallet)
}
export const getOvmEth = (wallet: Wallet) => {
return new Contract(OVM_ETH_ADDRESS, getContractInterface('OVM_ETH'), wallet)
}
export const fundUser = async ( export const fundUser = async (
messenger: CrossChainMessenger, messenger: CrossChainMessenger,
amount: NumberLike, amount: NumberLike,
......
...@@ -210,17 +210,19 @@ describe('stress tests', () => { ...@@ -210,17 +210,19 @@ describe('stress tests', () => {
const tip = await env.l2Provider.getBlock('latest') const tip = await env.l2Provider.getBlock('latest')
const prev = { const prev = {
block: await env.l2Provider.getBlock(0), block: await env.l2Provider.getBlock(0),
l1BlockNumber: await env.l1BlockNumber.getL1BlockNumber({ l1BlockNumber:
blockTag: 0, await env.messenger.contracts.l2.OVM_L1BlockNumber.getL1BlockNumber({
}), blockTag: 0,
}),
} }
for (let i = 1; i < tip.number; i++) { for (let i = 1; i < tip.number; i++) {
const block = await env.l2Provider.getBlock(i) const block = await env.l2Provider.getBlock(i)
expect(block.timestamp).to.be.gte(prev.block.timestamp) expect(block.timestamp).to.be.gte(prev.block.timestamp)
const l1BlockNumber = await env.l1BlockNumber.getL1BlockNumber({ const l1BlockNumber =
blockTag: i, await env.messenger.contracts.l2.OVM_L1BlockNumber.getL1BlockNumber({
}) blockTag: i,
})
expect(l1BlockNumber.gt(prev.l1BlockNumber)) expect(l1BlockNumber.gt(prev.l1BlockNumber))
prev.block = block prev.block = block
......
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