From e76ee76a871f62cd9c510f18a07f491edcb88d2d Mon Sep 17 00:00:00 2001 From: Juan Diego Carballo Date: Wed, 30 Oct 2024 13:52:00 -0600 Subject: [PATCH] feat: add fund test event emit --- contracts/src/fund.cairo | 4 ++-- contracts/tests/test_fund.cairo | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index 4b9af43..00f0b34 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -21,7 +21,7 @@ pub trait IFund { } #[starknet::contract] -mod Fund { +pub mod Fund { // ************************************************************************* // IMPORT // ************************************************************************* @@ -41,7 +41,7 @@ mod Fund { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { DonationWithdraw: DonationWithdraw, NewVoteReceived: NewVoteReceived, DonationReceived: DonationReceived, diff --git a/contracts/tests/test_fund.cairo b/contracts/tests/test_fund.cairo index 248151a..d23d503 100644 --- a/contracts/tests/test_fund.cairo +++ b/contracts/tests/test_fund.cairo @@ -6,12 +6,14 @@ use starknet::syscalls::call_contract_syscall; use snforge_std::{ declare, ContractClassTrait, start_cheat_caller_address_global, start_cheat_caller_address, - cheat_caller_address, CheatSpan + cheat_caller_address, CheatSpan, spy_events, EventSpyAssertionsTrait }; use openzeppelin::utils::serde::SerializedAppend; use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; + +use gostarkme::fund::Fund; use gostarkme::fund::IFundDispatcher; use gostarkme::fund::IFundDispatcherTrait; use gostarkme::constants::{funds::{fund_manager_constants::FundManagerConstants},}; @@ -189,3 +191,29 @@ fn test_set_goal_unauthorized() { // Change the goal without being the fund manager dispatcher.setGoal(22); } + + +#[test] +fn test_new_vote_received_event_emitted_successful() { + let contract_address = _setup_(); + let dispatcher = IFundDispatcher { contract_address }; + + let mut spy = spy_events(); + + start_cheat_caller_address(contract_address, OTHER_USER()); + dispatcher.receiveVote(); + + spy + .assert_emitted( + @array![ + ( + contract_address, + Fund::Event::NewVoteReceived( + Fund::NewVoteReceived { + voter: OTHER_USER(), fund: contract_address, votes: 1 + } + ) + ) + ] + ); +}