Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions packages/contracts/contracts/Tally.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ contract Tally is Clone, SnarkCommon, Hasher, DomainObjs, ITally {
// spent field retrieved in the totalSpentVoiceCredits object
uint256 public totalSpent;

/// @notice events
event ResultAdded(uint256 indexed voteOptionIndex, uint256 indexed tallyResult);

/// @notice custom errors
error ProcessingNotComplete();
error InvalidTallyVotesProof();
Expand Down Expand Up @@ -420,5 +423,7 @@ contract Tally is Clone, SnarkCommon, Hasher, DomainObjs, ITally {
}

previous.value = _tallyResult;

emit ResultAdded(_voteOptionIndex, _tallyResult);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea but should the event be emitted on addTallyResults rather than addTallyResult ? My understanding is that the coordinator calls once addTallyResults and then addTallyResult is called multiple times internally.

I feel it might be more helpful to get an event after all results have been tallied rather than on every execution of partial results tallying 😊

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addTallyResults won't be called once. It can be called multiple times.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xmad so is it better to emit the event in addTallyResult or in addTallyResults?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use it in addTallyResult to use it simplier with subgraph.

}
}
11 changes: 10 additions & 1 deletion packages/contracts/tests/Tally.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ describe("VoteTally", function test() {
expect(initialTotalResults).to.equal(tallyData.results.tally.length);
expect(initialResults.map((result) => result.value)).to.deep.equal(tallyData.results.tally);

await tallyContract
const receipt = await tallyContract
.addTallyResults({
voteOptionIndices: indices,
tallyResults: tallyData.results.tally,
Expand All @@ -487,6 +487,15 @@ describe("VoteTally", function test() {
})
.then((tx) => tx.wait());

const [event] = await tallyContract.queryFilter(
tallyContract.filters.ResultAdded,
receipt?.blockNumber,
receipt?.blockNumber,
);

expect(event.args[0].toString()).to.eq(indices[0].toString());
expect(event.args[1].toString()).to.eq(tallyData.results.tally[0].toString());

const results = await Promise.all(indices.map((index) => tallyContract.getTallyResults(index)));
const totalResults = await tallyContract.totalTallyResults();

Expand Down
Loading