forked from OffchainLabs/arbitrum-orbit-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestHelpers.ts
212 lines (192 loc) Β· 7.03 KB
/
testHelpers.ts
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import { Address, Chain, PublicClient, zeroAddress } from 'viem';
import { PrivateKeyAccount, privateKeyToAccount, generatePrivateKey } from 'viem/accounts';
import { config } from 'dotenv';
import { execSync } from 'node:child_process';
import { generateChainId, sanitizePrivateKey } from './utils';
import { createRollup } from './createRollup';
import { createRollupPrepareDeploymentParamsConfig } from './createRollupPrepareDeploymentParamsConfig';
import { prepareChainConfig } from './prepareChainConfig';
config();
type PrivateKeyAccountWithPrivateKey = PrivateKeyAccount & { privateKey: `0x${string}` };
// Source: https://github.com/OffchainLabs/nitro-testnode/blob/release/scripts/accounts.ts#L28
type NitroTestNodePrivateKeyAccounts = {
// funnel
deployer: PrivateKeyAccountWithPrivateKey;
// sequencer (batch poster and rollup owner are the same in nitro-testnode)
l2RollupOwner: PrivateKeyAccountWithPrivateKey;
// l3owner
l3RollupOwner: PrivateKeyAccountWithPrivateKey;
// sha256(user_token_bridge_deployer)
l3TokenBridgeDeployer: PrivateKeyAccountWithPrivateKey;
// l2 token bridge deployer
l2TokenBridgeDeployer: PrivateKeyAccountWithPrivateKey;
// l3 token bridge deployer which holds custom gas token
};
export function getNitroTestnodePrivateKeyAccounts(): NitroTestNodePrivateKeyAccounts {
if (
typeof process.env.NITRO_TESTNODE_DEPLOYER_PRIVATE_KEY === 'undefined' ||
typeof process.env.NITRO_TESTNODE_L2_ROLLUP_OWNER_PRIVATE_KEY === 'undefined' ||
typeof process.env.NITRO_TESTNODE_L3_ROLLUP_OWNER_PRIVATE_KEY === 'undefined' ||
typeof process.env.NITRO_TESTNODE_L2_TOKEN_BRIDGE_DEPLOYER_PRIVATE_KEY === 'undefined' ||
typeof process.env.NITRO_TESTNODE_L3_TOKEN_BRIDGE_DEPLOYER_PRIVATE_KEY === 'undefined'
) {
throw Error(
`required env variables: NITRO_TESTNODE_DEPLOYER_PRIVATE_KEY, NITRO_TESTNODE_L2_ROLLUP_OWNER_PRIVATE_KEY,
NITRO_TESTNODE_L2_TOKEN_BRIDGE_DEPLOYER_PRIVATE_KEY, NITRO_TESTNODE_L3_ROLLUP_OWNER_PRIVATE_KEY,
NITRO_TESTNODE_L3_TOKEN_BRIDGE_DEPLOYER_PRIVATE_KEY`,
);
}
const deployerPrivateKey = sanitizePrivateKey(process.env.NITRO_TESTNODE_DEPLOYER_PRIVATE_KEY);
const l2RollupOwnerPrivateKey = sanitizePrivateKey(
process.env.NITRO_TESTNODE_L2_ROLLUP_OWNER_PRIVATE_KEY,
);
const l2TokenBridgeDeployerPrivateKey = sanitizePrivateKey(
process.env.NITRO_TESTNODE_L2_TOKEN_BRIDGE_DEPLOYER_PRIVATE_KEY,
);
const l3RollupOwnerPrivateKey = sanitizePrivateKey(
process.env.NITRO_TESTNODE_L3_ROLLUP_OWNER_PRIVATE_KEY,
);
const l3TokenBridgeDeployerPrivateKey = sanitizePrivateKey(
process.env.NITRO_TESTNODE_L3_TOKEN_BRIDGE_DEPLOYER_PRIVATE_KEY,
);
return {
deployer: { ...privateKeyToAccount(deployerPrivateKey), privateKey: deployerPrivateKey },
l2RollupOwner: {
...privateKeyToAccount(l2RollupOwnerPrivateKey),
privateKey: l2RollupOwnerPrivateKey,
},
l2TokenBridgeDeployer: {
...privateKeyToAccount(l2TokenBridgeDeployerPrivateKey),
privateKey: l2TokenBridgeDeployerPrivateKey,
},
l3RollupOwner: {
...privateKeyToAccount(l3RollupOwnerPrivateKey),
privateKey: l3RollupOwnerPrivateKey,
},
l3TokenBridgeDeployer: {
...privateKeyToAccount(l3TokenBridgeDeployerPrivateKey),
privateKey: l3TokenBridgeDeployerPrivateKey,
},
};
}
type TestnodeInformation = {
bridge: Address;
rollup: Address;
sequencerInbox: Address;
l3SequencerInbox: Address;
l3Bridge: Address;
batchPoster: Address;
l3BatchPoster: Address;
l3UpgradeExecutor: Address;
l3Rollup: `0x${string}`;
l3NativeToken: `0x${string}`;
};
export function getInformationFromTestnode(): TestnodeInformation {
const containers = [
'nitro_sequencer_1',
'nitro-sequencer-1',
'nitro-testnode-sequencer-1',
'nitro-testnode_sequencer_1',
];
for (const container of containers) {
try {
const deploymentJson = JSON.parse(
execSync('docker exec ' + container + ' cat /config/deployment.json').toString(),
);
const l3DeploymentJson = JSON.parse(
execSync('docker exec ' + container + ' cat /config/l3deployment.json').toString(),
);
const sequencerConfig = JSON.parse(
execSync('docker exec ' + container + ' cat /config/sequencer_config.json').toString(),
);
const l3SequencerConfig = JSON.parse(
execSync('docker exec ' + container + ' cat /config/l3node_config.json').toString(),
);
return {
bridge: deploymentJson['bridge'],
rollup: deploymentJson['rollup'],
sequencerInbox: deploymentJson['sequencer-inbox'],
batchPoster: sequencerConfig.node['batch-poster']['parent-chain-wallet'].account,
l3Bridge: l3DeploymentJson['bridge'],
l3Rollup: l3DeploymentJson['rollup'],
l3SequencerInbox: l3DeploymentJson['sequencer-inbox'],
l3NativeToken: l3DeploymentJson['native-token'],
l3BatchPoster: l3SequencerConfig.node['batch-poster']['parent-chain-wallet'].account,
l3UpgradeExecutor: l3DeploymentJson['upgrade-executor'],
};
} catch {
// empty on purpose
}
}
throw new Error('nitro-testnode sequencer not found');
}
export async function createRollupHelper({
deployer,
batchPosters,
validators,
nativeToken = zeroAddress,
client,
}: {
deployer: PrivateKeyAccountWithPrivateKey;
batchPosters: Address[];
validators: Address[];
nativeToken: Address;
client: PublicClient;
}) {
const chainId = generateChainId();
const createRollupConfig = createRollupPrepareDeploymentParamsConfig(client, {
chainId: BigInt(chainId),
owner: deployer.address,
chainConfig: prepareChainConfig({
chainId,
arbitrum: {
InitialChainOwner: deployer.address,
DataAvailabilityCommittee: true,
},
}),
});
const createRollupInformation = await createRollup({
params: {
config: createRollupConfig,
batchPosters,
validators,
nativeToken,
},
account: deployer,
parentChainPublicClient: client,
});
// create test rollup with ETH as gas token
return {
createRollupConfig,
createRollupInformation,
};
}
export function testHelper_createCustomParentChain(params?: { id?: number }) {
const chainId = params?.id ?? generateChainId();
const rollupCreator = privateKeyToAccount(generatePrivateKey()).address;
const tokenBridgeCreator = privateKeyToAccount(generatePrivateKey()).address;
return {
id: chainId,
name: `Custom Parent Chain (${chainId})`,
network: `custom-parent-chain-${chainId}`,
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
rpcUrls: {
public: {
// have to put a valid rpc here so using arbitrum sepolia
http: ['https://sepolia-rollup.arbitrum.io/rpc'],
},
default: {
// have to put a valid rpc here so using arbitrum sepolia
http: ['https://sepolia-rollup.arbitrum.io/rpc'],
},
},
contracts: {
rollupCreator: { address: rollupCreator },
tokenBridgeCreator: { address: tokenBridgeCreator },
},
} satisfies Chain;
}