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

Commit

Permalink
add test & yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey authored and Andrey committed Jul 24, 2023
1 parent 716bc9d commit 82bf6f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
7 changes: 5 additions & 2 deletions contracts/core/index-fund/IndexFund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard {
// tokens must be transfered from the sender to this contract
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
// we give allowance to accounts contract
IERC20(token).safeApprove(registrarConfig.accountsContract, amount);
require(
IERC20(token).approve(registrarConfig.accountsContract, amount),
"Approval needed for Accounts Contract to spend"
);

if (fundId != 0) {
// Depositor has chosen a specific fund to send tokens to. Send 100% to that fund.
Expand Down Expand Up @@ -305,7 +308,7 @@ contract IndexFund is IIndexFund, Storage, OwnableUpgradeable, ReentrancyGuard {
);
} else if (state.config.fundRotation == 0 && state.config.fundingGoal > 0) {
// Fundraising Goal-based rotation of Funds
// Check if funding goal is met for current active fund and rotate funds
// Check if funding goal is met for current active fund and rotate funds
// until all donated tokens are depleted
uint256 loopDonation = 0;
uint256 goalLeftover = state.config.fundingGoal - state.roundDonations;
Expand Down
21 changes: 16 additions & 5 deletions test/core/IndexFund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ describe("IndexFund", function () {
);
});

it("reverts when amount donated, on a per endowment-basis for a fund, would be < 100 units", async function () {
expect(indexFund.depositERC20(1, token1.address, 100)).to.be.revertedWith(
"Amount must be greater than 100 units per endowment"
);
});

it("reverts when target fund is expired", async function () {
expect(indexFund.depositERC20(2, token1.address, 100)).to.be.revertedWith("Fund expired");
});
Expand Down Expand Up @@ -496,9 +502,11 @@ describe("IndexFund", function () {
expect(
await indexFund.depositERC20(4, token1.address, 500, {
gasPrice: 3000,
gasLimit: 10000000
gasLimit: 10000000,
})
).to.emit(indexFund, "DonationProcessed").withArgs(4);
)
.to.emit(indexFund, "DonationProcessed")
.withArgs(4);
});

it("passes for an active fund donation(amount-based rotation), amount > zero & token is valid", async function () {
Expand All @@ -511,11 +519,14 @@ describe("IndexFund", function () {
.to.emit("FundCreated")
.withArgs(5);

expect(await indexFund.depositERC20(0, token1.address, 10000, {
expect(
await indexFund.depositERC20(0, token1.address, 10000, {
gasPrice: 3000,
gasLimit: 10000000
gasLimit: 10000000,
})
).to.emit(indeFund, "DonationProcessed").withArgs(4);
)
.to.emit(indexFund, "DonationProcessed")
.withArgs(4);
});
});
});

0 comments on commit 82bf6f3

Please sign in to comment.