Skip to content

Commit

Permalink
chore: add failure expect test case
Browse files Browse the repository at this point in the history
  • Loading branch information
idea404 committed Nov 11, 2023
1 parent 1a66eeb commit 87268d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from "chai";
import * as hre from "hardhat";
import { ethers } from "ethers";
import * as zks from "zksync-web3";
import { deployFactory, deployMultisig, fundAccount, MultiSigWallet, deployPension } from "./utils";
import { deployFactory, deployMultisig, fundAccount, MultiSigWallet, deployPension, PensionWallet } from "./utils";

const config = {
firstWalletPrivateKey: "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110",
Expand Down Expand Up @@ -143,6 +143,31 @@ describe("Account Abstraction Tests", function () {
const btcInvestment = parseFloat(ethers.utils.formatEther(investmentDetails.btcInvestment));
expect(btcInvestment).to.equal(expectedInvestmentPerToken);
});

it("Should not be able to withdraw before the lockup period", async function () {
const pensionWallet = new PensionWallet(
pensionAccountContract.address,
ownerWallet.privateKey,
provider
);
const balanceBefore = (await provider.getBalance(ownerWallet.address)).toBigInt();
try {
const tx = await pensionWallet.transfer({
to: firstRichWallet.address,
amount: ethers.utils.parseUnits("10", 18),
overrides: { type: 113 },
});
tx.wait();
// expect to fail
expect(true).to.be.false;
} catch (e) {
expect(e.message).to.contains("execution reverted: Failed to pay for the transaction: Action locked until expiry time");
}
const balance = (await provider.getBalance(ownerWallet.address)).toBigInt();
const difference = balanceBefore - balance;
// expect no difference
expect(difference.toString().substring(0, 2)).to.equal("0");
});
});
});
});
29 changes: 29 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@ export class MultiSigWallet extends Wallet {
}
}

// Temporary wallet for testing - that is accepting one private key - and signs the transaction with it.
export class PensionWallet extends Wallet {
readonly accountAddress: string;
otherWallet: Wallet;

// accountAddress - is the account abstraction address for which, we'll use the private key to sign transactions.
constructor(
accountAddress: string,
privateKey: string,
providerL2: Provider,
) {
super(privateKey, providerL2);
this.accountAddress = accountAddress;
}

getAddress(): Promise<string> {
return Promise.resolve(this.accountAddress);
}

async signTransaction(transaction: types.TransactionRequest) {
const sig1 = await this.eip712.sign(transaction);
if (transaction.customData === undefined) {
throw new Error("Transaction customData is undefined");
}
transaction.customData.customSignature = sig1;
return (0, utils.serialize)(transaction);
}
}

function createMockAddress(base: string) {
const baseHex = base.replace(/[^0-9A-Fa-f]/g, ''); // Remove non-hex characters
const paddingLength = 40 - baseHex.length; // Calculate padding length
Expand Down

0 comments on commit 87268d7

Please sign in to comment.