Skip to content

Commit

Permalink
feat(backend): sponsorship queue
Browse files Browse the repository at this point in the history
refs #14
  • Loading branch information
jo-elimu committed Jun 27, 2024
1 parent bc15a27 commit 379a810
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions backend/contracts/SponsorshipQueue.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

struct Sponsorship {
uint256 estimatedCost;
uint256 timestamp;
address sponsor;
}

contract SponsorshipQueue {
address public owner;
uint256 public estimatedCost;
Sponsorship[] public sponsorships;

event OwnerUpdated(address owner);
event EstimatedCostUpdated(uint256 estimatedCost);
event SponsorshipAdded(Sponsorship sponsorship);

error OnlyOwner();

Expand All @@ -31,4 +39,15 @@ contract SponsorshipQueue {
estimatedCost = _estimatedCost;
emit EstimatedCostUpdated(_estimatedCost);
}

function addSponsorship() public payable {
payable(address(this)).send(msg.value);
Sponsorship memory sponsorship = Sponsorship(
msg.value,
block.timestamp,
msg.sender
);
sponsorships.push(sponsorship);
emit SponsorshipAdded(sponsorship);
}
}
9 changes: 9 additions & 0 deletions backend/test/SponsorshipQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ describe("SponsorshipQueue", function () {
.withArgs(newEstimatedCost);
});
});

describe("Sponsorships", function () {
it("Should emit an event on addSponsorship", async function () {
const { sponsorshipQueue } = await loadFixture(deployFixture);

await expect(sponsorshipQueue.addSponsorship())
.to.emit(sponsorshipQueue, "SponsorshipAdded");
});
});
});

0 comments on commit 379a810

Please sign in to comment.