Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] #137 implement newVoteReceived event on Fund contract #148

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ mod Fund {
self.state.write(FundStates::RECOLLECTING_VOTES);
}

// *************************************************************************
// EVENTS
// *************************************************************************
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
NewVoteReceived: NewVoteReceived
}

#[derive(Drop, starknet::Event)]
pub struct NewVoteReceived {
#[key]
pub voter: ContractAddress,
EmmanuelAR marked this conversation as resolved.
Show resolved Hide resolved
pub fund: ContractAddress,
pub votes: u32
}


// *************************************************************************
// EXTERNALS
// *************************************************************************
Expand Down Expand Up @@ -105,6 +123,15 @@ mod Fund {
if self.up_votes.read() >= FundConstants::UP_VOTES_NEEDED {
self.state.write(FundStates::RECOLLECTING_DONATIONS);
}

self
.emit(
NewVoteReceived {
voter: get_caller_address(),
fund: get_contract_address(),
votes: self.up_votes.read()
}
);
}
fn getUpVotes(self: @ContractState) -> u32 {
return self.up_votes.read();
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/test_fund_manager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ fn test_new_fund() {
let expected_fund_class_hash = get_class_hash(fund_manager_contract.getFund(1));
let current_id = fund_manager_contract.getCurrentId();
assert(expected_fund_class_hash == fund_class_hash, 'Invalid fund address');
assert(current_id == 2 , 'Invalid current ID');
assert(current_id == 2, 'Invalid current ID');
}
Loading