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 Apr 22, 2024
1 parent a25d363 commit 9bf8cf7
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 @@ -185,6 +185,14 @@ contract Crowdfund is AHasContext {
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 @@ -261,6 +269,7 @@ contract Crowdfund is AHasContext {
uint256 collected;
uint256 feeAmount;
uint256 pledgerCount;
bool isCapped;
}

/**
Expand All @@ -277,7 +286,8 @@ contract Crowdfund is AHasContext {
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 @@ -286,6 +286,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 @@ -677,6 +691,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 9bf8cf7

Please sign in to comment.