diff --git a/DaoValidators/schema.graphql b/DaoValidators/schema.graphql index 2431a63..6573a97 100644 --- a/DaoValidators/schema.graphql +++ b/DaoValidators/schema.graphql @@ -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" diff --git a/DaoValidators/src/entities/Proposal.ts b/DaoValidators/src/entities/Proposal.ts index c90e02c..221b042 100644 --- a/DaoValidators/src/entities/Proposal.ts +++ b/DaoValidators/src/entities/Proposal.ts @@ -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; } diff --git a/DaoValidators/src/entities/ValidatorInProposal.ts b/DaoValidators/src/entities/ValidatorInProposal.ts index 0020927..63d9ba4 100644 --- a/DaoValidators/src/entities/ValidatorInProposal.ts +++ b/DaoValidators/src/entities/ValidatorInProposal.ts @@ -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; diff --git a/DaoValidators/src/mappings/DaoValidators.ts b/DaoValidators/src/mappings/DaoValidators.ts index 39f6e44..00f1d5f 100644 --- a/DaoValidators/src/mappings/DaoValidators.ts +++ b/DaoValidators/src/mappings/DaoValidators.ts @@ -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(); diff --git a/DaoValidators/tests/DaoValidators.test.ts b/DaoValidators/tests/DaoValidators.test.ts index 6b15819..83730b4 100644 --- a/DaoValidators/tests/DaoValidators.test.ts +++ b/DaoValidators/tests/DaoValidators.test.ts @@ -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(), @@ -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(), @@ -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", () => { @@ -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); @@ -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", () => {