Skip to content

Commit

Permalink
tests: up op-stack
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Feb 23, 2025
1 parent 6b9b30b commit 3442874
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 104 deletions.
36 changes: 21 additions & 15 deletions src/op-stack/actions/getGame.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { expect, test } from 'vitest'
import { anvilSepolia } from '../../../test/src/anvil.js'
import { optimismSepolia } from '../../op-stack/chains.js'
import { beforeAll, expect, test } from 'vitest'
import { anvilMainnet } from '../../../test/src/anvil.js'
import { reset } from '../../actions/index.js'
import { optimism } from '../../op-stack/chains.js'
import { getGame } from './getGame.js'

const sepoliaClient = anvilSepolia.getClient()
const client = anvilMainnet.getClient()

beforeAll(async () => {
await reset(client, {
blockNumber: 21911472n,
})
})

// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
test('default', async () => {
const game = await getGame(sepoliaClient, {
targetChain: optimismSepolia,
l2BlockNumber: 9510398n,
const game = await getGame(client, {
targetChain: optimism,
l2BlockNumber: 132300000n,
limit: 10,
})
expect(game).toHaveProperty('l2BlockNumber')
Expand All @@ -21,9 +27,9 @@ test('default', async () => {
})

test('args: strategy', async () => {
const game = await getGame(sepoliaClient, {
targetChain: optimismSepolia,
l2BlockNumber: 9510398n,
const game = await getGame(client, {
targetChain: optimism,
l2BlockNumber: 132300000n,
limit: 10,
strategy: 'random',
})
Expand All @@ -36,11 +42,11 @@ test('args: strategy', async () => {
})

test('args: address', async () => {
const game = await getGame(sepoliaClient, {
const game = await getGame(client, {
limit: 10,
l2BlockNumber: 9510398n,
disputeGameFactoryAddress: '0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1',
portalAddress: '0x16Fc5058F25648194471939df75CF27A2fdC48BC',
l2BlockNumber: 132300000n,
disputeGameFactoryAddress: '0xe5965Ab5962eDc7477C8520243A95517CD252fA9',
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed',
})
expect(game).toHaveProperty('l2BlockNumber')
expect(game).toHaveProperty('index')
Expand Down
34 changes: 20 additions & 14 deletions src/op-stack/actions/getGames.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { expect, test } from 'vitest'
import { anvilSepolia } from '../../../test/src/anvil.js'
import { optimismSepolia } from '../../op-stack/chains.js'
import { beforeAll, expect, test } from 'vitest'
import { anvilMainnet } from '../../../test/src/anvil.js'
import { reset } from '../../actions/index.js'
import { optimism } from '../../op-stack/chains.js'
import { getGames } from './getGames.js'

const sepoliaClient = anvilSepolia.getClient()
const client = anvilMainnet.getClient()

beforeAll(async () => {
await reset(client, {
blockNumber: 21911472n,
})
})

// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
test('default', async () => {
const games = await getGames(sepoliaClient, {
targetChain: optimismSepolia,
const games = await getGames(client, {
targetChain: optimism,
limit: 10,
})
expect(games.length > 0).toBeTruthy()
Expand All @@ -23,8 +29,8 @@ test('default', async () => {
})

test('args: l2BlockNumber', async () => {
const games = await getGames(sepoliaClient, {
targetChain: optimismSepolia,
const games = await getGames(client, {
targetChain: optimism,
limit: 10,
l2BlockNumber: 9510398n,
})
Expand All @@ -40,20 +46,20 @@ test('args: l2BlockNumber', async () => {
})

test('args: l2BlockNumber (high)', async () => {
const games = await getGames(sepoliaClient, {
targetChain: optimismSepolia,
const games = await getGames(client, {
targetChain: optimism,
limit: 10,
l2BlockNumber: 99999999999999999999n,
})
expect(games.length).toBe(0)
})

test('args: address', async () => {
const games = await getGames(sepoliaClient, {
const games = await getGames(client, {
limit: 10,
l2BlockNumber: 9510398n,
disputeGameFactoryAddress: '0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1',
portalAddress: '0x16Fc5058F25648194471939df75CF27A2fdC48BC',
disputeGameFactoryAddress: '0xe5965Ab5962eDc7477C8520243A95517CD252fA9',
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed',
})
expect(games.length > 0).toBeTruthy()

Expand Down
29 changes: 8 additions & 21 deletions src/op-stack/actions/getL2Output.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import { expect, test } from 'vitest'
import { anvilMainnet, anvilSepolia } from '../../../test/src/anvil.js'
import { base, optimismSepolia } from '../../op-stack/chains.js'
import { anvilMainnet } from '../../../test/src/anvil.js'
import { reset } from '../../actions/index.js'
import { optimism } from '../../op-stack/chains.js'
import { getL2Output } from './getL2Output.js'

const client = anvilMainnet.getClient()
const sepoliaClient = anvilSepolia.getClient()

test('default', async () => {
const output = await getL2Output(client, {
l2BlockNumber: 2725977n,
targetChain: base,
await reset(client, {
blockNumber: 21911472n,
})
expect(output).toMatchInlineSnapshot(`
{
"l2BlockNumber": 2727000n,
"outputIndex": 1514n,
"outputRoot": "0xff22d9720c41431eb398a07c5b315199f8f0dc6a07643e4e43a20b910f12f2f2",
"timestamp": 1692244499n,
}
`)
})

// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
test('portal v3', async () => {
const game = await getL2Output(sepoliaClient, {
targetChain: optimismSepolia,
l2BlockNumber: 9510398n,
const game = await getL2Output(client, {
targetChain: optimism,
l2BlockNumber: 132300000n,
limit: 10,
})
expect(game).toHaveProperty('l2BlockNumber')
Expand Down
56 changes: 28 additions & 28 deletions src/op-stack/actions/getTimeToNextGame.test.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import { expect, test, vi } from 'vitest'
import { anvilSepolia } from '../../../test/src/anvil.js'
import { optimismSepolia } from '../../op-stack/chains.js'
import { beforeAll, expect, test, vi } from 'vitest'
import { anvilMainnet } from '../../../test/src/anvil.js'
import { reset } from '../../actions/index.js'
import { optimism } from '../../op-stack/chains.js'
import { getGames } from './getGames.js'
import { getTimeToNextGame } from './getTimeToNextGame.js'

const sepoliaClient = anvilSepolia.getClient()
const client = anvilMainnet.getClient()

const games = await getGames(sepoliaClient, {
limit: 10,
targetChain: optimismSepolia,
let l2BlockNumber: bigint
beforeAll(async () => {
await reset(client, {
blockNumber: 21911472n,
})
const games = await getGames(client, {
limit: 10,
targetChain: optimism,
})
const [game] = games
l2BlockNumber = game.l2BlockNumber
})
const [game] = games
const l2BlockNumber = game.l2BlockNumber

// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
test('default', async () => {
const { interval, seconds, timestamp } = await getTimeToNextGame(
sepoliaClient,
{
l2BlockNumber: l2BlockNumber + 1n,
targetChain: optimismSepolia,
},
)
const { interval, seconds, timestamp } = await getTimeToNextGame(client, {
l2BlockNumber: l2BlockNumber + 1n,
targetChain: optimism,
})
expect(interval).toBeDefined()
expect(seconds).toBeDefined()
expect(timestamp).toBeDefined()
})

test('Date.now < latestOutputTimestamp', async () => {
vi.setSystemTime(new Date(1702399191000))
const { seconds, timestamp } = await getTimeToNextGame(sepoliaClient, {
const { seconds, timestamp } = await getTimeToNextGame(client, {
l2BlockNumber: l2BlockNumber + 1n,
targetChain: optimismSepolia,
targetChain: optimism,
})
vi.useRealTimers()
expect(seconds).toBe(0)
expect(timestamp).toBe(undefined)
})

test('elapsedBlocks > blockInterval', async () => {
const { interval, seconds, timestamp } = await getTimeToNextGame(
sepoliaClient,
{
l2BlockNumber: l2BlockNumber + 1000n,
targetChain: optimismSepolia,
},
)
const { interval, seconds, timestamp } = await getTimeToNextGame(client, {
l2BlockNumber: l2BlockNumber + 1000n,
targetChain: optimism,
})
expect(interval).toBeDefined()
expect(seconds).toBeDefined()
expect(timestamp).toBeDefined()
})

test('l2BlockNumber < latestGame.blockNumber', async () => {
const { seconds, timestamp } = await getTimeToNextGame(sepoliaClient, {
const { seconds, timestamp } = await getTimeToNextGame(client, {
l2BlockNumber: l2BlockNumber - 10n,
targetChain: optimismSepolia,
targetChain: optimism,
})
expect(seconds).toBe(0)
expect(timestamp).toBe(undefined)
Expand Down
26 changes: 16 additions & 10 deletions src/op-stack/actions/waitForNextGame.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { expect, test } from 'vitest'
import { anvilSepolia } from '../../../test/src/anvil.js'
import { optimismSepolia } from '../../op-stack/chains.js'
import { beforeAll, expect, test } from 'vitest'
import { anvilMainnet } from '../../../test/src/anvil.js'
import { reset } from '../../actions/index.js'
import { optimism } from '../../op-stack/chains.js'
import { getGames } from './getGames.js'
import { waitForNextGame } from './waitForNextGame.js'

const sepoliaClient = anvilSepolia.getClient()
const client = anvilMainnet.getClient()

const games = await getGames(sepoliaClient, {
limit: 10,
targetChain: optimismSepolia,
beforeAll(async () => {
await reset(client, {
blockNumber: 21911472n,
})
})
const [defaultGame] = games

test('default', async () => {
const game = await waitForNextGame(sepoliaClient, {
const games = await getGames(client, {
limit: 10,
targetChain: optimism,
})
const [defaultGame] = games
const game = await waitForNextGame(client, {
limit: 10,
l2BlockNumber: defaultGame.l2BlockNumber - 10n,
targetChain: optimismSepolia,
targetChain: optimism,
})
expect(game).toHaveProperty('l2BlockNumber')
expect(game).toHaveProperty('index')
Expand Down
29 changes: 13 additions & 16 deletions src/op-stack/decorators/publicL1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { describe, expect, test } from 'vitest'

import { accounts } from '~test/src/constants.js'
import { mainnetClient } from '~test/src/utils.js'
import { anvilSepolia } from '../../../test/src/anvil.js'
import { http, createPublicClient } from '../../index.js'
import { optimism, optimismSepolia } from '../../op-stack/chains.js'
import { optimism } from '../../op-stack/chains.js'
import { getWithdrawals } from '../../op-stack/index.js'
import { publicActionsL1 } from './publicL1.js'

Expand All @@ -14,8 +13,6 @@ const l2Client = createPublicClient({
transport: http(),
})

const sepoliaClient = anvilSepolia.getClient().extend(publicActionsL1())

test('default', async () => {
expect(publicActionsL1()(mainnetClient)).toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -98,19 +95,19 @@ describe('smoke test', () => {
})

test('getGame', async () => {
const request = await sepoliaClient.getGame({
l2BlockNumber: 9510398n,
const request = await client.getGame({
l2BlockNumber: 132300000n,
limit: 10,
targetChain: optimismSepolia,
targetChain: optimism,
})
expect(request).toBeDefined()
})

test('getGames', async () => {
const request = await sepoliaClient.getGames({
l2BlockNumber: 9510398n,
const request = await client.getGames({
l2BlockNumber: 132300000n,
limit: 10,
targetChain: optimismSepolia,
targetChain: optimism,
})
expect(request).toBeDefined()
})
Expand All @@ -131,9 +128,9 @@ describe('smoke test', () => {
})

test('getTimeToNextGame', async () => {
const request = await sepoliaClient.getTimeToNextGame({
const request = await client.getTimeToNextGame({
l2BlockNumber: 113365018n,
targetChain: optimismSepolia,
targetChain: optimism,
})
expect(request).toBeDefined()
})
Expand All @@ -158,14 +155,14 @@ describe('smoke test', () => {
})

test('waitForNextGame', async () => {
const games = await sepoliaClient.getGames({
const games = await client.getGames({
limit: 10,
targetChain: optimismSepolia,
targetChain: optimism,
})
const request = await sepoliaClient.waitForNextGame({
const request = await client.waitForNextGame({
l2BlockNumber: games[0].l2BlockNumber - 10n,
limit: 10,
targetChain: optimismSepolia,
targetChain: optimism,
})
expect(request).toBeDefined()
})
Expand Down

0 comments on commit 3442874

Please sign in to comment.