Commit 27452790 authored by Mark Tyneway's avatar Mark Tyneway

tests: add replica tests

parent 128e0f84
import { OptimismEnv } from './shared/env'
import { defaultTransactionFactory, gasPriceForL2, sleep } from './shared/utils'
import { expect } from 'chai'
describe('Replica Tests', () => {
let env: OptimismEnv
before(async () => {
env = await OptimismEnv.new()
})
describe('Matching blocks', () => {
it('should sync a transaction', async () => {
const tx = defaultTransactionFactory()
tx.gasPrice = await gasPriceForL2()
const result = await env.l2Wallet.sendTransaction(tx)
let receipt
while (!receipt) {
receipt = await env.replicaProvider.getTransactionReceipt(result.hash)
await sleep(200)
}
const sequencerBlock = (await env.l2Provider.getBlock(
result.blockNumber
)) as any
const replicaBlock = (await env.replicaProvider.getBlock(
result.blockNumber
)) as any
expect(sequencerBlock.stateRoot).to.deep.eq(replicaBlock.stateRoot)
expect(sequencerBlock.hash).to.deep.eq(replicaBlock.hash)
})
it('sync an unprotected tx (eip155)', async () => {
const tx = {
...defaultTransactionFactory(),
nonce: await env.l2Wallet.getTransactionCount(),
gasPrice: await gasPriceForL2(),
chainId: null, // Disables EIP155 transaction signing.
}
const signed = await env.l2Wallet.signTransaction(tx)
const result = await env.l2Provider.sendTransaction(signed)
let receipt
while (!receipt) {
receipt = await env.replicaProvider.getTransactionReceipt(result.hash)
await sleep(200)
}
const sequencerBlock = (await env.l2Provider.getBlock(
result.blockNumber
)) as any
const replicaBlock = (await env.replicaProvider.getBlock(
result.blockNumber
)) as any
expect(sequencerBlock.stateRoot).to.deep.eq(replicaBlock.stateRoot)
expect(sequencerBlock.hash).to.deep.eq(replicaBlock.hash)
})
})
})
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
getAddressManager, getAddressManager,
l1Provider, l1Provider,
l2Provider, l2Provider,
replicaProvider,
l1Wallet, l1Wallet,
l2Wallet, l2Wallet,
fundUser, fundUser,
...@@ -52,6 +53,7 @@ export class OptimismEnv { ...@@ -52,6 +53,7 @@ export class OptimismEnv {
// The providers // The providers
l1Provider: providers.JsonRpcProvider l1Provider: providers.JsonRpcProvider
l2Provider: providers.JsonRpcProvider l2Provider: providers.JsonRpcProvider
replicaProvider: providers.JsonRpcProvider
constructor(args: any) { constructor(args: any) {
this.addressManager = args.addressManager this.addressManager = args.addressManager
...@@ -67,6 +69,7 @@ export class OptimismEnv { ...@@ -67,6 +69,7 @@ export class OptimismEnv {
this.l2Wallet = args.l2Wallet this.l2Wallet = args.l2Wallet
this.l1Provider = args.l1Provider this.l1Provider = args.l1Provider
this.l2Provider = args.l2Provider this.l2Provider = args.l2Provider
this.replicaProvider = args.replicaProvider
this.ctc = args.ctc this.ctc = args.ctc
this.scc = args.scc this.scc = args.scc
} }
...@@ -126,6 +129,7 @@ export class OptimismEnv { ...@@ -126,6 +129,7 @@ export class OptimismEnv {
l2Wallet, l2Wallet,
l1Provider, l1Provider,
l2Provider, l2Provider,
replicaProvider,
}) })
} }
......
...@@ -55,13 +55,19 @@ const env = cleanEnv(process.env, { ...@@ -55,13 +55,19 @@ const env = cleanEnv(process.env, {
export const l1Provider = new providers.JsonRpcProvider(env.L1_URL) export const l1Provider = new providers.JsonRpcProvider(env.L1_URL)
l1Provider.pollingInterval = env.L1_POLLING_INTERVAL l1Provider.pollingInterval = env.L1_POLLING_INTERVAL
export const l2Provider = new providers.JsonRpcProvider(env.L2_URL) export const l2Provider = injectL2Context(
new providers.JsonRpcProvider(env.L2_URL)
)
l2Provider.pollingInterval = env.L2_POLLING_INTERVAL l2Provider.pollingInterval = env.L2_POLLING_INTERVAL
export const verifierProvider = new providers.JsonRpcProvider(env.VERIFIER_URL) export const verifierProvider = injectL2Context(
new providers.JsonRpcProvider(env.VERIFIER_URL)
)
verifierProvider.pollingInterval = env.VERIFIER_POLLING_INTERVAL verifierProvider.pollingInterval = env.VERIFIER_POLLING_INTERVAL
export const replicaProvider = new providers.JsonRpcProvider(env.REPLICA_URL) export const replicaProvider = injectL2Context(
new providers.JsonRpcProvider(env.REPLICA_URL)
)
replicaProvider.pollingInterval = env.REPLICA_POLLING_INTERVAL replicaProvider.pollingInterval = env.REPLICA_POLLING_INTERVAL
// The sequencer private key which is funded on L1 // The sequencer private key which is funded on L1
......
...@@ -165,7 +165,7 @@ services: ...@@ -165,7 +165,7 @@ services:
depends_on: depends_on:
- dtl - dtl
deploy: deploy:
replicas: 0 replicas: 1
build: build:
context: .. context: ..
dockerfile: ./ops/docker/Dockerfile.geth dockerfile: ./ops/docker/Dockerfile.geth
...@@ -181,8 +181,8 @@ services: ...@@ -181,8 +181,8 @@ services:
ETH1_CTC_DEPLOYMENT_HEIGHT: 8 ETH1_CTC_DEPLOYMENT_HEIGHT: 8
RETRIES: 60 RETRIES: 60
ports: ports:
- ${L2GETH_HTTP_PORT:-8549}:8545 - ${REPLICA_HTTP_PORT:-8549}:8545
- ${L2GETH_WS_PORT:-8550}:8546 - ${REPLICA_WS_PORT:-8550}:8546
integration_tests: integration_tests:
deploy: deploy:
......
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