Skip to content

Commit

Permalink
Add a test with forced exit of an operator account
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Feb 23, 2022
1 parent 5ac1ae0 commit 1fa5e04
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
25 changes: 25 additions & 0 deletions core/tests/ts-tests/tests/suits/extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ describe(`Extended tests`, () => {
).to.be.true;
});

it('should force-exit operator account without problems', async () => {
// In this test, we run ForcedExit on the operator account.
// It should not cause any problems and disrupt operator work, since operator doesn't use its L2 balance.
// This is done after checking fees as the part of this workflow, and not at the very end of the whole
// test run (inclusing other suits).
// Running after checking fees is required, since we don't update the running fee.

// Operator account may not exist in L2, so we transfer some funds there to create it first.
// It can also be considered a part of test -- it should not cause problems as well.
const transfer = await alice.syncTransfer({
to: tester.operatorWallet.address(),
token,
amount: TX_AMOUNT
});
const transferReceipt = await transfer.awaitReceipt();
expect(transferReceipt.success, 'Transfer to operator failed').to.be.true;
const forcedExit = await alice.syncForcedExit({
target: tester.operatorWallet.address(),
token
});
// We want the tx to be verified to ensure that block can be created and sent to L1.
const forcedExitReceipt = await forcedExit.awaitVerifyReceipt();
expect(forcedExitReceipt.success, 'ForcedExit of operator account failed').to.be.true;
});

it('should fail trying to send tx with wrong signature', async () => {
await tester.testWrongSignature(alice, bob, token, TX_AMOUNT, providerType);
});
Expand Down
17 changes: 15 additions & 2 deletions core/tests/ts-tests/tests/tester/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class Tester {
public ethProvider: ethers.providers.Provider,
public syncProvider: zksync.SyncProvider,
public ethWallet: ethers.Wallet,
public syncWallet: zksync.Wallet
public syncWallet: zksync.Wallet,
public operatorWallet: zksync.Wallet
) {
this.contract = new ethers.Contract(syncProvider.contractAddress.mainContract, zksyncAbi, ethWallet);
this.runningFee = ethers.BigNumber.from(0);
Expand All @@ -56,7 +57,19 @@ export class Tester {
"m/44'/60'/0'/0/0"
).connect(ethProvider);
const syncWallet = await zksync.Wallet.fromEthSigner(ethWallet, syncProvider);
return new Tester(network, ethProvider, syncProvider, ethWallet, syncWallet);

const operatorPrivateKey = process.env.ETH_SENDER_SENDER_OPERATOR_PRIVATE_KEY;
if (!operatorPrivateKey) {
throw new Error("Operator private key is not set in env or the variable name has changed");
}
const operatorEthWallet = new ethers.Wallet(operatorPrivateKey);
const operatorWallet = await zksync.Wallet.fromEthSigner(operatorEthWallet, syncProvider);
// Sanity check.
if (operatorWallet.address() != process.env.ETH_SENDER_SENDER_OPERATOR_COMMIT_ETH_ADDR) {
throw new Error("Operator private key doesn't correspond to the operator address from env");
}

return new Tester(network, ethProvider, syncProvider, ethWallet, syncWallet, operatorWallet);
}

static async createSyncProvider(network: Network, transport: 'WS' | 'HTTP', providerType: 'REST' | 'RPC') {
Expand Down

0 comments on commit 1fa5e04

Please sign in to comment.