Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
fix some of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaVashchuk committed Dec 19, 2023
1 parent 9a2392d commit 92af8a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
20 changes: 11 additions & 9 deletions test/BootloaderUtilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -32,7 +31,7 @@ describe("BootloaderUtilities tests", function () {
});
const signedEip712Tx = await wallet.signTransaction(eip712Tx);
const parsedEIP712tx = zksync.utils.parseEip712(signedEip712Tx);

console.log(" parsedEIP712tx ", parsedEIP712tx );

Check failure on line 34 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
const eip712TxData = signedTxToTransactionData(parsedEIP712tx)!;
const expectedEIP712TxHash = parsedEIP712tx.hash;
const expectedEIP712SignedHash = zksync.EIP712Signer.getSignedDigest(eip712Tx);
Expand All @@ -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() );

Check failure on line 59 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
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);
Expand All @@ -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() );

Check failure on line 80 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
const txData = signedTxToTransactionData(parsedTx)!;

const signature = ethers.toBeArray(ethers.hexlify(txData.signature));
Expand All @@ -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() );

Check failure on line 104 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
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);
Expand All @@ -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() );

Check failure on line 127 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
const EIP1559TxData = signedTxToTransactionData(parsedEIP1559tx)!;
const signature = ethers.toBeArray(ethers.hexlify(EIP1559TxData.signature));
signature[64] = 0;
Expand All @@ -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() );

Check failure on line 150 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`

Check failure on line 151 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
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);
Expand All @@ -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() );

Check failure on line 174 in test/BootloaderUtilities.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`

const EIP2930TxData = signedTxToTransactionData(parsedEIP2930tx)!;
const signature = ethers.toBeArray(ethers.hexlify(EIP2930TxData.signature));
Expand Down
28 changes: 8 additions & 20 deletions test/shared/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BigNumberish, BytesLike, TransactionLike } from "ethers";
import type { BigNumberish, BytesLike, Transaction, TransactionLike } from "ethers";

Check failure on line 1 in test/shared/transactions.ts

View workflow job for this annotation

GitHub Actions / lint

'Transaction' is defined but never used
import { ethers } from "ethers";
import { DataHexString } from "ethers/lib.commonjs/utils/data";

Check failure on line 3 in test/shared/transactions.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`
import * as zksync from "zksync-ethers";

// Interface encoding the transaction struct used for AA protocol
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -135,7 +123,7 @@ export function signedTxToTransactionData(tx: TransactionLike) {
}

const txType = tx.type ?? 0;

switch (txType) {
case 0:
return legacyTxToTransactionData(tx);
Expand Down
7 changes: 2 additions & 5 deletions test/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down

0 comments on commit 92af8a6

Please sign in to comment.