diff --git a/backend/contracts/SponsorshipProgram.sol b/backend/contracts/SponsorshipProgram.sol index c0a52db..c365162 100644 --- a/backend/contracts/SponsorshipProgram.sol +++ b/backend/contracts/SponsorshipProgram.sol @@ -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(); @@ -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); } } diff --git a/backend/test/SponsorshipProgram.ts b/backend/test/SponsorshipProgram.ts index be19cdd..4a19cb8 100644 --- a/backend/test/SponsorshipProgram.ts +++ b/backend/test/SponsorshipProgram.ts @@ -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 () { @@ -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); + }); + }); });