Skip to content

Commit

Permalink
feat(backend): set sponsorship cost
Browse files Browse the repository at this point in the history
refs #10
  • Loading branch information
jo-elimu committed Jun 27, 2024
1 parent f0ba348 commit 56d98fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
16 changes: 8 additions & 8 deletions backend/contracts/SponsorshipProgram.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity ^0.8.24;

/**
* A system for sponsoring the education of one individual child.
* Education sponsorship program, for delivering education to out-of-school children.
*/
contract SponsorshipProgram {
address public owner;
uint256 public sponsorshipCost;
uint256 public estimatedCost;

event SponsorshipCostUpdated(uint256 amount);
event EstimatedCostUpdated(uint256 amount);

error OnlyOwner();

Expand All @@ -19,13 +19,13 @@ contract SponsorshipProgram {
_;
}

constructor(uint256 _sponsorshipCost) {
constructor(uint256 _estimatedCost) {
owner = msg.sender;
sponsorshipCost = _sponsorshipCost;
estimatedCost = _estimatedCost;
}

function updateSponsorshipCost(uint256 amount) public onlyOwner {
sponsorshipCost = amount;
emit SponsorshipCostUpdated(amount);
function updateEstimatedCost(uint256 amount) public onlyOwner {
estimatedCost = amount;
emit EstimatedCostUpdated(amount);
}
}
20 changes: 16 additions & 4 deletions backend/test/SponsorshipProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ describe("SponsorshipProgram", function () {
// Contracts are deployed using the first signer/account by default
const [owner, otherAccount] = await hre.ethers.getSigners();

const sponsorshipCost = hre.ethers.parseUnits("0.02");
const estimatedCost = hre.ethers.parseUnits("0.02");

const SponsorshipProgram = await hre.ethers.getContractFactory("SponsorshipProgram");
const sponsorshipProgram = await SponsorshipProgram.deploy(sponsorshipCost);
const sponsorshipProgram = await SponsorshipProgram.deploy(estimatedCost);

return { sponsorshipProgram, owner, otherAccount };
}

describe("Deployment", function () {
it("Should set the right sponshorship cost", async function () {
it("Should set the right estimated cost", async function () {
const { sponsorshipProgram } = await loadFixture(deployFixture);

const expectedValue = hre.ethers.parseUnits("0.02");
console.log("expectedValue:", expectedValue);
expect(await sponsorshipProgram.sponsorshipCost()).to.equal(expectedValue);
expect(await sponsorshipProgram.estimatedCost()).to.equal(expectedValue);
});

it("Should set the right owner", async function () {
Expand All @@ -35,4 +35,16 @@ describe("SponsorshipProgram", function () {
expect(await sponsorshipProgram.owner()).to.equal(owner.address);
});
});

describe("EstimatedCost", function () {
it("Should emit an event on update", async function () {
const { sponsorshipProgram } = await loadFixture(deployFixture);

const newEstimatedCost = hre.ethers.parseUnits("0.03");
console.log("newEstimatedCost:", newEstimatedCost);
await expect(sponsorshipProgram.updateEstimatedCost(newEstimatedCost))
.to.emit(sponsorshipProgram, "EstimatedCostUpdated")
.withArgs(newEstimatedCost);
});
});
});

0 comments on commit 56d98fc

Please sign in to comment.