Skip to content

Commit

Permalink
fix: remove skipped test
Browse files Browse the repository at this point in the history
  • Loading branch information
idea404 committed Jul 28, 2023
1 parent 74c4e67 commit a91c0d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 64 deletions.
68 changes: 4 additions & 64 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 4,10 @@ import { utils, Wallet, Provider, Contract, EIP712Signer, types } from "zksync-w
import * as hre from "hardhat";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { ZkSyncArtifact } from "@matterlabs/hardhat-zksync-deploy/dist/types";
import { logCyan, sendFunds } from "./utils";

const RICH_WALLET_PK = "0x3eb15da85647edd9a1159a4a13b9e7c56877c4eb33f614546d4db06a51868b1c";

function logCyan(message: string) {
console.log("\x1b[36m%s\x1b[0m", " > " message);
}

describe("Tests for Factory Multisig AA", function () {
const DEFAULT_ADDRESS = "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
let aaFactoryAddress = DEFAULT_ADDRESS;
Expand Down Expand Up @@ -51,7 48,7 @@ describe("Tests for Factory Multisig AA", function () {
// Private key of the account used to deploy
const aaFactory = new ethers.Contract(aaFactoryAddress, factoryArtifact.abi, wallet);

// For the simplicity of the tutorial, we will use zero hash as salt
// For the simplicity, we will use zero hash as salt
const salt = ethers.constants.HashZero;

// deploy account owned by owner1 & owner2
Expand All @@ -64,18 61,12 @@ describe("Tests for Factory Multisig AA", function () {
const abiCoder = new ethers.utils.AbiCoder();
multisigAddress = utils.create2Address(aaFactoryAddress, await aaFactory.aaBytecodeHash(), salt, abiCoder.encode(["address", "address"], [msOwner1.address, msOwner2.address]));
expect(multisigAddress).to.not.equal(DEFAULT_ADDRESS);
logCyan(`Multisig account deployed on address ${multisigAddress}`);
logCyan(`Multisig account address ${multisigAddress}`);

// Send funds to the multisig account we just deployed
logCyan("Sending funds to multisig account");
const sendAmount = ethers.utils.parseEther("0.008");
await (
await wallet.sendTransaction({
to: multisigAddress,
// You can increase the amount of ETH sent to the multisig
value: sendAmount,
})
).wait();
await sendFunds(wallet, multisigAddress, sendAmount);
let multisigBalance = await provider.getBalance(multisigAddress);
expect(multisigBalance.toString()).to.equal(sendAmount.toString());
logCyan(`Multisig account balance is ${multisigBalance.toString()}`);
Expand Down Expand Up @@ -123,55 114,4 @@ describe("Tests for Factory Multisig AA", function () {
multisigBalance = await provider.getBalance(multisigAddress);
logCyan(`Multisig account balance is now ${multisigBalance.toString()}`);
});

// TODO: Fails with "TypeError: Cannot read properties of undefined (reading 'toHexString'"
it.skip("Should be able to send funds from multisig", async function () {
const multisigContract = new ethers.Contract(multisigAddress, multisigArtifact.abi);
const sendAmount = ethers.utils.parseEther("0.001");
logCyan(`Sending ${sendAmount} ETH from multisig`);
const balanceBefore = await provider.getBalance(wallet.address);
logCyan(`Wallet balance before sending funds: ${balanceBefore}`);
const multiSigNonceBefore = await provider.getTransactionCount(multisigAddress);
logCyan(`Multisig nonce before sending funds: ${multiSigNonceBefore}`);

// Constructing a raw transaction
let tx = {
salt: ethers.constants.HashZero,
from: multisigAddress,
value: sendAmount,
chainId: (await provider.getNetwork()).chainId,
nonce: multiSigNonceBefore,
gasLimit: ethers.utils.hexlify(21000), // standard gas limit for ETH transfer
gasPrice: await provider.getGasPrice(),
type: 0,
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
} as types.Eip712Meta
};
const signedTxHash = EIP712Signer.getSignedDigest(tx);
logCyan("1");
const multiSignature = ethers.utils.concat([
// Note, that `signMessage` wouldn't work here, since we don't want
// the signed hash to be prefixed with `\x19Ethereum Signed Message:\n`
ethers.utils.joinSignature(msOwner1._signingKey().signDigest(signedTxHash)),
ethers.utils.joinSignature(msOwner2._signingKey().signDigest(signedTxHash)),
]);
logCyan("1");
tx.customData = {
...tx.customData,
customSignature: multiSignature,
};
// Send the transaction to the multisig contract
const executeTx = await multisigContract.executeTransactionFromOutside(tx);
logCyan("1");
await executeTx.wait();
logCyan("1");

const balanceAfter = await provider.getBalance(wallet.address);
logCyan(`Wallet balance after sending funds: ${balanceAfter}`);
expect(balanceAfter.sub(balanceBefore)).to.equal(sendAmount);
const multiSigNonceAfter = await provider.getTransactionCount(multisigAddress);
logCyan(`Multisig nonce after sending funds: ${multiSigNonceAfter}`);
expect(multiSigNonceAfter).to.equal(multiSigNonceBefore 1);
});
});
16 changes: 16 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
import { Wallet } from "zksync-web3";
import * as ethers from "ethers";

export function logCyan(message: string) {
console.log("\x1b[36m%s\x1b[0m", " > " message);
}

export async function sendFunds(wallet: Wallet, multisigAddress: string, sendAmount: ethers.ethers.BigNumber) {
await (
await wallet.sendTransaction({
to: multisigAddress,
// You can increase the amount of ETH sent to the multisig
value: sendAmount,
})
).wait();
}

0 comments on commit a91c0d8

Please sign in to comment.