Commit f86b7df4 authored by Mark Tyneway's avatar Mark Tyneway

integration-tests: cover fee too low/high cases

Updates the integration tests to work when fees
are enforced by the sequencer. This allows for
integration test coverage of the cases where transactions
are rejected when fees are too low or too high.
parent 05e01a00
...@@ -8,7 +8,7 @@ import { serialize } from '@ethersproject/transactions' ...@@ -8,7 +8,7 @@ import { serialize } from '@ethersproject/transactions'
import { predeploys, getContractFactory } from '@eth-optimism/contracts' import { predeploys, getContractFactory } from '@eth-optimism/contracts'
/* Imports: Internal */ /* Imports: Internal */
import { gasPriceForL2, isLiveNetwork } from './shared/utils' import { isLiveNetwork } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { Direction } from './shared/watcher-utils' import { Direction } from './shared/watcher-utils'
...@@ -173,10 +173,7 @@ describe('Fee Payment Integration Tests', async () => { ...@@ -173,10 +173,7 @@ describe('Fee Payment Integration Tests', async () => {
env.sequencerFeeVault.address env.sequencerFeeVault.address
) )
// Submit the withdrawal. const withdrawTx = await env.sequencerFeeVault.withdraw()
const withdrawTx = await env.sequencerFeeVault.withdraw({
gasPrice: await gasPriceForL2(env), // Will be zero on HH
})
// Wait for the withdrawal to be relayed to L1. // Wait for the withdrawal to be relayed to L1.
await withdrawTx.wait() await withdrawTx.wait()
......
...@@ -140,6 +140,45 @@ describe('Basic RPC tests', () => { ...@@ -140,6 +140,45 @@ describe('Basic RPC tests', () => {
'gas required exceeds allowance' 'gas required exceeds allowance'
) )
}) })
it('should reject a transaction with too low of a fee', async () => {
if (isLiveNetwork()) {
console.log('Skipping too low of a fee test on live network')
return
}
const gasPrice = await env.gasPriceOracle.gasPrice()
await env.gasPriceOracle.setGasPrice(1000)
const tx = {
...defaultTransactionFactory(),
gasPrice: 1,
}
await expect(env.l2Wallet.sendTransaction(tx)).to.be.rejectedWith(
`gas price too low: 1 wei, use at least tx.gasPrice = 1000 wei`
)
// Reset the gas price to its original price
await env.gasPriceOracle.setGasPrice(gasPrice)
})
it('should reject a transaction with too high of a fee', async () => {
if (isLiveNetwork()) {
console.log('Skpping too high of a fee test on live network')
return
}
const gasPrice = await env.gasPriceOracle.gasPrice()
const largeGasPrice = gasPrice.mul(10)
const tx = {
...defaultTransactionFactory(),
gasPrice: largeGasPrice,
}
await expect(env.l2Wallet.sendTransaction(tx)).to.be.rejectedWith(
`gas price too high: ${largeGasPrice.toString()} wei, use at most ` +
`tx.gasPrice = ${gasPrice.toString()} wei`
)
})
}) })
describe('eth_call', () => { describe('eth_call', () => {
......
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
replicaProvider, replicaProvider,
l1Wallet, l1Wallet,
l2Wallet, l2Wallet,
gasPriceOracleWallet,
fundUser, fundUser,
getOvmEth, getOvmEth,
getL1Bridge, getL1Bridge,
...@@ -100,7 +101,7 @@ export class OptimismEnv { ...@@ -100,7 +101,7 @@ export class OptimismEnv {
.attach(ctcAddress) .attach(ctcAddress)
const gasPriceOracle = getContractFactory('OVM_GasPriceOracle') const gasPriceOracle = getContractFactory('OVM_GasPriceOracle')
.connect(l2Wallet) .connect(gasPriceOracleWallet)
.attach(predeploys.OVM_GasPriceOracle) .attach(predeploys.OVM_GasPriceOracle)
const sccAddress = await addressManager.getAddress('StateCommitmentChain') const sccAddress = await addressManager.getAddress('StateCommitmentChain')
......
...@@ -47,6 +47,10 @@ const env = cleanEnv(process.env, { ...@@ -47,6 +47,10 @@ const env = cleanEnv(process.env, {
ADDRESS_MANAGER: str({ ADDRESS_MANAGER: str({
default: '0x5FbDB2315678afecb367f032d93F642f64180aa3', default: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
}), }),
GAS_PRICE_ORACLE_PRIVATE_KEY: str({
default:
'0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba',
}),
L2_CHAINID: num({ default: 420 }), L2_CHAINID: num({ default: 420 }),
IS_LIVE_NETWORK: bool({ default: false }), IS_LIVE_NETWORK: bool({ default: false }),
}) })
...@@ -77,6 +81,12 @@ export const l1Wallet = new Wallet(env.PRIVATE_KEY, l1Provider) ...@@ -77,6 +81,12 @@ export const l1Wallet = new Wallet(env.PRIVATE_KEY, l1Provider)
// if it's using non-0 gas price // if it's using non-0 gas price
export const l2Wallet = l1Wallet.connect(l2Provider) export const l2Wallet = l1Wallet.connect(l2Provider)
// The owner of the GasPriceOracle on L2
export const gasPriceOracleWallet = new Wallet(
env.GAS_PRICE_ORACLE_PRIVATE_KEY,
l2Provider
)
// Predeploys // Predeploys
export const PROXY_SEQUENCER_ENTRYPOINT_ADDRESS = export const PROXY_SEQUENCER_ENTRYPOINT_ADDRESS =
'0x4200000000000000000000000000000000000004' '0x4200000000000000000000000000000000000004'
...@@ -182,14 +192,17 @@ export const waitForL2Geth = async ( ...@@ -182,14 +192,17 @@ export const waitForL2Geth = async (
// eslint-disable-next-line @typescript-eslint/no-shadow // eslint-disable-next-line @typescript-eslint/no-shadow
export const gasPriceForL2 = async (env: OptimismEnv) => { export const gasPriceForL2 = async (env: OptimismEnv) => {
if (await isMainnet(env)) { // The integration tests enforce fees on L2
// which run against hardhat on L1. Update if
// geth --dev is adopted for L1
const chainId = await env.l1Wallet.getChainId()
if ((await isMainnet(env)) || chainId === 31337) {
return env.l2Wallet.getGasPrice() return env.l2Wallet.getGasPrice()
} }
if (isLiveNetwork()) { if (isLiveNetwork()) {
return Promise.resolve(BigNumber.from(10000)) return Promise.resolve(BigNumber.from(10000))
} }
return Promise.resolve(BigNumber.from(0)) return Promise.resolve(BigNumber.from(0))
} }
......
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