Skip to content

Commit 05a1ec2

Browse files
committed
fixes
1 parent 3eeda26 commit 05a1ec2

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

core/tests/highlevel-test-tools/tests/token-balance-migration-tester.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,36 @@ export class ChainHandler {
104104
async migrateToGateway() {
105105
// Pause deposits before initiating migration
106106
await utils.spawn(`zkstack chain pause-deposits --chain ${this.inner.chainName}`);
107-
//await utils.spawn(`zkstack chain gateway notify-about-to-gateway-update --chain ${this.inner.chainName}`);
108107
// Wait for all batches to be executed and stop the server
109108
// Priority queue should be empty as all deposits have already been processed
110109
await this.inner.waitForAllBatchesToBeExecuted();
111110
await this.stopServer();
112111
// We can now reliably migrate to gateway
113112
await migrateToGatewayIfNeeded(this.inner.chainName);
114-
115113
await startServer(this.inner.chainName);
114+
116115
// We can now define the gateway getters contract
117116
const gatewayConfig = loadConfig({ pathToHome, chain: this.inner.chainName, config: 'gateway_chain.yaml' });
117+
const secretsConfig = loadConfig({ pathToHome, chain: this.inner.chainName, config: 'secrets.yaml' });
118118
this.gwGettersContract = new zksync.Contract(
119119
gatewayConfig.diamond_proxy_addr,
120120
readArtifact('Getters', 'out', 'GettersFacet').abi,
121-
this.l2RichWallet
121+
new zksync.Provider(secretsConfig.l1.gateway_rpc_url)
122122
);
123123
}
124124

125125
async migrateFromGateway() {
126126
// Pause deposits before initiating migration
127127
await utils.spawn(`zkstack chain pause-deposits --chain ${this.inner.chainName}`);
128-
// Notify server
129-
// Wait for all batches to be executed
128+
// Wait for priority queue to be empty and all batches to be executed
129+
await this.waitForPriorityQueueToBeEmpty(this.gwGettersContract);
130130
await this.inner.waitForAllBatchesToBeExecuted();
131+
await this.stopServer();
131132
// Migrate from gateway
132133
await utils.spawn(
133134
`zkstack chain gateway migrate-from-gateway --gateway-chain-name gateway --chain ${this.inner.chainName}`
134135
);
136+
await startServer(this.inner.chainName);
135137
}
136138

137139
async migrateTokenBalancesToGateway() {
@@ -154,18 +156,22 @@ export class ChainHandler {
154156
}
155157

156158
async migrateTokenBalancesToL1() {
157-
const migrationCmd = `zkstack chain gateway migrate-token-balances --to-gateway false --gateway-chain-name gateway --chain ${this.inner.chainName}`;
158-
159-
// Migration might sometimes fail, so we retry a few times.
160-
for (let attempt = 1; attempt <= 3; attempt++) {
161-
try {
162-
await utils.spawn(migrationCmd);
163-
break;
164-
} catch (e) {
165-
if (attempt === 3) throw e;
166-
await utils.sleep(2 * attempt);
167-
}
168-
}
159+
await executeCommand(
160+
'zkstack',
161+
[
162+
'chain',
163+
'gateway',
164+
'migrate-token-balances',
165+
'--to-gateway',
166+
'false',
167+
'--gateway-chain-name',
168+
'gateway',
169+
'--chain',
170+
this.inner.chainName
171+
],
172+
this.inner.chainName,
173+
'token_balance_migration_to_l1'
174+
);
169175
}
170176
//18:13:19
171177

@@ -182,6 +188,14 @@ export class ChainHandler {
182188
async deployNativeToken() {
183189
return await ERC20Handler.deployTokenOnL2(this.l2RichWallet);
184190
}
191+
192+
private async waitForPriorityQueueToBeEmpty(gettersContract: ethers.Contract | zksync.Contract) {
193+
let tryCount = 0;
194+
while ((await gettersContract.getPriorityQueueSize()) > 0 && tryCount < 100) {
195+
tryCount += 1;
196+
await zksync.utils.sleep(this.l2RichWallet.provider.pollingInterval);
197+
}
198+
}
185199
}
186200

187201
export class ERC20Handler {

core/tests/highlevel-test-tools/tests/token-balance-migration.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ if (shouldSkip) {
158158
});
159159

160160
it('Can migrate token balances from GW', async () => {
161-
// TODO: WHY DOES THIS FAIL?
162-
// await chainHandler.migrateFromGateway();
163-
// await chainHandler.migrateTokenBalancesToL1();
161+
await chainHandler.migrateFromGateway();
162+
await chainHandler.migrateTokenBalancesToL1();
164163
});
165164

166165
it('Bridge tokens', async () => {

0 commit comments

Comments
 (0)