From 9bf8cf76341483d700423fded0beb56903b5ddc1 Mon Sep 17 00:00:00 2001 From: James Duncombe Date: Mon, 19 Feb 2024 17:27:17 +0000 Subject: [PATCH] Adds isCapped method and updates details struct. --- contracts/fast/Crowdfund.sol | 12 +++++++++++- test/fast/Crowdfund.test.ts | 31 ++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/contracts/fast/Crowdfund.sol b/contracts/fast/Crowdfund.sol index 72785bb..b880513 100644 --- a/contracts/fast/Crowdfund.sol +++ b/contracts/fast/Crowdfund.sol @@ -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. @@ -261,6 +269,7 @@ contract Crowdfund is AHasContext { uint256 collected; uint256 feeAmount; uint256 pledgerCount; + bool isCapped; } /** @@ -277,7 +286,8 @@ contract Crowdfund is AHasContext { creationBlock: creationBlock, collected: collected, feeAmount: feeAmount(), - pledgerCount: pledgerCount() + pledgerCount: pledgerCount(), + isCapped: isCapped() }); } diff --git a/test/fast/Crowdfund.test.ts b/test/fast/Crowdfund.test.ts index a9fec9d..849eb8c 100644 --- a/test/fast/Crowdfund.test.ts +++ b/test/fast/Crowdfund.test.ts @@ -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 () => { @@ -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 + }); + }); }); });