|
1 |
| -import { expect, test, vi } from 'vitest' |
2 |
| -import { anvilSepolia } from '../../../test/src/anvil.js' |
3 |
| -import { optimismSepolia } from '../../op-stack/chains.js' |
| 1 | +import { beforeAll, expect, test, vi } from 'vitest' |
| 2 | +import { anvilMainnet } from '../../../test/src/anvil.js' |
| 3 | +import { reset } from '../../actions/index.js' |
| 4 | +import { optimism } from '../../op-stack/chains.js' |
4 | 5 | import { getGames } from './getGames.js'
|
5 | 6 | import { getTimeToNextGame } from './getTimeToNextGame.js'
|
6 | 7 |
|
7 |
| -const sepoliaClient = anvilSepolia.getClient() |
| 8 | +const client = anvilMainnet.getClient() |
8 | 9 |
|
9 |
| -const games = await getGames(sepoliaClient, { |
10 |
| - limit: 10, |
11 |
| - targetChain: optimismSepolia, |
| 10 | +let l2BlockNumber: bigint |
| 11 | +beforeAll(async () => { |
| 12 | + await reset(client, { |
| 13 | + blockNumber: 21911472n, |
| 14 | + }) |
| 15 | + const games = await getGames(client, { |
| 16 | + limit: 10, |
| 17 | + targetChain: optimism, |
| 18 | + }) |
| 19 | + const [game] = games |
| 20 | + l2BlockNumber = game.l2BlockNumber |
12 | 21 | })
|
13 |
| -const [game] = games |
14 |
| -const l2BlockNumber = game.l2BlockNumber |
15 | 22 |
|
16 |
| -// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet. |
17 | 23 | test('default', async () => {
|
18 |
| - const { interval, seconds, timestamp } = await getTimeToNextGame( |
19 |
| - sepoliaClient, |
20 |
| - { |
21 |
| - l2BlockNumber: l2BlockNumber + 1n, |
22 |
| - targetChain: optimismSepolia, |
23 |
| - }, |
24 |
| - ) |
| 24 | + const { interval, seconds, timestamp } = await getTimeToNextGame(client, { |
| 25 | + l2BlockNumber: l2BlockNumber + 1n, |
| 26 | + targetChain: optimism, |
| 27 | + }) |
25 | 28 | expect(interval).toBeDefined()
|
26 | 29 | expect(seconds).toBeDefined()
|
27 | 30 | expect(timestamp).toBeDefined()
|
28 | 31 | })
|
29 | 32 |
|
30 | 33 | test('Date.now < latestOutputTimestamp', async () => {
|
31 | 34 | vi.setSystemTime(new Date(1702399191000))
|
32 |
| - const { seconds, timestamp } = await getTimeToNextGame(sepoliaClient, { |
| 35 | + const { seconds, timestamp } = await getTimeToNextGame(client, { |
33 | 36 | l2BlockNumber: l2BlockNumber + 1n,
|
34 |
| - targetChain: optimismSepolia, |
| 37 | + targetChain: optimism, |
35 | 38 | })
|
36 | 39 | vi.useRealTimers()
|
37 | 40 | expect(seconds).toBe(0)
|
38 | 41 | expect(timestamp).toBe(undefined)
|
39 | 42 | })
|
40 | 43 |
|
41 | 44 | test('elapsedBlocks > blockInterval', async () => {
|
42 |
| - const { interval, seconds, timestamp } = await getTimeToNextGame( |
43 |
| - sepoliaClient, |
44 |
| - { |
45 |
| - l2BlockNumber: l2BlockNumber + 1000n, |
46 |
| - targetChain: optimismSepolia, |
47 |
| - }, |
48 |
| - ) |
| 45 | + const { interval, seconds, timestamp } = await getTimeToNextGame(client, { |
| 46 | + l2BlockNumber: l2BlockNumber + 1000n, |
| 47 | + targetChain: optimism, |
| 48 | + }) |
49 | 49 | expect(interval).toBeDefined()
|
50 | 50 | expect(seconds).toBeDefined()
|
51 | 51 | expect(timestamp).toBeDefined()
|
52 | 52 | })
|
53 | 53 |
|
54 | 54 | test('l2BlockNumber < latestGame.blockNumber', async () => {
|
55 |
| - const { seconds, timestamp } = await getTimeToNextGame(sepoliaClient, { |
| 55 | + const { seconds, timestamp } = await getTimeToNextGame(client, { |
56 | 56 | l2BlockNumber: l2BlockNumber - 10n,
|
57 |
| - targetChain: optimismSepolia, |
| 57 | + targetChain: optimism, |
58 | 58 | })
|
59 | 59 | expect(seconds).toBe(0)
|
60 | 60 | expect(timestamp).toBe(undefined)
|
|
0 commit comments