diff --git a/test/main.test.ts b/test/main.test.ts index 1c38b35..f64b09d 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -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", @@ -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"); + }); }); }); }); diff --git a/test/utils.ts b/test/utils.ts index e7a2278..406ee2d 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -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 { + 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