Commit 3c5fd4c3 authored by Matthew Slipper's avatar Matthew Slipper Committed by Kelvin Fichter

Itests mainnet prep

parent 23ec66f7
...@@ -33,3 +33,10 @@ You can also set environment variables on the command line instead of inside `.e ...@@ -33,3 +33,10 @@ You can also set environment variables on the command line instead of inside `.e
```bash ```bash
L1_URL=whatever L2_URL=whatever yarn test:integration:live L1_URL=whatever L2_URL=whatever yarn test:integration:live
``` ```
To run the Uniswap integration tests against a deployed set of Uniswap contracts, add the following env vars:
```
UNISWAP_POSITION_MANAGER_ADDRESS=<non fungible position manager address>
UNISWAP_ROUTER_ADDRESS=<router address>
```
...@@ -9,6 +9,7 @@ import simpleStorageJson from '../artifacts/contracts/SimpleStorage.sol/SimpleSt ...@@ -9,6 +9,7 @@ import simpleStorageJson from '../artifacts/contracts/SimpleStorage.sol/SimpleSt
import l2ReverterJson from '../artifacts/contracts/Reverter.sol/Reverter.json' import l2ReverterJson from '../artifacts/contracts/Reverter.sol/Reverter.json'
import { Direction } from './shared/watcher-utils' import { Direction } from './shared/watcher-utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { isMainnet } from './shared/utils'
describe('Basic L1<>L2 Communication', async () => { describe('Basic L1<>L2 Communication', async () => {
let Factory__L1SimpleStorage: ContractFactory let Factory__L1SimpleStorage: ContractFactory
...@@ -48,7 +49,13 @@ describe('Basic L1<>L2 Communication', async () => { ...@@ -48,7 +49,13 @@ describe('Basic L1<>L2 Communication', async () => {
}) })
describe('L2 => L1', () => { describe('L2 => L1', () => {
it('should be able to perform a withdrawal from L2 -> L1', async () => { it('should be able to perform a withdrawal from L2 -> L1', async function () {
if (await isMainnet(env)) {
console.log('Skipping withdrawals test on mainnet.')
this.skip()
return
}
const value = `0x${'77'.repeat(32)}` const value = `0x${'77'.repeat(32)}`
// Send L2 -> L1 message. // Send L2 -> L1 message.
......
...@@ -7,6 +7,9 @@ import { UniswapV3Deployer } from 'uniswap-v3-deploy-plugin/dist/deployer/Uniswa ...@@ -7,6 +7,9 @@ import { UniswapV3Deployer } from 'uniswap-v3-deploy-plugin/dist/deployer/Uniswa
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { FeeAmount, TICK_SPACINGS } from '@uniswap/v3-sdk' import { FeeAmount, TICK_SPACINGS } from '@uniswap/v3-sdk'
import { abi as NFTABI } from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'
import { abi as RouterABI } from '@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json'
chai.use(solidity) chai.use(solidity)
// Below methods taken from the Uniswap test suite, see // Below methods taken from the Uniswap test suite, see
...@@ -97,6 +100,27 @@ describe('Contract interactions', () => { ...@@ -97,6 +100,27 @@ describe('Contract interactions', () => {
let tokens: Contract[] let tokens: Contract[]
before(async () => { before(async () => {
if (
process.env.UNISWAP_POSITION_MANAGER_ADDRESS &&
process.env.UNISWAP_ROUTER_ADDRESS
) {
console.log('Using predeployed Uniswap. Addresses:')
console.log(
`Position manager: ${process.env.UNISWAP_POSITION_MANAGER_ADDRESS}`
)
console.log(`Router: ${process.env.UNISWAP_ROUTER_ADDRESS}`)
contracts = {
positionManager: new Contract(
process.env.UNISWAP_POSITION_MANAGER_ADDRESS,
NFTABI
).connect(env.l2Wallet),
router: new Contract(
process.env.UNISWAP_ROUTER_ADDRESS,
RouterABI
).connect(env.l2Wallet),
}
}
const tokenA = await Factory__ERC20.deploy(100000000, 'OVM1', 8, 'OVM1') const tokenA = await Factory__ERC20.deploy(100000000, 'OVM1', 8, 'OVM1')
await tokenA.deployed() await tokenA.deployed()
const tokenB = await Factory__ERC20.deploy(100000000, 'OVM2', 8, 'OVM2') const tokenB = await Factory__ERC20.deploy(100000000, 'OVM2', 8, 'OVM2')
...@@ -118,7 +142,15 @@ describe('Contract interactions', () => { ...@@ -118,7 +142,15 @@ describe('Contract interactions', () => {
await tx.wait() await tx.wait()
}) })
it('should deploy the Uniswap ecosystem', async () => { it('should deploy the Uniswap ecosystem', async function () {
if (contracts) {
console.log(
'Skipping Uniswap deployment since addresses are already defined.'
)
this.skip()
return
}
contracts = await UniswapV3Deployer.deploy(env.l2Wallet) contracts = await UniswapV3Deployer.deploy(env.l2Wallet)
}) })
......
...@@ -47,7 +47,7 @@ describe('Native ETH value integration tests', () => { ...@@ -47,7 +47,7 @@ describe('Native ETH value integration tests', () => {
const there = await wallet.sendTransaction({ const there = await wallet.sendTransaction({
to: other.address, to: other.address,
value, value,
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
}) })
const thereReceipt = await there.wait() const thereReceipt = await there.wait()
const thereGas = thereReceipt.gasUsed.mul(there.gasPrice) const thereGas = thereReceipt.gasUsed.mul(there.gasPrice)
...@@ -65,7 +65,7 @@ describe('Native ETH value integration tests', () => { ...@@ -65,7 +65,7 @@ describe('Native ETH value integration tests', () => {
const backAgain = await other.sendTransaction({ const backAgain = await other.sendTransaction({
to: wallet.address, to: wallet.address,
value: backVal, value: backVal,
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
}) })
const backReceipt = await backAgain.wait() const backReceipt = await backAgain.wait()
const backGas = backReceipt.gasUsed.mul(backAgain.gasPrice) const backGas = backReceipt.gasUsed.mul(backAgain.gasPrice)
...@@ -171,7 +171,7 @@ describe('Native ETH value integration tests', () => { ...@@ -171,7 +171,7 @@ describe('Native ETH value integration tests', () => {
it('should allow ETH to be sent', async () => { it('should allow ETH to be sent', async () => {
const sendAmount = 15 const sendAmount = 15
const tx = await ValueCalls0.simpleSend(ValueCalls1.address, sendAmount, { const tx = await ValueCalls0.simpleSend(ValueCalls1.address, sendAmount, {
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
}) })
await tx.wait() await tx.wait()
......
...@@ -9,7 +9,6 @@ import { ...@@ -9,7 +9,6 @@ import {
defaultTransactionFactory, defaultTransactionFactory,
fundUser, fundUser,
L2_CHAINID, L2_CHAINID,
IS_LIVE_NETWORK,
isLiveNetwork, isLiveNetwork,
gasPriceForL2, gasPriceForL2,
} from './shared/utils' } from './shared/utils'
...@@ -62,7 +61,7 @@ describe('Basic RPC tests', () => { ...@@ -62,7 +61,7 @@ describe('Basic RPC tests', () => {
describe('eth_sendRawTransaction', () => { describe('eth_sendRawTransaction', () => {
it('should correctly process a valid transaction', async () => { it('should correctly process a valid transaction', async () => {
const tx = defaultTransactionFactory() const tx = defaultTransactionFactory()
tx.gasPrice = await gasPriceForL2() tx.gasPrice = await gasPriceForL2(env)
const nonce = await wallet.getTransactionCount() const nonce = await wallet.getTransactionCount()
const result = await wallet.sendTransaction(tx) const result = await wallet.sendTransaction(tx)
...@@ -76,7 +75,7 @@ describe('Basic RPC tests', () => { ...@@ -76,7 +75,7 @@ describe('Basic RPC tests', () => {
it('should not accept a transaction with the wrong chain ID', async () => { it('should not accept a transaction with the wrong chain ID', async () => {
const tx = { const tx = {
...defaultTransactionFactory(), ...defaultTransactionFactory(),
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
chainId: (await wallet.getChainId()) + 1, chainId: (await wallet.getChainId()) + 1,
} }
...@@ -88,7 +87,7 @@ describe('Basic RPC tests', () => { ...@@ -88,7 +87,7 @@ describe('Basic RPC tests', () => {
it('should not accept a transaction without a chain ID', async () => { it('should not accept a transaction without a chain ID', async () => {
const tx = { const tx = {
...defaultTransactionFactory(), ...defaultTransactionFactory(),
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
chainId: null, // Disables EIP155 transaction signing. chainId: null, // Disables EIP155 transaction signing.
} }
...@@ -100,7 +99,7 @@ describe('Basic RPC tests', () => { ...@@ -100,7 +99,7 @@ describe('Basic RPC tests', () => {
it('should accept a transaction with a value', async () => { it('should accept a transaction with a value', async () => {
const tx = { const tx = {
...defaultTransactionFactory(), ...defaultTransactionFactory(),
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
chainId: await env.l2Wallet.getChainId(), chainId: await env.l2Wallet.getChainId(),
data: '0x', data: '0x',
value: ethers.utils.parseEther('0.1'), value: ethers.utils.parseEther('0.1'),
...@@ -120,7 +119,7 @@ describe('Basic RPC tests', () => { ...@@ -120,7 +119,7 @@ describe('Basic RPC tests', () => {
const balance = await env.l2Wallet.getBalance() const balance = await env.l2Wallet.getBalance()
const tx = { const tx = {
...defaultTransactionFactory(), ...defaultTransactionFactory(),
gasPrice: await gasPriceForL2(), gasPrice: await gasPriceForL2(env),
chainId: await env.l2Wallet.getChainId(), chainId: await env.l2Wallet.getChainId(),
data: '0x', data: '0x',
value: balance.add(ethers.utils.parseEther('1')), value: balance.add(ethers.utils.parseEther('1')),
...@@ -284,7 +283,7 @@ describe('Basic RPC tests', () => { ...@@ -284,7 +283,7 @@ describe('Basic RPC tests', () => {
describe('eth_getTransactionByHash', () => { describe('eth_getTransactionByHash', () => {
it('should be able to get all relevant l1/l2 transaction data', async () => { it('should be able to get all relevant l1/l2 transaction data', async () => {
const tx = defaultTransactionFactory() const tx = defaultTransactionFactory()
tx.gasPrice = await gasPriceForL2() tx.gasPrice = await gasPriceForL2(env)
const result = await wallet.sendTransaction(tx) const result = await wallet.sendTransaction(tx)
await result.wait() await result.wait()
...@@ -299,7 +298,7 @@ describe('Basic RPC tests', () => { ...@@ -299,7 +298,7 @@ describe('Basic RPC tests', () => {
it('should return the block and all included transactions', async () => { it('should return the block and all included transactions', async () => {
// Send a transaction and wait for it to be mined. // Send a transaction and wait for it to be mined.
const tx = defaultTransactionFactory() const tx = defaultTransactionFactory()
tx.gasPrice = await gasPriceForL2() tx.gasPrice = await gasPriceForL2(env)
const result = await wallet.sendTransaction(tx) const result = await wallet.sendTransaction(tx)
const receipt = await result.wait() const receipt = await result.wait()
...@@ -326,7 +325,7 @@ describe('Basic RPC tests', () => { ...@@ -326,7 +325,7 @@ describe('Basic RPC tests', () => {
// other people are sending transactions to the Sequencer at the same time // other people are sending transactions to the Sequencer at the same time
// as this test is running. // as this test is running.
it('should return the same result when new transactions are not applied', async function () { it('should return the same result when new transactions are not applied', async function () {
if (IS_LIVE_NETWORK) { if (isLiveNetwork()) {
this.skip() this.skip()
} }
......
...@@ -78,8 +78,8 @@ export class OptimismEnv { ...@@ -78,8 +78,8 @@ export class OptimismEnv {
// fund the user if needed // fund the user if needed
const balance = await l2Wallet.getBalance() const balance = await l2Wallet.getBalance()
if (balance.isZero()) { if (balance.lt(utils.parseEther('1'))) {
await fundUser(watcher, l1Bridge, utils.parseEther('20')) await fundUser(watcher, l1Bridge, utils.parseEther('1').sub(balance))
} }
const l1Messenger = getContractFactory('L1CrossDomainMessenger') const l1Messenger = getContractFactory('L1CrossDomainMessenger')
.connect(l1Wallet) .connect(l1Wallet)
......
...@@ -71,7 +71,7 @@ export const executeL2ToL1Transaction = async ( ...@@ -71,7 +71,7 @@ export const executeL2ToL1Transaction = async (
), ),
MESSAGE_GAS, MESSAGE_GAS,
{ {
gasPrice: gasPriceForL2(), gasPrice: gasPriceForL2(env),
} }
) )
) )
...@@ -90,7 +90,7 @@ export const executeL2Transaction = async ( ...@@ -90,7 +90,7 @@ export const executeL2Transaction = async (
tx.contract tx.contract
.connect(signer) .connect(signer)
.functions[tx.functionName](...tx.functionParams, { .functions[tx.functionName](...tx.functionParams, {
gasPrice: gasPriceForL2(), gasPrice: gasPriceForL2(env),
}) })
) )
await result.wait() await result.wait()
......
...@@ -174,7 +174,12 @@ export const waitForL2Geth = async ( ...@@ -174,7 +174,12 @@ export const waitForL2Geth = async (
return injectL2Context(provider) return injectL2Context(provider)
} }
export const gasPriceForL2 = async () => { // eslint-disable-next-line @typescript-eslint/no-shadow
export const gasPriceForL2 = async (env: OptimismEnv) => {
if (await isMainnet(env)) {
return env.l2Wallet.getGasPrice()
}
if (isLiveNetwork()) { if (isLiveNetwork()) {
return Promise.resolve(BigNumber.from(10000)) return Promise.resolve(BigNumber.from(10000))
} }
...@@ -198,3 +203,9 @@ export const gasPriceForL1 = async (env: OptimismEnv) => { ...@@ -198,3 +203,9 @@ export const gasPriceForL1 = async (env: OptimismEnv) => {
return BigNumber.from(0) return BigNumber.from(0)
} }
} }
// eslint-disable-next-line @typescript-eslint/no-shadow
export const isMainnet = async (env: OptimismEnv) => {
const chainId = await env.l1Wallet.getChainId()
return chainId === 1
}
...@@ -17,7 +17,7 @@ import { ...@@ -17,7 +17,7 @@ import {
/* Imports: Artifacts */ /* Imports: Artifacts */
import simpleStorageJson from '../artifacts/contracts/SimpleStorage.sol/SimpleStorage.json' import simpleStorageJson from '../artifacts/contracts/SimpleStorage.sol/SimpleStorage.json'
import { fundUser, isLiveNetwork } from './shared/utils' import { fundUser, isLiveNetwork, isMainnet } from './shared/utils'
// Need a big timeout to allow for all transactions to be processed. // Need a big timeout to allow for all transactions to be processed.
// For some reason I can't figure out how to set the timeout on a per-suite basis // For some reason I can't figure out how to set the timeout on a per-suite basis
...@@ -31,8 +31,13 @@ describe('stress tests', () => { ...@@ -31,8 +31,13 @@ describe('stress tests', () => {
const wallets: Wallet[] = [] const wallets: Wallet[] = []
before(async () => { before(async function () {
env = await OptimismEnv.new() env = await OptimismEnv.new()
if (await isMainnet(env)) {
console.log('Skipping stress tests on mainnet.')
this.skip()
return
}
for (let i = 0; i < numTransactions; i++) { for (let i = 0; i < numTransactions; i++) {
wallets.push(Wallet.createRandom()) wallets.push(Wallet.createRandom())
......
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