Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
use hardhat helpers to impersonate Accounts Contract to send msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey authored and Andrey committed Jul 21, 2023
1 parent 3c8396f commit 5538016
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions test/core/IndexFund.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect} from "chai";
import hre from "hardhat";
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {impersonateAccount, setBalance} from "@nomicfoundation/hardhat-network-helpers";
import {
AccountsDepositWithdrawEndowments,
AccountsDepositWithdrawEndowments__factory,
Expand Down Expand Up @@ -317,29 +318,25 @@ describe("IndexFund", function () {
await indexFund.createIndexFund("Test Fund #1", "Test fund", [2, 3], true, 50, 0);
await indexFund.createIndexFund("Test Fund #2", "Test fund", [3], false, 50, 0);

// registrar config has the accounts contract set as owner (for ease of testing)
let {splitToLiquid, ...curConfig} = await registrar.queryConfig();
await registrar.updateConfig({
...curConfig,
accountsContract: owner.address,
splitMax: 100,
splitMin: 0,
splitDefault: 50,
collectorShare: 0,
});
});

it("reverts when the message sender is not the accounts contract", async function () {
expect(indexFund.removeMember(1)).to.be.revertedWith("Unauthorized");
});

it("passes with correct sender", async function () {
// create a signer for the Accounts contract to send msgs from
let regConfig = await registrar.queryConfig();
await impersonateAccount(regConfig.accountsContract);
await setBalance(regConfig.accountsContract, 1000000000000000000); // give it some gas money, as impersonateAccount does not
const acctSigner = await ethers.getSigner(regConfig.accountsContract);

// Endowment #1 should be invloved with two funds
let funds = await indexFund.queryInvolvedFunds(3);
expect(funds.length).to.equal(2);

// remove Endowment #1 from all funds
expect(await indexFund.connect(owner).removeMember(3)).to.emit(indexFund, "MemberRemoved");
expect(await indexFund.connect(acctSigner).removeMember(3)).to.emit(indexFund, "MemberRemoved");

// Endowment #1 should not be invloved with any funds now
funds = await indexFund.queryInvolvedFunds(3);
Expand Down

0 comments on commit 5538016

Please sign in to comment.