Skip to content

Commit

Permalink
added validatorrs voted field to Proposal entity
Browse files Browse the repository at this point in the history
  • Loading branch information
kevandee committed Dec 4, 2023
1 parent bb74071 commit 201bb3d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DaoValidators/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Proposal @entity {
"The percentage of total votes required to decide whether to confirm the proposal or not"
quorum: BigInt!

"The number of voted validators"
validatorsVoted: BigInt!

"The current number of votes for the proposal"
totalVoteFor: BigInt!
"The current number of votes against the proposal"
Expand Down
1 change: 1 addition & 0 deletions DaoValidators/src/entities/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function getProposal(
proposal.quorum = quorum;
proposal.totalVoteFor = BigInt.zero();
proposal.totalVoteAgainst = BigInt.zero();
proposal.validatorsVoted = BigInt.zero();
proposal.executor = Bytes.empty();
proposal.creator = creator;
}
Expand Down
2 changes: 2 additions & 0 deletions DaoValidators/src/entities/ValidatorInProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function getValidatorInProposal(validator: ValidatorInPool, proposal: Pro
validatorInProposal.totalVoteAgainst = BigInt.zero();

validatorInProposal.validator = validator.id;

proposal.validatorsVoted = proposal.validatorsVoted.plus(BigInt.fromI32(1));
}

return validatorInProposal;
Expand Down
2 changes: 2 additions & 0 deletions DaoValidators/src/mappings/DaoValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export function onVoteCanceled(event: VoteCanceled): void {
proposal.totalVoteAgainst = proposal.totalVoteAgainst.minus(validatorInProposal.totalVoteAgainst);
validatorInProposal.totalVoteAgainst = BigInt.zero();

proposal.validatorsVoted = proposal.validatorsVoted.minus(BigInt.fromI32(1));

vote.save();
validatorInProposal.save();
validatorInPool.save();
Expand Down
41 changes: 41 additions & 0 deletions DaoValidators/tests/DaoValidators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ describe("DaoValidators", () => {

onVoted(event);

assert.fieldEquals(
"Proposal",
poolAddress.toHexString() + proposalId.toString() + '_' + (isInternal ? '1' : '0'),
"validatorsVoted",
"1"
);

assert.fieldEquals(
"ValidatorInProposal",
sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(),
Expand Down Expand Up @@ -444,6 +451,13 @@ describe("DaoValidators", () => {

onVoted(event);

assert.fieldEquals(
"Proposal",
poolAddress.toHexString() + proposalId.toString() + '_' + (isInternal ? '1' : '0'),
"validatorsVoted",
"1"
);

assert.fieldEquals(
"ValidatorInProposal",
sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(),
Expand Down Expand Up @@ -487,6 +501,19 @@ describe("DaoValidators", () => {
"voter",
sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString()
);

sender = Address.fromString("0x86e08f7d84603AEb97cd1c89A80A9e914f181671");

event = createVoted(proposalId, sender, vote, isInternal, isVoteFor, contractSender, block, nextTx);

onVoted(event);

assert.fieldEquals(
"Proposal",
poolAddress.toHexString() + proposalId.toString() + '_' + (isInternal ? '1' : '0'),
"validatorsVoted",
"2"
);
});

test("should handle VoteCanceled", () => {
Expand Down Expand Up @@ -539,6 +566,13 @@ describe("DaoValidators", () => {
sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString()
);

assert.fieldEquals(
"Proposal",
poolAddress.toHexString() + proposalId.toString() + '_' + (isInternal ? '1' : '0'),
"validatorsVoted",
"1"
);

const nextTx = getNextTx(tx);
let event = createVoteCanceled(proposalId, sender, isInternal, contractSender, block, nextTx);

Expand Down Expand Up @@ -587,6 +621,13 @@ describe("DaoValidators", () => {
"voter",
sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString()
);

assert.fieldEquals(
"Proposal",
poolAddress.toHexString() + proposalId.toString() + '_' + (isInternal ? '1' : '0'),
"validatorsVoted",
"0"
);
});

test("should handle ChangedValidatorsBalances", () => {
Expand Down

0 comments on commit 201bb3d

Please sign in to comment.