-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathgetBatchPosters.integration.test.ts
More file actions
166 lines (141 loc) Β· 5.98 KB
/
getBatchPosters.integration.test.ts
File metadata and controls
166 lines (141 loc) Β· 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { describe, it, expect } from 'vitest';
import { Address, createPublicClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { nitroTestnodeL2 } from './chains';
import { sequencerInboxActions } from './decorators/sequencerInboxActions';
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from './testHelpers';
import { getBatchPosters } from './getBatchPosters';
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
const { l3Rollup, l3UpgradeExecutor, l3SequencerInbox } = getInformationFromTestnode();
const client = createPublicClient({
chain: nitroTestnodeL2,
transport: http(),
}).extend(
sequencerInboxActions({
sequencerInbox: l3SequencerInbox,
}),
);
async function setBatchPoster(batchPoster: Address, state: boolean) {
const tx = await client.sequencerInboxPrepareTransactionRequest({
functionName: 'setIsBatchPoster',
args: [batchPoster, state],
account: l3RollupOwner.address,
upgradeExecutor: l3UpgradeExecutor,
sequencerInbox: l3SequencerInbox,
});
const txHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(tx),
});
await client.waitForTransactionReceipt({
hash: txHash,
});
}
// Tests can be enabled once we run one node per integration test
describe('successfully get batch posters', () => {
it('when disabling the same batch posters multiple time', async () => {
const randomAccount = privateKeyToAccount(generatePrivateKey()).address;
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
await getBatchPosters(client, {
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
});
// By default, chains from nitro testnode has 1 batch poster
expect(initialBatchPosters).toHaveLength(1);
expect(isAccurateInitially).toBeTruthy();
await setBatchPoster(randomAccount, false);
await setBatchPoster(randomAccount, false);
const { isAccurate: isStillAccurate, batchPosters: newBatchPosters } = await getBatchPosters(
client,
{
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
},
);
// Setting the same batch poster multiple time to false doesn't add new batch posters
expect(newBatchPosters).toEqual(initialBatchPosters);
expect(isStillAccurate).toBeTruthy();
await setBatchPoster(randomAccount, true);
const { batchPosters, isAccurate } = await getBatchPosters(client, {
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
});
expect(batchPosters).toEqual(initialBatchPosters.concat(randomAccount));
expect(isAccurate).toBeTruthy();
// Reset state for future tests
await setBatchPoster(randomAccount, false);
const { isAccurate: isAccurateFinal, batchPosters: batchPostersFinal } = await getBatchPosters(
client,
{
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
},
);
expect(batchPostersFinal).toEqual(initialBatchPosters);
expect(isAccurateFinal).toBeTruthy();
});
it('when enabling the same batch poster multiple time', async () => {
const randomAccount = privateKeyToAccount(generatePrivateKey()).address;
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
await getBatchPosters(client, {
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
});
// By default, chains from nitro testnode has 1 batch poster
expect(initialBatchPosters).toHaveLength(1);
expect(isAccurateInitially).toBeTruthy();
await setBatchPoster(randomAccount, true);
await setBatchPoster(randomAccount, true);
const { isAccurate: isStillAccurate, batchPosters: newBatchPosters } = await getBatchPosters(
client,
{
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
},
);
expect(newBatchPosters).toEqual(initialBatchPosters.concat(randomAccount));
expect(isStillAccurate).toBeTruthy();
// Reset state for futures tests
await setBatchPoster(randomAccount, false);
const { batchPosters, isAccurate } = await getBatchPosters(client, {
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
});
expect(batchPosters).toEqual(initialBatchPosters);
expect(isAccurate).toBeTruthy();
});
it('when adding an existing batch poster', async () => {
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
await getBatchPosters(client, { rollup: l3Rollup, sequencerInbox: l3SequencerInbox });
expect(initialBatchPosters).toHaveLength(1);
expect(isAccurateInitially).toBeTruthy();
const firstBatchPoster = initialBatchPosters[0];
await setBatchPoster(firstBatchPoster, true);
const { isAccurate, batchPosters } = await getBatchPosters(client, {
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
});
expect(batchPosters).toEqual(initialBatchPosters);
expect(isAccurate).toBeTruthy();
});
it('when removing an existing batch poster', async () => {
const { isAccurate: isAccurateInitially, batchPosters: initialBatchPosters } =
await getBatchPosters(client, { rollup: l3Rollup, sequencerInbox: l3SequencerInbox });
expect(initialBatchPosters).toHaveLength(1);
expect(isAccurateInitially).toBeTruthy();
const lastBatchPoster = initialBatchPosters[initialBatchPosters.length - 1];
await setBatchPoster(lastBatchPoster, false);
const { isAccurate, batchPosters } = await getBatchPosters(client, {
rollup: l3Rollup,
sequencerInbox: l3SequencerInbox,
});
expect(batchPosters).toEqual(initialBatchPosters.slice(0, -1));
expect(isAccurate).toBeTruthy();
await setBatchPoster(lastBatchPoster, true);
const { isAccurate: isAccurateFinal, batchPosters: batchPostersFinal } = await getBatchPosters(
client,
{ rollup: l3Rollup, sequencerInbox: l3SequencerInbox },
);
expect(batchPostersFinal).toEqual(initialBatchPosters);
expect(isAccurateFinal).toBeTruthy();
});
});