-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathrollupAdminLogicPublicActions.integration.test.ts
More file actions
147 lines (126 loc) Β· 4.63 KB
/
rollupAdminLogicPublicActions.integration.test.ts
File metadata and controls
147 lines (126 loc) Β· 4.63 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
import { it, expect } from 'vitest';
import { createPublicClient, http } from 'viem';
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { nitroTestnodeL2 } from '../chains';
import { rollupAdminLogicPublicActions } from './rollupAdminLogicPublicActions';
import { getInformationFromTestnode, getNitroTestnodePrivateKeyAccounts } from '../testHelpers';
import { getValidators } from '../getValidators';
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
const { l3Rollup, l3UpgradeExecutor } = getInformationFromTestnode();
const client = createPublicClient({
chain: nitroTestnodeL2,
transport: http(),
}).extend(
rollupAdminLogicPublicActions({
rollup: l3Rollup,
}),
);
it('successfully set validators', async () => {
const randomAccounts = [
privateKeyToAccount(generatePrivateKey()).address,
privateKeyToAccount(generatePrivateKey()).address,
];
const { validators: initialValidators, isAccurate: isAccurateInitially } = await getValidators(
client,
{
rollup: l3Rollup,
},
);
// By default, chains from nitro testnode has 11 validators
// https://github.com/OffchainLabs/nitro-testnode/blob/de8cf4edec0d12e5ef1b7623e54e35ddb579ff0b/test-node.bash#L634
// https://github.com/OffchainLabs/nitro-contracts/blob/47a9c034bc082256d498f8031fab1a37c37a123c/scripts/rollupCreation.ts#L250-L257
expect(initialValidators).toHaveLength(11);
expect(isAccurateInitially).toBeTruthy();
const tx = await client.rollupAdminLogicPrepareTransactionRequest({
functionName: 'setValidator',
args: [randomAccounts, [true, false]],
account: l3RollupOwner.address,
upgradeExecutor: l3UpgradeExecutor,
rollup: l3Rollup,
});
const txHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(tx),
});
await client.waitForTransactionReceipt({
hash: txHash,
});
const validators = await Promise.all([
client.rollupAdminLogicReadContract({
functionName: 'isValidator',
args: [randomAccounts[0]],
rollup: l3Rollup,
}),
client.rollupAdminLogicReadContract({
functionName: 'isValidator',
args: [randomAccounts[1]],
rollup: l3Rollup,
}),
]);
const { validators: currentValidators, isAccurate: currentIsAccurate } = await getValidators(
client,
{ rollup: l3Rollup },
);
expect(validators).toEqual([true, false]);
expect(currentValidators).toEqual(initialValidators.concat(randomAccounts[0]));
expect(currentIsAccurate).toBeTruthy();
const revertTx = await client.rollupAdminLogicPrepareTransactionRequest({
functionName: 'setValidator',
args: [randomAccounts, [false, false]],
account: l3RollupOwner.address,
upgradeExecutor: l3UpgradeExecutor,
rollup: l3Rollup,
});
const revertTxHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(revertTx),
});
await client.waitForTransactionReceipt({
hash: revertTxHash,
});
const { validators: revertedValidators, isAccurate: revertedIsAccurate } = await getValidators(
client,
{
rollup: l3Rollup,
},
);
expect(revertedValidators).toEqual(initialValidators);
expect(revertedIsAccurate).toBeTruthy();
});
it('successfully enable/disable whitelist', async () => {
const whitelistDisabledBefore = await client.rollupAdminLogicReadContract({
functionName: 'validatorWhitelistDisabled',
});
// By default whitelist is not disabled
expect(whitelistDisabledBefore).toEqual(false);
const tx = await client.rollupAdminLogicPrepareTransactionRequest({
functionName: 'setValidatorWhitelistDisabled',
args: [true],
account: l3RollupOwner.address,
rollup: l3Rollup,
upgradeExecutor: l3UpgradeExecutor,
});
const txHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(tx),
});
await client.waitForTransactionReceipt({
hash: txHash,
});
const whitelistDisabled = await client.rollupAdminLogicReadContract({
functionName: 'validatorWhitelistDisabled',
rollup: l3Rollup,
});
expect(whitelistDisabled).toEqual(true);
// Revert changes, so test can be run multiple time without issues
const revertTx = await client.rollupAdminLogicPrepareTransactionRequest({
functionName: 'setValidatorWhitelistDisabled',
args: [false],
account: l3RollupOwner.address,
rollup: l3Rollup,
upgradeExecutor: l3UpgradeExecutor,
});
const revertTxHash = await client.sendRawTransaction({
serializedTransaction: await l3RollupOwner.signTransaction(revertTx),
});
await client.waitForTransactionReceipt({
hash: revertTxHash,
});
});