Skip to content

Commit 7abce74

Browse files
committed
test: Add integration tests for arbOwner
1 parent 7f20a37 commit 7abce74

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { getNitroTestnodePrivateKeyAccounts } from '../testHelpers';
3+
import { Address, createPublicClient, http, zeroAddress } from 'viem';
4+
import { nitroTestnodeL3 } from '../chains';
5+
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
6+
import { getAllChainOwners } from './getAllChainOwners';
7+
import { buildAddChainOwner } from './buildAddChainOwner';
8+
import { buildRemoveChainOwner } from './buildRemoveChainOwner';
9+
import { isChainOwner } from './isChainOwner';
10+
import { getInfraFeeAccount } from './getInfraFeeAccount';
11+
import { getNetworkFeeAccount } from './getNetworkFeeAccount';
12+
import { getScheduledUpgrade } from './getScheduledUpgrade';
13+
import { buildSetMaxTxGasLimit } from './buildSetMaxTxGasLimit';
14+
import { buildSetSpeedLimit } from './buildSetSpeedLimit';
15+
import { buildSetParentPricePerUnit } from './buildSetParentPricePerUnit';
16+
import { getParentBaseFeeEstimate } from './getParentBaseFeeEstimate';
17+
import { getGasAccountingParams } from './getGasAccountingParams';
18+
import { buildSetParentPricingRewardRate } from './buildSetParentPricingRewardRate';
19+
import { getParentRewardRate } from './getParentRewardRate';
20+
import { buildSetParentPricingRewardRecipient } from './buildSetParentPricingRewardRecipient';
21+
import { getParentRewardRecipient } from './getParentRewardRecipient';
22+
23+
const { l3RollupOwner } = getNitroTestnodePrivateKeyAccounts();
24+
25+
const client = createPublicClient({
26+
chain: nitroTestnodeL3,
27+
transport: http(),
28+
});
29+
30+
describe('chain owner management', () => {
31+
it('buildAdd/RemoveChainOwner successfully add and remove chain owner', async () => {
32+
const randomAddress = privateKeyToAccount(generatePrivateKey()).address;
33+
expect(await getAllChainOwners(client)).toEqual([l3RollupOwner.address]);
34+
expect(await isChainOwner(client, { address: randomAddress })).toBeFalsy();
35+
36+
const addTransactionRequest = await buildAddChainOwner(client, {
37+
upgradeExecutor: false,
38+
account: l3RollupOwner.address,
39+
params: {
40+
newOwner: randomAddress,
41+
},
42+
});
43+
const addTxHash = await client.sendRawTransaction({
44+
serializedTransaction: await l3RollupOwner.signTransaction(addTransactionRequest),
45+
});
46+
await client.waitForTransactionReceipt({ hash: addTxHash });
47+
48+
expect(await isChainOwner(client, { address: randomAddress })).toBeTruthy();
49+
expect(await getAllChainOwners(client)).toEqual([l3RollupOwner.address, randomAddress]);
50+
51+
const removeTransactionRequest = await buildRemoveChainOwner(client, {
52+
upgradeExecutor: false,
53+
account: l3RollupOwner.address,
54+
params: {
55+
owner: randomAddress,
56+
},
57+
});
58+
const removeTxHash = await client.sendRawTransaction({
59+
serializedTransaction: await l3RollupOwner.signTransaction(removeTransactionRequest),
60+
});
61+
await client.waitForTransactionReceipt({ hash: removeTxHash });
62+
63+
expect(await getAllChainOwners(client)).toEqual([l3RollupOwner.address]);
64+
expect(await isChainOwner(client, { address: randomAddress })).toBeFalsy();
65+
});
66+
});
67+
68+
describe('Fee account', () => {
69+
it('getInfraFeeAccount returns the infra fee account', async () => {
70+
const infraFeeAccount = await getInfraFeeAccount(client);
71+
expect(infraFeeAccount).toBe(zeroAddress);
72+
});
73+
74+
it('getNetworkFeeAccount returns the network fee account', async () => {
75+
const networkFeeAccount = await getNetworkFeeAccount(client);
76+
expect(networkFeeAccount).toBe(l3RollupOwner.address);
77+
});
78+
});
79+
80+
describe('Fee management', () => {
81+
it('buildSetMaxTxGasLimit successfully set max gas limit for transaction', async () => {
82+
async function changeMaxTxGasLimit(limit: bigint) {
83+
const transactionRequest = await buildSetMaxTxGasLimit(client, {
84+
upgradeExecutor: false,
85+
account: l3RollupOwner.address,
86+
params: {
87+
limit,
88+
},
89+
});
90+
const txHash = await client.sendRawTransaction({
91+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
92+
});
93+
await client.waitForTransactionReceipt({ hash: txHash });
94+
}
95+
// const { maxTxGasLimit } = await getGasAccountingParams(client);
96+
// expect(maxTxGasLimit).toEqual(32000000n)
97+
98+
await changeMaxTxGasLimit(64_000_000n);
99+
100+
// const { maxTxGasLimit } = await getGasAccountingParams(client);
101+
// expect(maxTxGasLimit).toEqual(64000000n)
102+
103+
await changeMaxTxGasLimit(32_000_000n);
104+
105+
// const { maxTxGasLimit } = await getGasAccountingParams(client);
106+
// expect(maxTxGasLimit).toEqual(32000000n)
107+
});
108+
109+
it('buildSetSpeedLimit successfully speed limit', async () => {
110+
async function changeSpeedLimit(limit: bigint) {
111+
const transactionRequest = await buildSetSpeedLimit(client, {
112+
upgradeExecutor: false,
113+
account: l3RollupOwner.address,
114+
params: {
115+
limit,
116+
},
117+
});
118+
const txHash = await client.sendRawTransaction({
119+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
120+
});
121+
await client.waitForTransactionReceipt({ hash: txHash });
122+
}
123+
expect((await getGasAccountingParams(client)).speedLimitPerSecond).toEqual(7_000_000n);
124+
125+
await changeSpeedLimit(14_000_000n);
126+
expect((await getGasAccountingParams(client)).speedLimitPerSecond).toEqual(14_000_000n);
127+
128+
await changeSpeedLimit(7_000_000n);
129+
expect((await getGasAccountingParams(client)).speedLimitPerSecond).toEqual(7_000_000n);
130+
});
131+
132+
it('buildSetParentPricePerUnit successfully set parent price per unit', async () => {
133+
async function changeParentPricePerUnit(pricePerUnit: bigint) {
134+
const transactionRequest = await buildSetParentPricePerUnit(client, {
135+
upgradeExecutor: false,
136+
account: l3RollupOwner.address,
137+
params: {
138+
pricePerUnit,
139+
},
140+
});
141+
const txHash = await client.sendRawTransaction({
142+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
143+
});
144+
await client.waitForTransactionReceipt({ hash: txHash });
145+
}
146+
147+
const initialParentBaseFeeEstimate = await getParentBaseFeeEstimate(client);
148+
149+
await changeParentPricePerUnit(100_000_000n);
150+
expect(await getParentBaseFeeEstimate(client)).toEqual(100_000_000n);
151+
152+
await changeParentPricePerUnit(initialParentBaseFeeEstimate);
153+
expect(await getParentBaseFeeEstimate(client)).toEqual(initialParentBaseFeeEstimate);
154+
});
155+
156+
it('buildSetParentPricingRewardRate successfully set parent pricing reward rate', async () => {
157+
async function changeParentPriceRewardRate(weiPerUnit: bigint) {
158+
const transactionRequest = await buildSetParentPricingRewardRate(client, {
159+
upgradeExecutor: false,
160+
account: l3RollupOwner.address,
161+
params: {
162+
weiPerUnit,
163+
},
164+
});
165+
const txHash = await client.sendRawTransaction({
166+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
167+
});
168+
await client.waitForTransactionReceipt({ hash: txHash });
169+
}
170+
171+
const initialParentPriceRewardRate = await getParentRewardRate(client);
172+
173+
await changeParentPriceRewardRate(200_000_000n);
174+
expect(await getParentRewardRate(client)).toEqual(200_000_000n);
175+
176+
await changeParentPriceRewardRate(initialParentPriceRewardRate);
177+
expect(await getParentRewardRate(client)).toEqual(initialParentPriceRewardRate);
178+
});
179+
180+
it('buildSetParentPricingRewardRecipient successfully set parent pricing reward recipient', async () => {
181+
async function changeParentPriceRewardRecipient(recipient: Address) {
182+
const transactionRequest = await buildSetParentPricingRewardRecipient(client, {
183+
upgradeExecutor: false,
184+
account: l3RollupOwner.address,
185+
params: {
186+
recipient,
187+
},
188+
});
189+
const txHash = await client.sendRawTransaction({
190+
serializedTransaction: await l3RollupOwner.signTransaction(transactionRequest),
191+
});
192+
await client.waitForTransactionReceipt({ hash: txHash });
193+
}
194+
195+
const initialParentPriceRewardRecipient = await getParentRewardRecipient(client);
196+
expect(initialParentPriceRewardRecipient).toEqual(l3RollupOwner.address);
197+
198+
const randomAddress = privateKeyToAccount(generatePrivateKey()).address;
199+
await changeParentPriceRewardRecipient(randomAddress);
200+
expect(await getParentRewardRecipient(client)).toEqual(randomAddress);
201+
202+
await changeParentPriceRewardRecipient(initialParentPriceRewardRecipient);
203+
expect(await getParentRewardRecipient(client)).toEqual(initialParentPriceRewardRecipient);
204+
});
205+
});
206+
207+
describe('GetScheduledUpgrade', () => {
208+
it('getScheduledUpgrade returns timestamp and version for next upgrade', async () => {
209+
expect(await getScheduledUpgrade(client)).toEqual({
210+
arbosVersion: 0n,
211+
scheduledForTimestamp: 0n,
212+
});
213+
});
214+
});

0 commit comments

Comments
 (0)