From 379a810eb2f0404a85f3caf58929912f0b6d6575 Mon Sep 17 00:00:00 2001 From: jo-elimu <1451036+jo-elimu@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:32:27 +0700 Subject: [PATCH] feat(backend): sponsorship queue refs #14 --- backend/contracts/SponsorshipQueue.sol | 19 +++++++++++++++++++ backend/test/SponsorshipQueue.ts | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/backend/contracts/SponsorshipQueue.sol b/backend/contracts/SponsorshipQueue.sol index fee240f..94cfe88 100644 --- a/backend/contracts/SponsorshipQueue.sol +++ b/backend/contracts/SponsorshipQueue.sol @@ -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(); @@ -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); + } } diff --git a/backend/test/SponsorshipQueue.ts b/backend/test/SponsorshipQueue.ts index 70adce8..af3d9ac 100644 --- a/backend/test/SponsorshipQueue.ts +++ b/backend/test/SponsorshipQueue.ts @@ -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"); + }); + }); });