73 lines
2.9 KiB
TypeScript
73 lines
2.9 KiB
TypeScript
import { expect } from "chai";
|
|
import { ethers } from "hardhat";
|
|
import { SubAccountFactory, TreasuryWallet } from "../typechain-types";
|
|
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
|
|
|
|
describe("SubAccountFactory", function () {
|
|
let factory: SubAccountFactory;
|
|
let treasury: TreasuryWallet;
|
|
let owner1: SignerWithAddress;
|
|
let owner2: SignerWithAddress;
|
|
|
|
beforeEach(async function () {
|
|
[owner1, owner2] = await ethers.getSigners();
|
|
|
|
// Deploy factory
|
|
const FactoryFactory = await ethers.getContractFactory("SubAccountFactory");
|
|
factory = await FactoryFactory.deploy();
|
|
await factory.waitForDeployment();
|
|
|
|
// Deploy parent treasury
|
|
const TreasuryFactory = await ethers.getContractFactory("TreasuryWallet");
|
|
treasury = await TreasuryFactory.deploy([owner1.address, owner2.address], 2);
|
|
await treasury.waitForDeployment();
|
|
});
|
|
|
|
describe("Sub-Account Creation", function () {
|
|
it("Should create a sub-account", async function () {
|
|
const metadataHash = ethers.id("test-sub-account");
|
|
const tx = await factory.createSubAccount(await treasury.getAddress(), metadataHash);
|
|
const receipt = await tx.wait();
|
|
|
|
const subAccounts = await factory.getSubAccounts(await treasury.getAddress());
|
|
expect(subAccounts.length).to.equal(1);
|
|
expect(await factory.isSubAccount(subAccounts[0])).to.be.true;
|
|
});
|
|
|
|
it("Should create multiple sub-accounts for same treasury", async function () {
|
|
const hash1 = ethers.id("sub-account-1");
|
|
const hash2 = ethers.id("sub-account-2");
|
|
|
|
await factory.createSubAccount(await treasury.getAddress(), hash1);
|
|
await factory.createSubAccount(await treasury.getAddress(), hash2);
|
|
|
|
const subAccounts = await factory.getSubAccounts(await treasury.getAddress());
|
|
expect(subAccounts.length).to.equal(2);
|
|
});
|
|
|
|
it("Should return correct parent treasury", async function () {
|
|
const metadataHash = ethers.id("test");
|
|
await factory.createSubAccount(await treasury.getAddress(), metadataHash);
|
|
|
|
const subAccounts = await factory.getSubAccounts(await treasury.getAddress());
|
|
const parent = await factory.getParentTreasury(subAccounts[0]);
|
|
expect(parent).to.equal(await treasury.getAddress());
|
|
});
|
|
|
|
it("Should inherit owners from parent treasury", async function () {
|
|
const metadataHash = ethers.id("test");
|
|
await factory.createSubAccount(await treasury.getAddress(), metadataHash);
|
|
|
|
const subAccounts = await factory.getSubAccounts(await treasury.getAddress());
|
|
const subAccount = await ethers.getContractAt("TreasuryWallet", subAccounts[0]);
|
|
|
|
const owners = await subAccount.getOwners();
|
|
expect(owners.length).to.equal(2);
|
|
expect(owners[0]).to.equal(owner1.address);
|
|
expect(owners[1]).to.equal(owner2.address);
|
|
expect(await subAccount.threshold()).to.equal(2);
|
|
});
|
|
});
|
|
});
|
|
|