Skip to content

Commit 3442874

Browse files
committed
tests: up op-stack
1 parent 6b9b30b commit 3442874

File tree

6 files changed

+106
-104
lines changed

6 files changed

+106
-104
lines changed

src/op-stack/actions/getGame.test.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
import { expect, test } from 'vitest'
2-
import { anvilSepolia } from '../../../test/src/anvil.js'
3-
import { optimismSepolia } from '../../op-stack/chains.js'
1+
import { beforeAll, expect, test } 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'
45
import { getGame } from './getGame.js'
56

6-
const sepoliaClient = anvilSepolia.getClient()
7+
const client = anvilMainnet.getClient()
8+
9+
beforeAll(async () => {
10+
await reset(client, {
11+
blockNumber: 21911472n,
12+
})
13+
})
714

8-
// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
915
test('default', async () => {
10-
const game = await getGame(sepoliaClient, {
11-
targetChain: optimismSepolia,
12-
l2BlockNumber: 9510398n,
16+
const game = await getGame(client, {
17+
targetChain: optimism,
18+
l2BlockNumber: 132300000n,
1319
limit: 10,
1420
})
1521
expect(game).toHaveProperty('l2BlockNumber')
@@ -21,9 +27,9 @@ test('default', async () => {
2127
})
2228

2329
test('args: strategy', async () => {
24-
const game = await getGame(sepoliaClient, {
25-
targetChain: optimismSepolia,
26-
l2BlockNumber: 9510398n,
30+
const game = await getGame(client, {
31+
targetChain: optimism,
32+
l2BlockNumber: 132300000n,
2733
limit: 10,
2834
strategy: 'random',
2935
})
@@ -36,11 +42,11 @@ test('args: strategy', async () => {
3642
})
3743

3844
test('args: address', async () => {
39-
const game = await getGame(sepoliaClient, {
45+
const game = await getGame(client, {
4046
limit: 10,
41-
l2BlockNumber: 9510398n,
42-
disputeGameFactoryAddress: '0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1',
43-
portalAddress: '0x16Fc5058F25648194471939df75CF27A2fdC48BC',
47+
l2BlockNumber: 132300000n,
48+
disputeGameFactoryAddress: '0xe5965Ab5962eDc7477C8520243A95517CD252fA9',
49+
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed',
4450
})
4551
expect(game).toHaveProperty('l2BlockNumber')
4652
expect(game).toHaveProperty('index')

src/op-stack/actions/getGames.test.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { expect, test } from 'vitest'
2-
import { anvilSepolia } from '../../../test/src/anvil.js'
3-
import { optimismSepolia } from '../../op-stack/chains.js'
1+
import { beforeAll, expect, test } 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'
45
import { getGames } from './getGames.js'
56

6-
const sepoliaClient = anvilSepolia.getClient()
7+
const client = anvilMainnet.getClient()
8+
9+
beforeAll(async () => {
10+
await reset(client, {
11+
blockNumber: 21911472n,
12+
})
13+
})
714

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

2531
test('args: l2BlockNumber', async () => {
26-
const games = await getGames(sepoliaClient, {
27-
targetChain: optimismSepolia,
32+
const games = await getGames(client, {
33+
targetChain: optimism,
2834
limit: 10,
2935
l2BlockNumber: 9510398n,
3036
})
@@ -40,20 +46,20 @@ test('args: l2BlockNumber', async () => {
4046
})
4147

4248
test('args: l2BlockNumber (high)', async () => {
43-
const games = await getGames(sepoliaClient, {
44-
targetChain: optimismSepolia,
49+
const games = await getGames(client, {
50+
targetChain: optimism,
4551
limit: 10,
4652
l2BlockNumber: 99999999999999999999n,
4753
})
4854
expect(games.length).toBe(0)
4955
})
5056

5157
test('args: address', async () => {
52-
const games = await getGames(sepoliaClient, {
58+
const games = await getGames(client, {
5359
limit: 10,
5460
l2BlockNumber: 9510398n,
55-
disputeGameFactoryAddress: '0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1',
56-
portalAddress: '0x16Fc5058F25648194471939df75CF27A2fdC48BC',
61+
disputeGameFactoryAddress: '0xe5965Ab5962eDc7477C8520243A95517CD252fA9',
62+
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed',
5763
})
5864
expect(games.length > 0).toBeTruthy()
5965

src/op-stack/actions/getL2Output.test.ts

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
import { expect, test } from 'vitest'
2-
import { anvilMainnet, anvilSepolia } from '../../../test/src/anvil.js'
3-
import { base, optimismSepolia } from '../../op-stack/chains.js'
2+
import { anvilMainnet } from '../../../test/src/anvil.js'
3+
import { reset } from '../../actions/index.js'
4+
import { optimism } from '../../op-stack/chains.js'
45
import { getL2Output } from './getL2Output.js'
56

67
const client = anvilMainnet.getClient()
7-
const sepoliaClient = anvilSepolia.getClient()
88

99
test('default', async () => {
10-
const output = await getL2Output(client, {
11-
l2BlockNumber: 2725977n,
12-
targetChain: base,
10+
await reset(client, {
11+
blockNumber: 21911472n,
1312
})
14-
expect(output).toMatchInlineSnapshot(`
15-
{
16-
"l2BlockNumber": 2727000n,
17-
"outputIndex": 1514n,
18-
"outputRoot": "0xff22d9720c41431eb398a07c5b315199f8f0dc6a07643e4e43a20b910f12f2f2",
19-
"timestamp": 1692244499n,
20-
}
21-
`)
22-
})
23-
24-
// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
25-
test('portal v3', async () => {
26-
const game = await getL2Output(sepoliaClient, {
27-
targetChain: optimismSepolia,
28-
l2BlockNumber: 9510398n,
13+
const game = await getL2Output(client, {
14+
targetChain: optimism,
15+
l2BlockNumber: 132300000n,
2916
limit: 10,
3017
})
3118
expect(game).toHaveProperty('l2BlockNumber')

src/op-stack/actions/getTimeToNextGame.test.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
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'
45
import { getGames } from './getGames.js'
56
import { getTimeToNextGame } from './getTimeToNextGame.js'
67

7-
const sepoliaClient = anvilSepolia.getClient()
8+
const client = anvilMainnet.getClient()
89

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
1221
})
13-
const [game] = games
14-
const l2BlockNumber = game.l2BlockNumber
1522

16-
// TODO(fault-proofs): use anvil client when fault proofs deployed to mainnet.
1723
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+
})
2528
expect(interval).toBeDefined()
2629
expect(seconds).toBeDefined()
2730
expect(timestamp).toBeDefined()
2831
})
2932

3033
test('Date.now < latestOutputTimestamp', async () => {
3134
vi.setSystemTime(new Date(1702399191000))
32-
const { seconds, timestamp } = await getTimeToNextGame(sepoliaClient, {
35+
const { seconds, timestamp } = await getTimeToNextGame(client, {
3336
l2BlockNumber: l2BlockNumber + 1n,
34-
targetChain: optimismSepolia,
37+
targetChain: optimism,
3538
})
3639
vi.useRealTimers()
3740
expect(seconds).toBe(0)
3841
expect(timestamp).toBe(undefined)
3942
})
4043

4144
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+
})
4949
expect(interval).toBeDefined()
5050
expect(seconds).toBeDefined()
5151
expect(timestamp).toBeDefined()
5252
})
5353

5454
test('l2BlockNumber < latestGame.blockNumber', async () => {
55-
const { seconds, timestamp } = await getTimeToNextGame(sepoliaClient, {
55+
const { seconds, timestamp } = await getTimeToNextGame(client, {
5656
l2BlockNumber: l2BlockNumber - 10n,
57-
targetChain: optimismSepolia,
57+
targetChain: optimism,
5858
})
5959
expect(seconds).toBe(0)
6060
expect(timestamp).toBe(undefined)

src/op-stack/actions/waitForNextGame.test.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
import { expect, test } from 'vitest'
2-
import { anvilSepolia } from '../../../test/src/anvil.js'
3-
import { optimismSepolia } from '../../op-stack/chains.js'
1+
import { beforeAll, expect, test } 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'
45
import { getGames } from './getGames.js'
56
import { waitForNextGame } from './waitForNextGame.js'
67

7-
const sepoliaClient = anvilSepolia.getClient()
8+
const client = anvilMainnet.getClient()
89

9-
const games = await getGames(sepoliaClient, {
10-
limit: 10,
11-
targetChain: optimismSepolia,
10+
beforeAll(async () => {
11+
await reset(client, {
12+
blockNumber: 21911472n,
13+
})
1214
})
13-
const [defaultGame] = games
1415

1516
test('default', async () => {
16-
const game = await waitForNextGame(sepoliaClient, {
17+
const games = await getGames(client, {
18+
limit: 10,
19+
targetChain: optimism,
20+
})
21+
const [defaultGame] = games
22+
const game = await waitForNextGame(client, {
1723
limit: 10,
1824
l2BlockNumber: defaultGame.l2BlockNumber - 10n,
19-
targetChain: optimismSepolia,
25+
targetChain: optimism,
2026
})
2127
expect(game).toHaveProperty('l2BlockNumber')
2228
expect(game).toHaveProperty('index')

src/op-stack/decorators/publicL1.test.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { describe, expect, test } from 'vitest'
22

33
import { accounts } from '~test/src/constants.js'
44
import { mainnetClient } from '~test/src/utils.js'
5-
import { anvilSepolia } from '../../../test/src/anvil.js'
65
import { http, createPublicClient } from '../../index.js'
7-
import { optimism, optimismSepolia } from '../../op-stack/chains.js'
6+
import { optimism } from '../../op-stack/chains.js'
87
import { getWithdrawals } from '../../op-stack/index.js'
98
import { publicActionsL1 } from './publicL1.js'
109

@@ -14,8 +13,6 @@ const l2Client = createPublicClient({
1413
transport: http(),
1514
})
1615

17-
const sepoliaClient = anvilSepolia.getClient().extend(publicActionsL1())
18-
1916
test('default', async () => {
2017
expect(publicActionsL1()(mainnetClient)).toMatchInlineSnapshot(`
2118
{
@@ -98,19 +95,19 @@ describe('smoke test', () => {
9895
})
9996

10097
test('getGame', async () => {
101-
const request = await sepoliaClient.getGame({
102-
l2BlockNumber: 9510398n,
98+
const request = await client.getGame({
99+
l2BlockNumber: 132300000n,
103100
limit: 10,
104-
targetChain: optimismSepolia,
101+
targetChain: optimism,
105102
})
106103
expect(request).toBeDefined()
107104
})
108105

109106
test('getGames', async () => {
110-
const request = await sepoliaClient.getGames({
111-
l2BlockNumber: 9510398n,
107+
const request = await client.getGames({
108+
l2BlockNumber: 132300000n,
112109
limit: 10,
113-
targetChain: optimismSepolia,
110+
targetChain: optimism,
114111
})
115112
expect(request).toBeDefined()
116113
})
@@ -131,9 +128,9 @@ describe('smoke test', () => {
131128
})
132129

133130
test('getTimeToNextGame', async () => {
134-
const request = await sepoliaClient.getTimeToNextGame({
131+
const request = await client.getTimeToNextGame({
135132
l2BlockNumber: 113365018n,
136-
targetChain: optimismSepolia,
133+
targetChain: optimism,
137134
})
138135
expect(request).toBeDefined()
139136
})
@@ -158,14 +155,14 @@ describe('smoke test', () => {
158155
})
159156

160157
test('waitForNextGame', async () => {
161-
const games = await sepoliaClient.getGames({
158+
const games = await client.getGames({
162159
limit: 10,
163-
targetChain: optimismSepolia,
160+
targetChain: optimism,
164161
})
165-
const request = await sepoliaClient.waitForNextGame({
162+
const request = await client.waitForNextGame({
166163
l2BlockNumber: games[0].l2BlockNumber - 10n,
167164
limit: 10,
168-
targetChain: optimismSepolia,
165+
targetChain: optimism,
169166
})
170167
expect(request).toBeDefined()
171168
})

0 commit comments

Comments
 (0)