Skip to content

Commit

Permalink
Adds cap to Crowdfund params with tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesduncombe committed Feb 19, 2024
1 parent 6ba31fb commit aa41d1f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions contracts/fast/Crowdfund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ contract Crowdfund {
IERC20 token;
/// @notice An arbitrary reference string to keep track of.
string ref;
/// @notice The cap of the crowdfund if specified.
uint256 cap;
}

/// @notice A version identifier for us to track what's deployed.
Expand Down
13 changes: 11 additions & 2 deletions contracts/fast/FastCrowdfundsFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ contract FastCrowdfundsFacet is AFastFacet {
/**
* @notice Creates a crowdfund contract.
* @param token is the address of the ERC20 token that should be collected.
* @param beneficiary is the address that will receive the funds.
* @param ref is a reference for the crowdfund.
* @param cap is the maximum amount of tokens that can be collected (this is a hard cap).
*/
function createCrowdfund(IERC20 token, address beneficiary, string memory ref) external onlyGovernor(msg.sender) {
function createCrowdfund(
IERC20 token,
address beneficiary,
string memory ref,
uint256 cap
) external onlyGovernor(msg.sender) {
address issuer = FastTopFacet(address(this)).issuerAddress();
// Deploy a new Crowdfund contract.
Crowdfund crowdfund = new Crowdfund(
Expand All @@ -34,7 +42,8 @@ contract FastCrowdfundsFacet is AFastFacet {
beneficiary: beneficiary,
basisPointsFee: LibFastCrowdfunds.data().crowdfundsDefaultBasisPointsFee,
token: token,
ref: ref
ref: ref,
cap: cap
})
);
// Register our newly created crowdfund and keep track of it.
Expand Down
3 changes: 3 additions & 0 deletions test/fast/Crowdfund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe("Crowdfunds", () => {
fast: fast.address,
token: erc20.address,
ref: "Some reference",
cap: BigNumber.from(32_000_000_000)
};

deployCrowdfund = async (params) => {
Expand Down Expand Up @@ -128,6 +129,7 @@ describe("Crowdfunds", () => {
fast: validParams.fast,
token: validParams.token,
ref: validParams.ref,
cap: validParams.cap
});
});

Expand Down Expand Up @@ -167,6 +169,7 @@ describe("Crowdfunds", () => {
fast: validParams.fast,
token: validParams.token,
ref: validParams.ref,
cap: validParams.cap
});
});

Expand Down
32 changes: 24 additions & 8 deletions test/fast/FastCrowdfundsFacet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ describe("FastCrowdfundsFacet", () => {
const subject = crowdfunds.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 2_000_000
);
await expect(subject).to.have.revertedWith("RequiresFastGovernorship");
});
Expand All @@ -162,7 +163,8 @@ describe("FastCrowdfundsFacet", () => {
await crowdfundsAsGovernor.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 2_000_000
);
const [page] = await crowdfundsAsGovernor.paginateCrowdfunds(0, 1);
expect(page.length).to.eq(1);
Expand All @@ -175,7 +177,8 @@ describe("FastCrowdfundsFacet", () => {
await (tx = crowdfundsAsGovernor.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 310_000
));
const [crowdfundings] = await crowdfunds.paginateCrowdfunds(0, 1);
crowdfundAddr = crowdfundings[0];
Expand All @@ -191,15 +194,25 @@ describe("FastCrowdfundsFacet", () => {
crowdfundsAsGovernor.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 30_000
)
)
);
const [page] = await crowdfunds.paginateCrowdfunds(0, 10);
expect(page.length).to.eq(3);
});

it("sets the fee to the FAST-level default one");
it("sets the fee to the FAST-level default one", async () => {
const defaultFee = await crowdfunds.crowdfundsDefaultBasisPointFee();
const subject = await crowdfund.paramsStruct();
expect(subject.basisPointsFee).to.eq(defaultFee);
});

it("sets the cap to the passed cap amount", async () => {
const subject = await crowdfund.paramsStruct();
expect(subject.cap).to.eq(310_000);
});

it("emits a CrowdfundDeployed event", async () => {
await expect(tx)
Expand Down Expand Up @@ -227,7 +240,8 @@ describe("FastCrowdfundsFacet", () => {
await crowdfundsAsGovernor.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 300_000
);
});

Expand All @@ -253,7 +267,8 @@ describe("FastCrowdfundsFacet", () => {
await crowdfundsAsGovernor.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 300_000
);
});

Expand All @@ -268,7 +283,8 @@ describe("FastCrowdfundsFacet", () => {
await crowdfundsAsGovernor.createCrowdfund(
erc20.address,
alice.address,
"Blah"
"Blah",
/* cap */ 300_000
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { abiStructToObj } from "../utils";
chai.use(solidity);
chai.use(smock.matchers);

describe.only("MarketplaceFastDeploymentRequestsFacet", () => {
describe("MarketplaceFastDeploymentRequestsFacet", () => {
let deployer: SignerWithAddress,
issuerMember: SignerWithAddress,
alice: SignerWithAddress,
Expand Down

0 comments on commit aa41d1f

Please sign in to comment.