Commit f5c29ddd authored by Liam Horne's avatar Liam Horne

refactor: use mocha globals for integration test docker setup

parent 5a1cd418
--file ./test/setup-docker-compose-network.js
\ No newline at end of file
...@@ -8,12 +8,6 @@ import { Direction } from './shared/watcher-utils' ...@@ -8,12 +8,6 @@ import { Direction } from './shared/watcher-utils'
import l1SimpleStorageJson from '../artifacts/contracts/SimpleStorage.sol/SimpleStorage.json' import l1SimpleStorageJson from '../artifacts/contracts/SimpleStorage.sol/SimpleStorage.json'
import l2SimpleStorageJson from '../artifacts-ovm/contracts/SimpleStorage.sol/SimpleStorage.json' import l2SimpleStorageJson from '../artifacts-ovm/contracts/SimpleStorage.sol/SimpleStorage.json'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
before(async () => {
await new DockerComposeNetwork().up()
})
describe('Basic L1<>L2 Communication', async () => { describe('Basic L1<>L2 Communication', async () => {
let Factory__L1SimpleStorage: ContractFactory let Factory__L1SimpleStorage: ContractFactory
......
...@@ -3,12 +3,6 @@ import { ethers } from 'hardhat' ...@@ -3,12 +3,6 @@ import { ethers } from 'hardhat'
import { expect } from 'chai' import { expect } from 'chai'
import { GWEI } from './shared/utils' import { GWEI } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
before(async () => {
await new DockerComposeNetwork().up()
})
describe('Basic ERC20 interactions', async () => { describe('Basic ERC20 interactions', async () => {
const initialAmount = 1000 const initialAmount = 1000
......
...@@ -3,11 +3,6 @@ import chaiAsPromised from 'chai-as-promised' ...@@ -3,11 +3,6 @@ import chaiAsPromised from 'chai-as-promised'
chai.use(chaiAsPromised) chai.use(chaiAsPromised)
import { BigNumber, utils } from 'ethers' import { BigNumber, utils } from 'ethers'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
before(async () => {
await new DockerComposeNetwork().up()
})
describe('Fee Payment Integration Tests', async () => { describe('Fee Payment Integration Tests', async () => {
let env: OptimismEnv let env: OptimismEnv
......
...@@ -2,15 +2,9 @@ import { expect } from 'chai' ...@@ -2,15 +2,9 @@ import { expect } from 'chai'
import { Wallet, utils, BigNumber } from 'ethers' import { Wallet, utils, BigNumber } from 'ethers'
import { Direction } from './shared/watcher-utils' import { Direction } from './shared/watcher-utils'
import { DockerComposeNetwork } from './shared/docker-compose'
import { PROXY_SEQUENCER_ENTRYPOINT_ADDRESS } from './shared/utils' import { PROXY_SEQUENCER_ENTRYPOINT_ADDRESS } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
before(async () => {
await new DockerComposeNetwork().up()
})
describe('Native ETH Integration Tests', async () => { describe('Native ETH Integration Tests', async () => {
let env: OptimismEnv let env: OptimismEnv
let l1Bob: Wallet let l1Bob: Wallet
......
...@@ -8,15 +8,9 @@ import { ...@@ -8,15 +8,9 @@ import {
getAddressManager, getAddressManager,
} from './shared/utils' } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
import { getContractFactory } from '@eth-optimism/contracts' import { getContractFactory } from '@eth-optimism/contracts'
import { Contract, ContractFactory, Wallet, BigNumber } from 'ethers' import { Contract, ContractFactory, Wallet, BigNumber } from 'ethers'
before(async () => {
await new DockerComposeNetwork().up()
})
/** /**
* These tests cover the OVM execution contexts. In the OVM execution * These tests cover the OVM execution contexts. In the OVM execution
* of a L1 to L2 transaction, both `block.number` and `block.timestamp` * of a L1 to L2 transaction, both `block.number` and `block.timestamp`
...@@ -111,16 +105,21 @@ describe('OVM Context: Layer 2 EVM Context', () => { ...@@ -111,16 +105,21 @@ describe('OVM Context: Layer 2 EVM Context', () => {
for (let i = start; i < tip.number; i++) { for (let i = start; i < tip.number; i++) {
const block = await L2Provider.getBlockWithTransactions(i) const block = await L2Provider.getBlockWithTransactions(i)
const [, returnData] = await OVMMulticall.callStatic.aggregate([ const [, returnData] = await OVMMulticall.callStatic.aggregate(
[
OVMMulticall.address,
OVMMulticall.interface.encodeFunctionData('getCurrentBlockTimestamp'),
],
[ [
OVMMulticall.address, [
OVMMulticall.interface.encodeFunctionData('getCurrentBlockNumber'), OVMMulticall.address,
OVMMulticall.interface.encodeFunctionData(
'getCurrentBlockTimestamp'
),
],
[
OVMMulticall.address,
OVMMulticall.interface.encodeFunctionData('getCurrentBlockNumber'),
],
], ],
], {blockTag: i}) { blockTag: i }
)
const timestamp = BigNumber.from(returnData[0]) const timestamp = BigNumber.from(returnData[0])
const blockNumber = BigNumber.from(returnData[1]) const blockNumber = BigNumber.from(returnData[1])
......
...@@ -2,16 +2,11 @@ ...@@ -2,16 +2,11 @@
import { injectL2Context } from '@eth-optimism/core-utils' import { injectL2Context } from '@eth-optimism/core-utils'
import { sleep } from './shared/utils' import { sleep } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
/* Imports: External */ /* Imports: External */
import { providers } from 'ethers' import { providers } from 'ethers'
import { expect } from 'chai' import { expect } from 'chai'
before(async () => {
await new DockerComposeNetwork().up()
})
// This test ensures that the transactions which get `enqueue`d get // This test ensures that the transactions which get `enqueue`d get
// added to the L2 blocks by the Sync Service (which queries the DTL) // added to the L2 blocks by the Sync Service (which queries the DTL)
describe('Queue Ingestion', () => { describe('Queue Ingestion', () => {
......
...@@ -4,12 +4,6 @@ import { ethers } from 'hardhat' ...@@ -4,12 +4,6 @@ import { ethers } from 'hardhat'
/* Imports: External */ /* Imports: External */
import { Contract, Wallet } from 'ethers' import { Contract, Wallet } from 'ethers'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
before(async () => {
await new DockerComposeNetwork().up()
})
describe('Reading events from proxy contracts', () => { describe('Reading events from proxy contracts', () => {
let l2Wallet: Wallet let l2Wallet: Wallet
......
import { injectL2Context } from '@eth-optimism/core-utils' import { injectL2Context } from '@eth-optimism/core-utils'
import { Wallet, BigNumber } from 'ethers' import { Wallet, BigNumber } from 'ethers'
import chai, { expect } from 'chai' import chai, { expect } from 'chai'
import { sleep, l2Provider, GWEI } from './shared/utils' import { sleep, l2Provider, GWEI } from './shared/utils'
import chaiAsPromised from 'chai-as-promised' import chaiAsPromised from 'chai-as-promised'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'
chai.use(chaiAsPromised) chai.use(chaiAsPromised)
before(async () => {
await new DockerComposeNetwork().up()
})
describe('Basic RPC tests', () => { describe('Basic RPC tests', () => {
let env: OptimismEnv let env: OptimismEnv
...@@ -161,8 +155,8 @@ describe('Basic RPC tests', () => { ...@@ -161,8 +155,8 @@ describe('Basic RPC tests', () => {
// 96 bytes * 16 per non zero byte // 96 bytes * 16 per non zero byte
const onesCost = BigNumber.from(96).mul(16) const onesCost = BigNumber.from(96).mul(16)
const expectedCost = dataLen const expectedCost = dataLen
.map(len => BigNumber.from(len).mul(4)) .map((len) => BigNumber.from(len).mul(4))
.map(zerosCost => zerosCost.add(onesCost)) .map((zerosCost) => zerosCost.add(onesCost))
// Repeat this test for a series of possible transaction sizes. // Repeat this test for a series of possible transaction sizes.
for (let i = 0; i < dataLen.length; i++) { for (let i = 0; i < dataLen.length; i++) {
......
const { DockerComposeNetwork } = require("./shared/docker-compose")
before(async () => {
await new DockerComposeNetwork().up()
})
\ No newline at end of file
...@@ -2,28 +2,38 @@ import * as compose from 'docker-compose' ...@@ -2,28 +2,38 @@ import * as compose from 'docker-compose'
import * as shell from 'shelljs' import * as shell from 'shelljs'
import * as path from 'path' import * as path from 'path'
type ServiceNames = 'batch_submitter' | 'dtl' | 'l2geth' | 'relayer' type ServiceNames = 'batch_submitter' | 'dtl' | 'l2geth' | 'relayer'
const OPS_DIRECTORY = path.join(process.cwd(), '../ops') const OPS_DIRECTORY = path.join(process.cwd(), '../ops')
const DEFAULT_SERVICES: ServiceNames[] = ['batch_submitter', 'dtl', 'l2geth', 'relayer'] const DEFAULT_SERVICES: ServiceNames[] = [
'batch_submitter',
'dtl',
'l2geth',
'relayer',
]
export class DockerComposeNetwork { export class DockerComposeNetwork {
constructor(private readonly services: ServiceNames[] = DEFAULT_SERVICES) {} constructor(private readonly services: ServiceNames[] = DEFAULT_SERVICES) {}
async up() { async up() {
const out = await compose.upMany(this.services, {cwd: OPS_DIRECTORY}) const out = await compose.upMany(this.services, { cwd: OPS_DIRECTORY })
const {err, exitCode} = out; const { err, exitCode } = out
if (!err || exitCode) { if (!err || exitCode) {
console.error(err) console.error(err)
throw new Error('Unexpected error when starting docker-compose network, dumping output') throw new Error(
} 'Unexpected error when starting docker-compose network, dumping output'
)
}
if (err.includes('Creating')) { if (err.includes('Creating')) {
console.info('🐳 Tests required starting containers. Waiting for sequencer to ready.') console.info(
shell.exec(`${OPS_DIRECTORY}/scripts/wait-for-sequencer.sh`, {cwd: OPS_DIRECTORY}) '🐳 Tests required starting containers. Waiting for sequencer to ready.'
} )
shell.exec(`${OPS_DIRECTORY}/scripts/wait-for-sequencer.sh`, {
cwd: OPS_DIRECTORY,
})
} }
}
} }
...@@ -18,12 +18,17 @@ import { cleanEnv, str, num } from 'envalid' ...@@ -18,12 +18,17 @@ import { cleanEnv, str, num } from 'envalid'
export const GWEI = BigNumber.from(1e9) export const GWEI = BigNumber.from(1e9)
const env = cleanEnv(process.env, { const env = cleanEnv(process.env, {
L1_URL: str({ default: "http://localhost:9545" }), L1_URL: str({ default: 'http://localhost:9545' }),
L2_URL: str({ default: "http://localhost:8545" }), L2_URL: str({ default: 'http://localhost:8545' }),
L1_POLLING_INTERVAL: num({ default: 10 }), L1_POLLING_INTERVAL: num({ default: 10 }),
L2_POLLING_INTERVAL: num({ default: 10 }), L2_POLLING_INTERVAL: num({ default: 10 }),
PRIVATE_KEY: str({ default: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80' }), PRIVATE_KEY: str({
ADDRESS_MANAGER: str({ default: '0x5FbDB2315678afecb367f032d93F642f64180aa3' }) default:
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
}),
ADDRESS_MANAGER: str({
default: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
}),
}) })
// The hardhat instance // The hardhat instance
......
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