Skip to content

Commit

Permalink
draft of sync integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
annieke committed May 22, 2021
1 parent 7750b3d commit 59b368f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 11 deletions.
22 changes: 19 additions & 3 deletions integration-tests/test/shared/docker-compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as compose from 'docker-compose'
import * as shell from 'shelljs'
import * as path from 'path'

type ServiceNames = 'batch_submitter' | 'dtl' | 'l2geth' | 'relayer'
type ServiceNames =
| 'batch_submitter'
| 'dtl'
| 'l2geth'
| 'relayer'
| 'verifier'

const OPS_DIRECTORY = path.join(process.cwd(), '../ops')
const DEFAULT_SERVICES: ServiceNames[] = [
Expand All @@ -15,8 +20,11 @@ const DEFAULT_SERVICES: ServiceNames[] = [
export class DockerComposeNetwork {
constructor(private readonly services: ServiceNames[] = DEFAULT_SERVICES) {}

async up() {
const out = await compose.upMany(this.services, { cwd: OPS_DIRECTORY })
async up(options?: compose.IDockerComposeOptions) {
const out = await compose.upMany(this.services, {
cwd: OPS_DIRECTORY,
...options,
})

const { err, exitCode } = out

Expand All @@ -36,4 +44,12 @@ export class DockerComposeNetwork {
})
}
}

async logs() {
return await compose.logs(this.services, { cwd: OPS_DIRECTORY })
}

async stop(service: ServiceNames) {
return await compose.stopOne(service)
}
}
96 changes: 90 additions & 6 deletions integration-tests/test/sync-verifier.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,105 @@
import chai, { expect } from 'chai'
import { Wallet, BigNumber, Contract } from 'ethers'
import { Wallet, BigNumber, Contract, ContractFactory, providers } from 'ethers'
import { ethers } from 'hardhat'
import { injectL2Context } from '@eth-optimism/core-utils'

import { sleep, l2Provider } from './shared/utils'
import { OptimismEnv } from './shared/env'
import { DockerComposeNetwork } from './shared/docker-compose'

describe('Syncing a verifier', () => {
let env: OptimismEnv
let wallet: Wallet
let verifier: DockerComposeNetwork

const provider = injectL2Context(l2Provider)
before(async () => {
env = await OptimismEnv.new()
wallet = env.l2Wallet
})

it('should sync ERC20 deployment and transfer', async () => {
const tx = ''
const result = await wallet.sendTransaction(tx)
describe('ERC20 interactions', () => {
const initialAmount = 1000
const tokenName = 'OVM Test'
const tokenDecimals = 8
const TokenSymbol = 'OVM'

})
let other: Wallet
let Factory__ERC20: ContractFactory
let ERC20: Contract

before(async () => {
const env = await OptimismEnv.new()
wallet = env.l2Wallet
other = Wallet.createRandom().connect(ethers.provider)
Factory__ERC20 = await ethers.getContractFactory('ERC20', wallet)
})

// TODO(annieke): this currently brings down the sequencer too ugh
// afterEach(async () => {
// verifier.stop('verifier')
// })

it('should sync ERC20 deployment and transfer', async () => {
const preTxTotalEl = (await env.ctc.getTotalElements()) as BigNumber
ERC20 = await Factory__ERC20.deploy(
initialAmount,
tokenName,
tokenDecimals,
TokenSymbol
)

const transfer = await ERC20.transfer(other.address, 100)
await transfer.wait()

// Wait for batch submission to happen by watching the CTC
let newTotalEl = (await env.ctc.getTotalElements()) as BigNumber
while (preTxTotalEl.eq(newTotalEl)) {
await sleep(500)
console.log(
`still equal`,
preTxTotalEl.toNumber(),
newTotalEl.toNumber()
)
newTotalEl = (await env.ctc.getTotalElements()) as BigNumber
}
console.log(preTxTotalEl.toNumber())
console.log(newTotalEl.toNumber())

expect(newTotalEl.gt(preTxTotalEl))

})
const latestSequencerBlock = (await provider.getBlock('latest')) as any
console.log(latestSequencerBlock)

// Bring up new verifier
verifier = new DockerComposeNetwork(['verifier'])
await verifier.up({ commandOptions: ['--scale', 'verifier=1'] })

// Wait for verifier to be looping
let logs = await verifier.logs()
while (!logs.out.includes('Starting Sequencer Loop')) {
console.log('Retrieving more logs')
await sleep(500)
logs = await verifier.logs()
}

const verifierProvider = injectL2Context(
new providers.JsonRpcProvider('http://localhost:8547')
)
console.log(await verifierProvider.getBlock('latest'))

// Wait until verifier has caught up to the sequencer
let latestVerifierBlock = (await verifierProvider.getBlock(
'latest'
)) as any
while (latestVerifierBlock.number < latestSequencerBlock.number) {
await sleep(500)
latestVerifierBlock = (await verifierProvider.getBlock('latest')) as any
}

expect(latestVerifierBlock.stateRoot).to.eq(
latestSequencerBlock.stateRoot
)
})
})
})
4 changes: 2 additions & 2 deletions ops/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ services:
RETRIES: 60
IS_VERIFIER: "true"
ports:
- ${VERIFIER_HTTP_PORT:-8547}:8547
- ${VERIFIER_WS_PORT:-8548}:8548
- ${VERIFIER_HTTP_PORT:-8547}:8545
- ${VERIFIER_WS_PORT:-8548}:8546

integration_tests:
image: ethereumoptimism/integration-tests
Expand Down

0 comments on commit 59b368f

Please sign in to comment.