Commit 1644c7b2 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #1945 from mslipper/feat/nightly-actor-updates

integration-tests: Actor updates to run against nightly
parents f4cf99e3 5787a55b
---
'@eth-optimism/integration-tests': patch
---
Updates to support nightly actor tests
import fs from 'fs' import fs from 'fs'
import client from 'prom-client' import client from 'prom-client'
import http from 'http'
import url from 'url'
export const metricsRegistry = new client.Registry() export const metricsRegistry = new client.Registry()
...@@ -53,3 +55,18 @@ export const dumpMetrics = async (filename: string) => { ...@@ -53,3 +55,18 @@ export const dumpMetrics = async (filename: string) => {
flag: 'w+', flag: 'w+',
}) })
} }
export const serveMetrics = (port: number) => {
const server = http.createServer(async (req, res) => {
const route = url.parse(req.url).pathname
if (route !== '/metrics') {
res.writeHead(404)
res.end()
return
}
res.setHeader('Content-Type', metricsRegistry.contentType)
res.end(await metricsRegistry.metrics())
})
server.listen(port)
}
...@@ -3,7 +3,7 @@ import { defaultRuntime } from './convenience' ...@@ -3,7 +3,7 @@ import { defaultRuntime } from './convenience'
import { RunOpts } from './actor' import { RunOpts } from './actor'
import { Command } from 'commander' import { Command } from 'commander'
import pkg from '../../package.json' import pkg from '../../package.json'
import { metricsRegistry } from './metrics' import { serveMetrics } from './metrics'
const program = new Command() const program = new Command()
program.version(pkg.version) program.version(pkg.version)
...@@ -18,6 +18,11 @@ program ...@@ -18,6 +18,11 @@ program
) )
.option('-c, --concurrency <n>', 'number of concurrent workers to spawn', '1') .option('-c, --concurrency <n>', 'number of concurrent workers to spawn', '1')
.option('--think-time <n>', 'how long to wait between each run', '0') .option('--think-time <n>', 'how long to wait between each run', '0')
.option(
'-s, --serve [port]',
'Serve metrics with optional port number',
'8545'
)
program.parse(process.argv) program.parse(process.argv)
...@@ -27,6 +32,8 @@ const runsNum = Number(options.runs) ...@@ -27,6 +32,8 @@ const runsNum = Number(options.runs)
const timeNum = Number(options.time) const timeNum = Number(options.time)
const concNum = Number(options.concurrency) const concNum = Number(options.concurrency)
const thinkNum = Number(options.thinkTime) const thinkNum = Number(options.thinkTime)
const shouldServeMetrics = options.serve !== undefined
const metricsPort = options.serve || 8545
if (isNaN(runsNum) && isNaN(timeNum)) { if (isNaN(runsNum) && isNaN(timeNum)) {
console.error('Must define either a number of runs or how long to run.') console.error('Must define either a number of runs or how long to run.')
...@@ -58,15 +65,19 @@ const opts: Partial<RunOpts> = { ...@@ -58,15 +65,19 @@ const opts: Partial<RunOpts> = {
runs: runsNum, runs: runsNum,
} }
if (shouldServeMetrics) {
process.stderr.write(`Serving metrics on http://0.0.0.0:${metricsPort}.\n`)
serveMetrics(metricsPort)
}
defaultRuntime defaultRuntime
.run(opts) .run(opts)
.then(() => metricsRegistry.metrics()) .then(() => {
.then((metrics) => { process.stderr.write('Run complete.\n')
process.stderr.write('Run complete. Metrics:\n') process.exit(0)
console.log(metrics)
}) })
.catch((err) => { .catch((err) => {
console.error('Error running:') console.error('Error:')
console.error(err) console.error(err)
process.exit(1) process.exit(1)
}) })
import { utils, Wallet, Contract, ContractFactory } from 'ethers' import { utils, Wallet, Contract } from 'ethers'
import { actor, run, setupActor, setupRun } from './lib/convenience' import { actor, run, setupActor, setupRun } from './lib/convenience'
import { OptimismEnv } from '../test/shared/env' import { OptimismEnv } from '../test/shared/env'
import ERC721 from '../artifacts/contracts/NFT.sol/NFT.json' import ERC721 from '../artifacts/contracts/NFT.sol/NFT.json'
...@@ -16,14 +16,7 @@ actor('NFT claimer', () => { ...@@ -16,14 +16,7 @@ actor('NFT claimer', () => {
setupActor(async () => { setupActor(async () => {
env = await OptimismEnv.new() env = await OptimismEnv.new()
contract = new Contract(process.env.ERC_721_ADDRESS, ERC721.abi)
const factory = new ContractFactory(
ERC721.abi,
ERC721.bytecode,
env.l2Wallet
)
contract = await factory.deploy()
await contract.deployed()
}) })
setupRun(async () => { setupRun(async () => {
......
import { BigNumber, Contract, utils, Wallet, ContractFactory } from 'ethers' import { Contract, utils, Wallet } from 'ethers'
import { actor, run, setupActor, setupRun } from './lib/convenience' import { actor, run, setupActor, setupRun } from './lib/convenience'
import { OptimismEnv } from '../test/shared/env' import { OptimismEnv } from '../test/shared/env'
import { UniswapV3Deployer } from 'uniswap-v3-deploy-plugin/dist/deployer/UniswapV3Deployer' import { FeeAmount } from '@uniswap/v3-sdk'
import { FeeAmount, TICK_SPACINGS } from '@uniswap/v3-sdk'
import ERC20 from '../artifacts/contracts/ERC20.sol/ERC20.json' import ERC20 from '../artifacts/contracts/ERC20.sol/ERC20.json'
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'
interface Context { interface Context {
contracts: { [name: string]: Contract } contracts: { [name: string]: Contract }
wallet: Wallet wallet: Wallet
} }
// Below methods taken from the Uniswap test suite, see
// https://github.com/Uniswap/v3-periphery/blob/main/test/shared/ticks.ts
export const getMinTick = (tickSpacing: number) =>
Math.ceil(-887272 / tickSpacing) * tickSpacing
export const getMaxTick = (tickSpacing: number) =>
Math.floor(887272 / tickSpacing) * tickSpacing
actor('Uniswap swapper', () => { actor('Uniswap swapper', () => {
let env: OptimismEnv let env: OptimismEnv
...@@ -27,52 +21,29 @@ actor('Uniswap swapper', () => { ...@@ -27,52 +21,29 @@ actor('Uniswap swapper', () => {
setupActor(async () => { setupActor(async () => {
env = await OptimismEnv.new() env = await OptimismEnv.new()
const factory = new ContractFactory(ERC20.abi, ERC20.bytecode, env.l2Wallet) contracts = {
const tokenA = await factory.deploy(1000000000, 'OVM1', 8, 'OVM1') positionManager: new Contract(
await tokenA.deployed() process.env.UNISWAP_POSITION_MANAGER_ADDRESS,
const tokenB = await factory.deploy(1000000000, 'OVM2', 8, 'OVM2') NFTABI
await tokenB.deployed() ).connect(env.l2Wallet),
router: new Contract(
tokens = process.env.UNISWAP_ROUTER_ADDRESS,
tokenA.address < tokenB.address ? [tokenA, tokenB] : [tokenB, tokenA] RouterABI
contracts = await UniswapV3Deployer.deploy(env.l2Wallet) ).connect(env.l2Wallet),
let tx
for (const token of tokens) {
tx = await token.approve(contracts.positionManager.address, 1000000000)
await tx.wait()
tx = await token.approve(contracts.router.address, 1000000000)
await tx.wait()
} }
tx = await contracts.positionManager.createAndInitializePoolIfNecessary( tokens = [
tokens[0].address, new Contract(process.env.UNISWAP_TOKEN_0_ADDRESS, ERC20.abi).connect(
tokens[1].address, env.l2Wallet
FeeAmount.MEDIUM, ),
// initial ratio of 1/1 new Contract(process.env.UNISWAP_TOKEN_1_ADDRESS, ERC20.abi).connect(
BigNumber.from('79228162514264337593543950336') env.l2Wallet
) ),
await tx.wait() ]
tokens =
tx = await contracts.positionManager.mint( tokens[0].address.toLowerCase() < tokens[1].address.toLowerCase()
{ ? [tokens[0], tokens[1]]
token0: tokens[0].address, : [tokens[1], tokens[0]]
token1: tokens[1].address,
tickLower: getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]),
tickUpper: getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM]),
fee: FeeAmount.MEDIUM,
recipient: env.l2Wallet.address,
amount0Desired: 100000000,
amount1Desired: 100000000,
amount0Min: 0,
amount1Min: 0,
deadline: Date.now() * 2,
},
{
gasLimit: 10000000,
}
)
await tx.wait()
}) })
setupRun(async () => { setupRun(async () => {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"sync-tests/*.ts", "sync-tests/*.ts",
"./actor-tests/**/*.ts", "./actor-tests/**/*.ts",
"./artifacts/**/*.json", "./artifacts/**/*.json",
"./tasks/**/*.ts",
"./package.json" "./package.json"
], ],
"files": ["./hardhat.config.ts"] "files": ["./hardhat.config.ts"]
......
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