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

added validatorrs voted field to Proposal entity #144

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
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