From 92af8a6bffcdec4308aa9457250b778c7c3994da Mon Sep 17 00:00:00 2001 From: anastasiiaVashchuk Date: Tue, 19 Dec 2023 17:09:42 +0200 Subject: [PATCH] fix some of tests --- test/BootloaderUtilities.spec.ts | 20 +++++++++++--------- test/shared/transactions.ts | 28 ++++++++-------------------- test/shared/utils.ts | 7 ++----- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/test/BootloaderUtilities.spec.ts b/test/BootloaderUtilities.spec.ts index b413243..48f949d 100644 --- a/test/BootloaderUtilities.spec.ts +++ b/test/BootloaderUtilities.spec.ts @@ -3,7 +3,6 @@ import type { BootloaderUtilities } from "../typechain-types"; import { expect } from "chai"; import { ethers } from "hardhat"; import * as zksync from "zksync-ethers"; -import { serializeEip712 } from "zksync-ethers/build/src/utils"; import { signedTxToTransactionData } from "./shared/transactions"; import { deployContract, getWallets } from "./shared/utils"; @@ -32,7 +31,7 @@ describe("BootloaderUtilities tests", function () { }); const signedEip712Tx = await wallet.signTransaction(eip712Tx); const parsedEIP712tx = zksync.utils.parseEip712(signedEip712Tx); - + console.log(" parsedEIP712tx ", parsedEIP712tx ); const eip712TxData = signedTxToTransactionData(parsedEIP712tx)!; const expectedEIP712TxHash = parsedEIP712tx.hash; const expectedEIP712SignedHash = zksync.EIP712Signer.getSignedDigest(eip712Tx); @@ -57,10 +56,10 @@ describe("BootloaderUtilities tests", function () { const txBytes = await wallet.signTransaction(legacyTx); const parsedTx = ethers.Transaction.from(txBytes); const txData = signedTxToTransactionData(parsedTx)!; - + console.log(" parsedTx ", parsedTx.toJSON() ); const expectedTxHash = parsedTx.hash; delete legacyTx.from; - const expectedSignedHash = ethers.keccak256(serializeEip712(legacyTx)); + const expectedSignedHash = ethers.keccak256(parsedTx.serialized); const proposedHashes = await bootloaderUtilities.getTransactionHashes(txData); expect(proposedHashes.txHash).to.be.eq(expectedTxHash); @@ -78,6 +77,7 @@ describe("BootloaderUtilities tests", function () { }); const txBytes = await wallet.signTransaction(legacyTx); const parsedTx = ethers.Transaction.from(txBytes); + console.log(" parsedTx ", parsedTx.toJSON() ); const txData = signedTxToTransactionData(parsedTx)!; const signature = ethers.toBeArray(ethers.hexlify(txData.signature)); @@ -101,11 +101,11 @@ describe("BootloaderUtilities tests", function () { }); const signedEip1559Tx = await wallet.signTransaction(eip1559Tx); const parsedEIP1559tx = ethers.Transaction.from(signedEip1559Tx); - + console.log(" parsedEIP1559tx ", parsedEIP1559tx.toJSON() ); const EIP1559TxData = signedTxToTransactionData(parsedEIP1559tx)!; delete eip1559Tx.from; const expectedEIP1559TxHash = parsedEIP1559tx.hash; - const expectedEIP1559SignedHash = ethers.keccak256(serializeEip712(eip1559Tx)); + const expectedEIP1559SignedHash = ethers.keccak256(parsedEIP1559tx.serialized); const proposedEIP1559Hashes = await bootloaderUtilities.getTransactionHashes(EIP1559TxData); expect(proposedEIP1559Hashes.txHash).to.be.eq(expectedEIP1559TxHash); @@ -124,7 +124,7 @@ describe("BootloaderUtilities tests", function () { }); const signedEip1559Tx = await wallet.signTransaction(eip1559Tx); const parsedEIP1559tx = ethers.Transaction.from(signedEip1559Tx); - + console.log(" parsedEIP1559tx ", parsedEIP1559tx.toJSON() ); const EIP1559TxData = signedTxToTransactionData(parsedEIP1559tx)!; const signature = ethers.toBeArray(ethers.hexlify(EIP1559TxData.signature)); signature[64] = 0; @@ -147,11 +147,12 @@ describe("BootloaderUtilities tests", function () { }); const signedEip2930Tx = await wallet.signTransaction(eip2930Tx); const parsedEIP2930tx = ethers.Transaction.from(signedEip2930Tx); - + console.log(" parsedEIP2930tx ", parsedEIP2930tx.toJSON() ); + const EIP2930TxData = signedTxToTransactionData(parsedEIP2930tx)!; delete eip2930Tx.from; const expectedEIP2930TxHash = parsedEIP2930tx.hash; - const expectedEIP2930SignedHash = ethers.keccak256(serializeEip712(eip2930Tx)); + const expectedEIP2930SignedHash = ethers.keccak256(parsedEIP2930tx.serialized); const proposedEIP2930Hashes = await bootloaderUtilities.getTransactionHashes(EIP2930TxData); expect(proposedEIP2930Hashes.txHash).to.be.eq(expectedEIP2930TxHash); @@ -170,6 +171,7 @@ describe("BootloaderUtilities tests", function () { }); const signedEip2930Tx = await wallet.signTransaction(eip2930Tx); const parsedEIP2930tx = ethers.Transaction.from(signedEip2930Tx); + console.log(" parsedEIP2930tx ", parsedEIP2930tx.toJSON() ); const EIP2930TxData = signedTxToTransactionData(parsedEIP2930tx)!; const signature = ethers.toBeArray(ethers.hexlify(EIP2930TxData.signature)); diff --git a/test/shared/transactions.ts b/test/shared/transactions.ts index b742c4d..521a492 100644 --- a/test/shared/transactions.ts +++ b/test/shared/transactions.ts @@ -1,5 +1,6 @@ -import type { BigNumberish, BytesLike, TransactionLike } from "ethers"; +import type { BigNumberish, BytesLike, Transaction, TransactionLike } from "ethers"; import { ethers } from "ethers"; +import { DataHexString } from "ethers/lib.commonjs/utils/data"; import * as zksync from "zksync-ethers"; // Interface encoding the transaction struct used for AA protocol @@ -33,19 +34,6 @@ export interface TransactionData { } export function signedTxToTransactionData(tx: TransactionLike) { - // Transform legacy transaction's `v` part of the signature - // to a single byte used in the packed eth signature - function unpackV(v: number) { - if (v >= 35) { - const chainId = Math.floor((v - 35) / 2); - return v - chainId * 2 - 8; - } else if (v <= 1) { - return 27 + v; - } - - throw new Error("Invalid `v`"); - } - // eslint-disable-next-line @typescript-eslint/no-explicit-any function legacyTxToTransactionData(tx: any): TransactionData { return { @@ -61,7 +49,7 @@ export function signedTxToTransactionData(tx: TransactionLike) { value: tx.value || 0, reserved: [tx.chainId || 0, 0, 0, 0], data: tx.data!, - signature: ethers.concat([tx.r, tx.s, new Uint8Array([unpackV(tx.v)])]), + signature: ethers.concat([tx.signature?.r! as DataHexString, tx.signature?.s! as DataHexString, new Uint8Array(tx.signature?.v!)]), factoryDeps: [], paymasterInput: "0x", reservedDynamic: "0x", @@ -83,7 +71,7 @@ export function signedTxToTransactionData(tx: TransactionLike) { value: tx.value || 0, reserved: [0, 0, 0, 0], data: tx.data!, - signature: ethers.concat([tx.r, tx.s, unpackV(tx.v)]), + signature: ethers.concat([tx.signature?.r! as DataHexString, tx.signature?.s! as DataHexString, new Uint8Array(tx.signature?.v!)]), factoryDeps: [], paymasterInput: "0x", reservedDynamic: "0x", @@ -98,14 +86,14 @@ export function signedTxToTransactionData(tx: TransactionLike) { to: tx.to!, gasLimit: tx.gasLimit!, gasPerPubdataByteLimit: zksync.utils.DEFAULT_GAS_PER_PUBDATA_LIMIT, - maxFeePerGas: tx.maxFeePerGas, - maxPriorityFeePerGas: tx.maxPriorityFeePerGas, + maxFeePerGas: tx.maxFeePerGas!, + maxPriorityFeePerGas: tx.maxPriorityFeePerGas!, paymaster: 0, nonce: tx.nonce, value: tx.value || 0, reserved: [0, 0, 0, 0], data: tx.data!, - signature: ethers.concat([tx.r, tx.s, unpackV(tx.v)]), + signature: ethers.concat([tx.signature?.r! as DataHexString, tx.signature?.s! as DataHexString, new Uint8Array(tx.signature?.v!)]), factoryDeps: [], paymasterInput: "0x", reservedDynamic: "0x", @@ -135,7 +123,7 @@ export function signedTxToTransactionData(tx: TransactionLike) { } const txType = tx.type ?? 0; - + switch (txType) { case 0: return legacyTxToTransactionData(tx); diff --git a/test/shared/utils.ts b/test/shared/utils.ts index 318436d..bfbdb1c 100644 --- a/test/shared/utils.ts +++ b/test/shared/utils.ts @@ -39,11 +39,8 @@ const wallet = new Wallet(RICH_WALLETS[0].privateKey, provider); const deployer = new Deployer(hre, wallet as any); export async function callFallback(contract: Contract, data: string) { - // `eth_Call` revert is not parsed by ethers, so we send - // transaction to catch the error and use `eth_Call` to the return data. - await contract.fallback!({ data }); - return contract.provider.call({ - to: contract.address, + return contract.runner!.call!({ + to: await contract.getAddress(), data, }); }