Skip to content

Commit

Permalink
Adds isCapped method and updates details struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Feb 19, 2024
1 parent 02770d2 commit 0e364de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
12 changes: 11 additions & 1 deletion contracts/fast/Crowdfund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ contract Crowdfund {
return pledgerSet.values.length;
}

/**
* @notice Queries whether the crowdfund is capped or not.
* @return A `boolean`.
*/
function isCapped() public view returns (bool) {
return params.cap > 0;
}

/**
* @notice Queries pages of pledgers based on a start index and a page size.
* @param index is the offset at which the pagination operation should start.
Expand Down Expand Up @@ -247,6 +255,7 @@ contract Crowdfund {
uint256 collected;
uint256 feeAmount;
uint256 pledgerCount;
bool isCapped;
}

/**
Expand All @@ -263,7 +272,8 @@ contract Crowdfund {
creationBlock: creationBlock,
collected: collected,
feeAmount: feeAmount(),
pledgerCount: pledgerCount()
pledgerCount: pledgerCount(),
isCapped: isCapped()
});
}

Expand Down
31 changes: 30 additions & 1 deletion test/fast/Crowdfund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,20 @@ describe("Crowdfunds", () => {
});
});

describe("isCapped", () => {
it("returns false if the cap is not set", async () => {
await deployCrowdfund({ ...validParams, cap: 0 });
const subject = await crowdfund.isCapped();
expect(subject).to.be.false;
});

it("returns true if the cap is set", async () => {
await deployCrowdfund({ ...validParams, cap: 10_000_000_000_000 });
const subject = await crowdfund.isCapped();
expect(subject).to.be.true;
});
});

describe("advanceToFunding", () => {
describe("from an invalid phase", () => {
it("reverts", async () => {
Expand Down Expand Up @@ -627,6 +641,21 @@ describe("Crowdfunds", () => {
});

describe("details", () => {
it("MUST BE TESTED");
it("returns a details struct", async () => {
await deployCrowdfund(validParams);
const subject = await crowdfund.details();
const obj = abiStructToObj(subject);
expect(obj).to.eql({
addr: crowdfund.address,
VERSION: 3,
params: await crowdfund.paramsStruct(),
phase: CrowdFundPhase.Setup,
creationBlock: await crowdfund.creationBlock(),
collected: BigNumber.from(0),
feeAmount: BigNumber.from(0),
pledgerCount: BigNumber.from(0),
isCapped: true
});
});
});
});

0 comments on commit 0e364de

Please sign in to comment.