Commit 6b3a455a authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #1886 from ethereum-optimism/fix/remove-sync-tests

itests: remove old sync-tests
parents c5a8db93 a8013127
---
'@eth-optimism/integration-tests': patch
---
Remove sync-tests as coverage lives in itests now
......@@ -11,7 +11,6 @@
"test:integration": "hardhat --network optimism test",
"test:actor": "IS_LIVE_NETWORK=true ts-node actor-tests/lib/runner.ts",
"test:integration:live": "NO_NETWORK=true IS_LIVE_NETWORK=true hardhat --network optimism test",
"test:sync": "hardhat --network optimism test sync-tests/*.spec.ts --no-compile",
"clean": "rimraf cache artifacts",
"pre-commit": "lint-staged"
},
......
import { expect } from 'chai'
import { Wallet, BigNumber, providers } from 'ethers'
import { injectL2Context } from '@eth-optimism/core-utils'
import {
sleep,
l2Provider,
verifierProvider,
waitForL2Geth,
} from '../test/shared/utils'
import { OptimismEnv } from '../test/shared/env'
import { DockerComposeNetwork } from '../test/shared/docker-compose'
describe('Syncing a verifier', () => {
let env: OptimismEnv
let wallet: Wallet
let verifier: DockerComposeNetwork
let provider: providers.JsonRpcProvider
const sequencerProvider = injectL2Context(l2Provider)
/* Helper functions */
const waitForBatchSubmission = async (
totalElementsBefore: BigNumber
): Promise<BigNumber> => {
// Wait for batch submission to happen by watching the CTC
let totalElementsAfter = (await env.ctc.getTotalElements()) as BigNumber
while (totalElementsBefore.eq(totalElementsAfter)) {
await sleep(500)
totalElementsAfter = (await env.ctc.getTotalElements()) as BigNumber
}
return totalElementsAfter
}
const startVerifier = async () => {
// Bring up new verifier
verifier = new DockerComposeNetwork(['verifier'])
await verifier.up({ commandOptions: ['--scale', 'verifier=1'] })
provider = await waitForL2Geth(verifierProvider)
}
const syncVerifier = async (sequencerBlockNumber: number) => {
// Wait until verifier has caught up to the sequencer
let latestVerifierBlock = (await provider.getBlock('latest')) as any
while (latestVerifierBlock.number < sequencerBlockNumber) {
await sleep(500)
latestVerifierBlock = (await provider.getBlock('latest')) as any
}
return provider.getBlock(sequencerBlockNumber)
}
before(async () => {
env = await OptimismEnv.new()
wallet = env.l2Wallet
})
describe('Basic transactions', () => {
after(async () => {
await verifier.stop('verifier')
await verifier.rm()
})
it('should sync dummy transaction', async () => {
const totalElementsBefore =
(await env.ctc.getTotalElements()) as BigNumber
const tx = {
to: '0x' + '1234'.repeat(10),
gasLimit: 4000000,
gasPrice: 0,
data: '0x',
value: 0,
}
const result = await wallet.sendTransaction(tx)
await result.wait()
const totalElementsAfter = await waitForBatchSubmission(
totalElementsBefore
)
expect(totalElementsAfter.gt(totalElementsAfter))
const latestSequencerBlock = (await sequencerProvider.getBlock(
'latest'
)) as any
await startVerifier()
const matchingVerifierBlock = (await syncVerifier(
latestSequencerBlock.number
)) as any
expect(matchingVerifierBlock.stateRoot).to.eq(
latestSequencerBlock.stateRoot
)
})
it('should have matching block data', async () => {
const sequencerTip = await sequencerProvider.getBlock('latest')
const verifierTip = await provider.getBlock('latest')
expect(sequencerTip.number).to.deep.eq(verifierTip.number)
expect(sequencerTip.hash).to.deep.eq(verifierTip.hash)
})
})
})
import { expect } from 'chai'
import { Wallet, Contract, ContractFactory, providers } from 'ethers'
import { ethers } from 'hardhat'
import { injectL2Context } from '@eth-optimism/core-utils'
import {
sleep,
l2Provider,
replicaProvider,
waitForL2Geth,
} from '../test/shared/utils'
import { OptimismEnv } from '../test/shared/env'
import { DockerComposeNetwork } from '../test/shared/docker-compose'
describe('Syncing a replica', () => {
let env: OptimismEnv
let wallet: Wallet
let replica: DockerComposeNetwork
let provider: providers.JsonRpcProvider
const sequencerProvider = injectL2Context(l2Provider)
/* Helper functions */
const startReplica = async () => {
// Bring up new replica
replica = new DockerComposeNetwork(['replica'])
await replica.up({
commandOptions: ['--scale', 'replica=1'],
})
provider = await waitForL2Geth(replicaProvider)
}
const syncReplica = async (sequencerBlockNumber: number) => {
// Wait until replica has caught up to the sequencer
let latestReplicaBlock = (await provider.getBlock('latest')) as any
while (latestReplicaBlock.number < sequencerBlockNumber) {
await sleep(500)
latestReplicaBlock = (await provider.getBlock('latest')) as any
}
return provider.getBlock(sequencerBlockNumber)
}
before(async () => {
env = await OptimismEnv.new()
wallet = env.l2Wallet
})
after(async () => {
await replica.stop('replica')
await replica.rm()
})
describe('Basic transactions and ERC20s', () => {
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 () => {
other = Wallet.createRandom().connect(ethers.provider)
Factory__ERC20 = await ethers.getContractFactory('ERC20', wallet)
})
it('should sync dummy transaction', async () => {
const tx = {
to: '0x' + '1234'.repeat(10),
gasLimit: 4000000,
gasPrice: 0,
data: '0x',
value: 0,
}
const result = await wallet.sendTransaction(tx)
await result.wait()
const latestSequencerBlock = (await sequencerProvider.getBlock(
'latest'
)) as any
await startReplica()
const matchingReplicaBlock = (await syncReplica(
latestSequencerBlock.number
)) as any
expect(matchingReplicaBlock.stateRoot).to.eq(
latestSequencerBlock.stateRoot
)
})
it('should sync ERC20 deployment and transfer', async () => {
ERC20 = await Factory__ERC20.deploy(
initialAmount,
tokenName,
tokenDecimals,
TokenSymbol
)
const transfer = await ERC20.transfer(other.address, 100)
await transfer.wait()
const latestSequencerBlock = (await provider.getBlock('latest')) as any
const matchingReplicaBlock = (await syncReplica(
latestSequencerBlock.number
)) as any
expect(matchingReplicaBlock.stateRoot).to.eq(
latestSequencerBlock.stateRoot
)
})
})
})
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