From bb74071284c5b913d087a4224c6dca8ff98a79c3 Mon Sep 17 00:00:00 2001 From: Anton Chaika <91263261+kevandee@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:05:50 +0200 Subject: [PATCH] fixed id for ValidatorInProposal entity (#143) * fixed id for ValidatorInProposal entity * fixed comments in schema --- DaoValidators/schema.graphql | 14 +++++------ .../src/entities/ValidatorInProposal.ts | 2 +- DaoValidators/tests/DaoValidators.test.ts | 24 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/DaoValidators/schema.graphql b/DaoValidators/schema.graphql index 38dbb4d4..2431a63c 100644 --- a/DaoValidators/schema.graphql +++ b/DaoValidators/schema.graphql @@ -3,7 +3,7 @@ The entity that holds informations about pool """ type DaoPool @entity { "The pool address" - id: Bytes! # pool address + id: Bytes! "Array of ValidatorInPool entity ids" validators: [ValidatorInPool!]! @derivedFrom(field: "pool") } @@ -13,7 +13,7 @@ The entity that holds informations about validators contract """ type ValidatorsContract @entity(immutable: true) { "The validators contract address" - id: Bytes! # validators contract address + id: Bytes! "The pool address" pool: Bytes! } @@ -23,7 +23,7 @@ The entity that holds informations about validators proposal """ type Proposal @entity { "id forms from pool address + proposalId + isInternal" - id: ID! # pool address + proposalId + isInternal + id: ID! "The id of proposal" proposalId: BigInt! "Boolean flag, if true - internal for validators" @@ -52,7 +52,7 @@ The entity that holds informations about validator's actions in pool """ type ValidatorInPool @entity { "id forms from the validator address + pool address" - id: Bytes! # validator address + pool address + id: Bytes! "The address of validator" validatorAddress: Bytes! "The amount of validators token" @@ -67,7 +67,7 @@ The entity that holds informations about vote """ type ProposalInteraction @entity(immutable: true) { "id forms from the tx hash + interactionCount" - id: Bytes! # tx hash + counter + id: Bytes! "The tx hash" hash: Bytes! "The timestamp of transaction" @@ -88,8 +88,8 @@ type ProposalInteraction @entity(immutable: true) { The entity that holds informations about vote """ type ValidatorInProposal @entity { - "id forms from the validator address + pool address + proposal id" - id: Bytes! # user address + pool address + proposal id + "id forms from the validator address + pool address + proposal id + isInternal" + id: Bytes! "The pool entity id" pool: DaoPool! "The proposal entity id" diff --git a/DaoValidators/src/entities/ValidatorInProposal.ts b/DaoValidators/src/entities/ValidatorInProposal.ts index b3438b65..00209272 100644 --- a/DaoValidators/src/entities/ValidatorInProposal.ts +++ b/DaoValidators/src/entities/ValidatorInProposal.ts @@ -2,7 +2,7 @@ import { BigInt } from "@graphprotocol/graph-ts"; import { Proposal, ValidatorInPool, ValidatorInProposal } from "../../generated/schema"; export function getValidatorInProposal(validator: ValidatorInPool, proposal: Proposal): ValidatorInProposal { - let id = validator.id.concatI32(proposal.proposalId.toI32()); + let id = validator.id.concatI32(proposal.proposalId.toI32()).concatI32(proposal.isInternal); let validatorInProposal = ValidatorInProposal.load(id); if (validatorInProposal == null) { diff --git a/DaoValidators/tests/DaoValidators.test.ts b/DaoValidators/tests/DaoValidators.test.ts index 5a819507..6b158198 100644 --- a/DaoValidators/tests/DaoValidators.test.ts +++ b/DaoValidators/tests/DaoValidators.test.ts @@ -400,13 +400,13 @@ describe("DaoValidators", () => { assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteAgainst", "0" ); assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteFor", vote.toString() ); @@ -434,7 +434,7 @@ describe("DaoValidators", () => { "ProposalInteraction", tx.hash.concatI32(0).toHexString(), "voter", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString() + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString() ); isVoteFor = false; @@ -446,13 +446,13 @@ describe("DaoValidators", () => { assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteAgainst", vote.toString() ); assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteFor", vote.toString() ); @@ -485,7 +485,7 @@ describe("DaoValidators", () => { "ProposalInteraction", nextTx.hash.concatI32(0).toHexString(), "voter", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString() + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString() ); }); @@ -502,13 +502,13 @@ describe("DaoValidators", () => { assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteAgainst", "0" ); assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteFor", vote.toString() ); @@ -536,7 +536,7 @@ describe("DaoValidators", () => { "ProposalInteraction", tx.hash.concatI32(0).toHexString(), "voter", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString() + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString() ); const nextTx = getNextTx(tx); @@ -546,13 +546,13 @@ describe("DaoValidators", () => { assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteAgainst", "0" ); assert.fieldEquals( "ValidatorInProposal", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString(), + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString(), "totalVoteFor", "0" ); @@ -585,7 +585,7 @@ describe("DaoValidators", () => { "ProposalInteraction", nextTx.hash.concatI32(0).toHexString(), "voter", - sender.concat(poolAddress).concatI32(proposalId.toI32()).toHexString() + sender.concat(poolAddress).concatI32(proposalId.toI32()).concatI32(isInternal).toHexString() ); });