From dbeddb219ab12d1e8044a29eb39e0bfb0c6ef9f6 Mon Sep 17 00:00:00 2001 From: Grzegorz Guspiel Date: Mon, 6 Jan 2025 18:11:16 +0200 Subject: [PATCH] Revert "ZK-387: State sync tests (#42)" This reverts commit bbb418738cc6b670ef3658d86563c356dd98c29a. State sync tests pass on local env but fail on nightly testnet tests. Tried to debug them but haven't figured out what's wrong so far. The issue might resolve on its own once we rewrite these tests out of Playwright. --- .../tests/shielder/stateSync.test.ts | 146 ------------------ 1 file changed, 146 deletions(-) delete mode 100644 ts/shielder-sdk-tests/tests/shielder/stateSync.test.ts diff --git a/ts/shielder-sdk-tests/tests/shielder/stateSync.test.ts b/ts/shielder-sdk-tests/tests/shielder/stateSync.test.ts deleted file mode 100644 index 6aaddf60..00000000 --- a/ts/shielder-sdk-tests/tests/shielder/stateSync.test.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { expect } from "@playwright/test"; -import { getChainConfig, getRelayerConfig } from "@tests/chain/config"; -import { sdkTest } from "@tests/playwrightTestUtils"; - -import { generatePrivateKey } from "viem/accounts"; - -sdkTest("sync after withdraw w/ client", async ({ workerPage }) => { - const chainConfig = getChainConfig(); - const relayerConfig = getRelayerConfig(); - const privateKeyAlice = generatePrivateKey(); - - const isGood = await workerPage.evaluate( - async ({ chainConfig, relayerConfig, privateKeyAlice }) => { - // setup - const { alicePublicAccount, shielderClient, aliceSendTransaction } = - await window.chain.testUtils.setupContractTest( - 5n * 10n ** 18n, - chainConfig, - privateKeyAlice, - relayerConfig, - ); - - const depositAmount = 2n * 10n ** 18n; - await shielderClient.shield( - depositAmount, - aliceSendTransaction, - alicePublicAccount.account.address, - ); - - if ((await shielderClient.accountState()).balance != depositAmount) { - throw Error("Account state did not sync after deposit"); - } - - const withdrawAmount = 10n ** 18n; - const addressTo = "0x0000000000000000000000000000000000000001"; - const quotedFees = await shielderClient.getWithdrawFees(); - await shielderClient.withdraw( - withdrawAmount, - quotedFees.totalFee, - addressTo, - ); - - if ( - (await shielderClient.accountState()).balance != - depositAmount - withdrawAmount - ) { - throw Error("Account state did not sync after withdrawal"); - } - - return true; - }, - { chainConfig, relayerConfig, privateKeyAlice }, - ); - expect(isGood).toBe(true); -}); - -sdkTest("sync after withdraw w/o client", async ({ workerPage }) => { - const chainConfig = getChainConfig(); - const relayerConfig = getRelayerConfig(); - const privateKeyAlice = generatePrivateKey(); - - const isGood = await workerPage.evaluate( - async ({ chainConfig, relayerConfig, privateKeyAlice }) => { - // setup - const { - alicePublicAccount, - shielderClient, - aliceSendTransaction, - relayer, - contract, - } = await window.chain.testUtils.setupContractTest( - 5n * 10n ** 18n, - chainConfig, - privateKeyAlice, - relayerConfig, - ); - - const depositAmount = 2n * 10n ** 18n; - await shielderClient.shield( - depositAmount, - aliceSendTransaction, - alicePublicAccount.account.address, - ); - - const stateAfterNewAccount = await shielderClient.accountState(); - - if (stateAfterNewAccount.balance != depositAmount) { - throw Error("Account state did not sync after deposit"); - } - - // withdraw bypassing the shielder client - const withdrawAmount = 10n ** 18n; - const addressTo = "0x0000000000000000000000000000000000000001"; - const withdrawAction = window.shielder.actions.createWithdrawAction( - contract, - relayer!, - ); - - const quotedFees = await shielderClient.getWithdrawFees(); - const withdrawCalldata = await withdrawAction.generateCalldata( - stateAfterNewAccount, - withdrawAmount, - quotedFees.totalFee, - addressTo, - "0x000001", - ); - - const withdrawResponse = await relayer!.withdraw( - withdrawCalldata.expectedContractVersion, - window.crypto.scalar.scalarToBigint( - withdrawCalldata.calldata.pubInputs.idHiding, - ), - window.crypto.scalar.scalarToBigint( - withdrawCalldata.calldata.pubInputs.hNullifierOld, - ), - window.crypto.scalar.scalarToBigint( - withdrawCalldata.calldata.pubInputs.hNoteNew, - ), - window.crypto.scalar.scalarToBigint( - withdrawCalldata.calldata.pubInputs.merkleRoot, - ), - withdrawCalldata.amount, - withdrawCalldata.calldata.proof, - withdrawCalldata.address, - ); - const withdrawReceipt = - await alicePublicAccount.waitForTransactionReceipt({ - hash: withdrawResponse.tx_hash as `0x${string}`, - }); - if (withdrawReceipt.status !== "success") - throw new Error("Transaction failed"); - if ((await shielderClient.accountState()).balance != depositAmount) { - throw Error("Account should not be synced"); - } - await shielderClient.syncShielder(); - const stateAfterWithdraw = await shielderClient.accountState(); - if (stateAfterWithdraw.balance != depositAmount - withdrawAmount) { - throw Error("Account state did not sync after withdraw"); - } - - return true; - }, - { chainConfig, relayerConfig, privateKeyAlice }, - ); - expect(isGood).toBe(true); -});