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"); + }); + }); });