From 671071c2e3f2d09e774e42f0e9c86952b6a6cecb Mon Sep 17 00:00:00 2001 From: Claudia Date: Wed, 10 Apr 2024 18:57:55 +0200 Subject: [PATCH 01/25] feat: manage the voting mode indexes to set an Undefined mode when the provided index is not defined --- packages/subgraph/src/plugin/plugin.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index dfc98d8e..662851f2 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -70,7 +70,13 @@ export function _handleProposalCreated( // ProposalParameters const parameters = proposal.value.value2; - const votingMode = VOTING_MODES.get(parameters.votingMode); + let votingModeIndex = parameters.votingMode; + if (!VOTING_MODES.has(votingModeIndex)) { + // if the voting mode is not defined, set it to 'Undefined' + votingModeIndex = 10; + } + + const votingMode = VOTING_MODES.get(votingModeIndex); proposalEntity.votingMode = votingMode as string; proposalEntity.supportThreshold = parameters.supportThreshold; @@ -264,8 +270,13 @@ export function handleVotingSettingsUpdated( generatePluginEntityId(event.address) ); if (pluginEntity) { - const votingMode = VOTING_MODES.get(event.params.votingMode); + let votingModeIndex = event.params.votingMode; + if (!VOTING_MODES.has(votingModeIndex)) { + // if the voting mode is not defined, set it to 'Undefined' + votingModeIndex = 10; + } + const votingMode = VOTING_MODES.get(votingModeIndex); pluginEntity.votingMode = votingMode as string; pluginEntity.supportThreshold = event.params.supportThreshold; pluginEntity.minParticipation = event.params.minParticipation; From 2c1f7776241fdff7b9d6bd9ca63e8fe3595bd556 Mon Sep 17 00:00:00 2001 From: Claudia Date: Wed, 10 Apr 2024 18:59:33 +0200 Subject: [PATCH 02/25] feat: remove VOTING_MODE_INDEXES because is not longer needed and add new Undefined mode --- packages/subgraph/src/utils/constants.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/subgraph/src/utils/constants.ts b/packages/subgraph/src/utils/constants.ts index 1b7e108b..e11b9cbd 100644 --- a/packages/subgraph/src/utils/constants.ts +++ b/packages/subgraph/src/utils/constants.ts @@ -39,12 +39,8 @@ export const VOTE_OPTIONS = new Map() export const VOTING_MODES = new Map() .set(0, 'Standard') .set(1, 'EarlyExecution') - .set(2, 'VoteReplacement'); - -export const VOTING_MODE_INDEXES = new Map() - .set('Standard', '0') - .set('EarlyExecution', '1') - .set('VoteReplacement', '2'); + .set(2, 'VoteReplacement') + .set(10, 'Undefined'); export const TOKEN_VOTING_INTERFACE_ID = '0x50eb001e'; export const ADDRESSLIST_VOTING_INTERFACE_ID = '0x5f21eb8b'; From 1c456aa6577939c284a370359ded2942ffe85c34 Mon Sep 17 00:00:00 2001 From: Claudia Date: Wed, 10 Apr 2024 19:01:34 +0200 Subject: [PATCH 03/25] feat: update the extended method classes to properly manage with the undefined voting mode --- .../subgraph/tests/helpers/method-classes.ts | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index 03d65252..8c4c4cdb 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -28,7 +28,6 @@ import { VOTER_OPTIONS, VOTE_OPTIONS, VOTING_MODES, - VOTING_MODE_INDEXES, } from '../../src/utils/constants'; import {generateMemberEntityId} from '../../src/utils/ids'; import { @@ -187,7 +186,11 @@ class TokenVotingVoterMethods extends TokenVotingVoter { } class TokenVotingProposalMethods extends TokenVotingProposal { - withDefaultValues(): TokenVotingProposalMethods { + votingModeIndex: string = VOTING_MODE; + + withDefaultValues( + votingModeIndex: string = VOTING_MODE + ): TokenVotingProposalMethods { this.id = PROPOSAL_ENTITY_ID; this.daoAddress = Bytes.fromHexString(DAO_ADDRESS); @@ -198,7 +201,12 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.open = true; this.executed = false; - this.votingMode = VOTING_MODE; + // for event we need the index of the mapping to simulate the contract event + this.votingModeIndex = votingModeIndex; + this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) + ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) + : (VOTING_MODES.get(10) as string); + this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minVotingPower = BigInt.fromString(MIN_VOTING_POWER); this.startDate = BigInt.fromString(START_DATE); @@ -231,7 +239,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.pluginProposalId.toString(), this.open, this.executed, - this.votingMode, + this.votingModeIndex as string, // we need the index for this mocked call this.supportThreshold.toString(), this.minVotingPower.toString(), this.startDate.toString(), @@ -360,24 +368,24 @@ class TokenVotingVoteMethods extends TokenVotingVote { } class TokenVotingPluginMethods extends TokenVotingPlugin { + votingModeIndex: string = VOTING_MODE; // build entity // if id not changed it will update - withDefaultValues(): TokenVotingPluginMethods { - let votingModeIndex = parseInt(VOTING_MODE); - if (!VOTING_MODES.has(votingModeIndex)) { - throw new Error('voting mode is not valid.'); - } - - // we use casting here to remove autocompletion complaint - // since we know it will be captured by the previous check - let votingMode = VOTING_MODES.get(votingModeIndex) as string; + withDefaultValues( + votingModeIndex: string = VOTING_MODE + ): TokenVotingPluginMethods { const pluginAddress = Address.fromString(CONTRACT_ADDRESS); const pluginEntityId = generatePluginEntityId(pluginAddress); this.id = pluginEntityId; this.daoAddress = Bytes.fromHexString(DAO_ADDRESS); this.pluginAddress = pluginAddress; - this.votingMode = votingMode; + + this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event + this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) + ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) + : (VOTING_MODES.get(10) as string); + this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minParticipation = BigInt.fromString(MIN_PARTICIPATION); this.minDuration = BigInt.fromString(MIN_DURATION); @@ -396,22 +404,8 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { } createEvent_VotingSettingsUpdated(): VotingSettingsUpdated { - if (this.votingMode === null) { - throw new Error('Voting mode is null.'); - } - - // we cast to string only for stoping rust compiler complaints. - let votingMode: string = this.votingMode as string; - if (!VOTING_MODE_INDEXES.has(votingMode)) { - throw new Error('Voting mode index is not valid.'); - } - - // we use casting here to remove autocompletion complaint - // since we know it will be captured by the previous check - let votingModeIndex = VOTING_MODE_INDEXES.get(votingMode) as string; - let event = createNewVotingSettingsUpdatedEvent( - votingModeIndex, // for event we need the index of the mapping to simulate the contract event + this.votingModeIndex as string, // we need the index for simulate the event (this.supportThreshold as BigInt).toString(), (this.minParticipation as BigInt).toString(), (this.minDuration as BigInt).toString(), @@ -435,7 +429,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { } setNewPluginSetting( - newVotingMode: string = VOTING_MODES.get(parseInt(TWO)) as string, + votingModeIndex: string = TWO, newSupportThreshold: BigInt = BigInt.fromString(NEW_SUPPORT_THRESHOLD), newMinParticipation: BigInt = BigInt.fromString(NEW_MIN_PARTICIPATION), newMinDuration: BigInt = BigInt.fromString(NEW_MIN_DURATION), @@ -443,8 +437,10 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { NEW_MIN_PROPOSER_VOTING_POWER ) ): TokenVotingPluginMethods { - let votingMode = newVotingMode; - this.votingMode = votingMode; + this.votingModeIndex = votingModeIndex; + this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) + ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) + : (VOTING_MODES.get(10) as string); this.supportThreshold = newSupportThreshold; this.minParticipation = newMinParticipation; this.minDuration = newMinDuration; From e088648928d18eba2df25881518dc5da37dd9bc3 Mon Sep 17 00:00:00 2001 From: Claudia Date: Wed, 10 Apr 2024 19:03:02 +0200 Subject: [PATCH 04/25] feat: modify the extender to also generate the class extended properties --- packages/subgraph/tests/schema-extender.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/subgraph/tests/schema-extender.ts b/packages/subgraph/tests/schema-extender.ts index 149915fb..9ec34770 100644 --- a/packages/subgraph/tests/schema-extender.ts +++ b/packages/subgraph/tests/schema-extender.ts @@ -70,6 +70,19 @@ function main() { // add methods to generated classes sourceMethodClasses.forEach(classDeclaration => { if (classDeclaration.getName() === `${originalClassName}Methods`) { + const properties = classDeclaration.getProperties(); + properties.forEach(property => { + newClass.addProperty( + property.getStructure() as { + name: string; + type: string; + hasQuestionToken: boolean; + initializer: string; + decorators: {name: string; arguments: string[]}[]; + } + ); + }); + const methods = classDeclaration.getMethods(); methods.forEach(method => { From 99ea005eac7e9f62ccdc2d57ab7c97421b175c5a Mon Sep 17 00:00:00 2001 From: Claudia Date: Wed, 10 Apr 2024 19:45:09 +0200 Subject: [PATCH 05/25] feat: add test for the checking it works when an undefined voting mode is emitted --- packages/subgraph/tests/plugin/plugin.test.ts | 179 +++++++++++++----- 1 file changed, 128 insertions(+), 51 deletions(-) diff --git a/packages/subgraph/tests/plugin/plugin.test.ts b/packages/subgraph/tests/plugin/plugin.test.ts index 8bf0c9c7..15bc0217 100644 --- a/packages/subgraph/tests/plugin/plugin.test.ts +++ b/packages/subgraph/tests/plugin/plugin.test.ts @@ -27,60 +27,115 @@ import { import {bigInt, BigInt} from '@graphprotocol/graph-ts'; import { afterAll, + afterEach, assert, clearStore, describe, test, } from 'matchstick-as/assembly/index'; -test('Run TokenVoting (handleProposalCreated) mappings with mock event', () => { - // check store is empty before running the test - assert.entityCount('TokenVotingPlugin', 0); - assert.entityCount('TokenVotingProposal', 0); - assert.entityCount('Action', 0); +describe('handleProposalCreated', () => { + afterEach(() => { + clearStore(); + }); - // create state - let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues(); - tokenVotingPlugin.buildOrUpdate(); - // assert with default value - // eg. proposalCount is `0`. - tokenVotingPlugin.assertEntity(); + test('it should create the plugin, proposal and actions', () => { + // check store is empty before running the test + assert.entityCount('TokenVotingPlugin', 0); + assert.entityCount('TokenVotingProposal', 0); + assert.entityCount('Action', 0); - let proposal = new ExtendedTokenVotingProposal().withDefaultValues(); + // create state + let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues(); + tokenVotingPlugin.buildOrUpdate(); + // assert with default value + // eg. proposalCount is `0`. + tokenVotingPlugin.assertEntity(); - let action = new ExtendedAction().withDefaultValues(); + let proposal = new ExtendedTokenVotingProposal().withDefaultValues(); + let action = new ExtendedAction().withDefaultValues(); - // create calls - tokenVotingPlugin.proposalCount = BigInt.fromString(ONE); - tokenVotingPlugin.mockCall_getProposalCountCall(); - proposal.mockCall_getProposal([action.getDummyAction()]); - proposal.mockCall_totalVotingPower(); + // create calls + tokenVotingPlugin.proposalCount = BigInt.fromString(ONE); + tokenVotingPlugin.mockCall_getProposalCountCall(); + proposal.mockCall_getProposal([action.getDummyAction()]); + proposal.mockCall_totalVotingPower(); - // create event - let event = proposal.createEvent_ProposalCreated( - [action.getDummyAction()], - STRING_DATA - ); + // create event + let event = proposal.createEvent_ProposalCreated( + [action.getDummyAction()], + STRING_DATA + ); - // handle event - _handleProposalCreated(event, proposal.daoAddress.toHexString(), STRING_DATA); + // handle event + _handleProposalCreated( + event, + proposal.daoAddress.toHexString(), + STRING_DATA + ); - // checks - // expected changes - proposal.creationBlockNumber = BigInt.fromString(ONE); - proposal.votingMode = VOTING_MODES.get(parseInt(VOTING_MODE)) as string; + // checks + // expected changes + proposal.creationBlockNumber = BigInt.fromString(ONE); + proposal.votingMode = VOTING_MODES.get(parseInt(VOTING_MODE)) as string; - // check the proposal and the plugin - assert.entityCount('TokenVotingPlugin', 1); - assert.entityCount('TokenVotingProposal', 1); - proposal.assertEntity(); - tokenVotingPlugin.assertEntity(); + // check the proposal and the plugin + assert.entityCount('TokenVotingPlugin', 1); + assert.entityCount('TokenVotingProposal', 1); + proposal.assertEntity(); + tokenVotingPlugin.assertEntity(); + + // check the actions + assert.entityCount('Action', 1); + action.assertEntity(); + }); - // check the actions - assert.entityCount('Action', 1); - action.assertEntity(); + test('it should create the plugin, proposal and actions (with Undefined VotingMode)', () => { + // check store is empty before running the test + assert.entityCount('TokenVotingPlugin', 0); + assert.entityCount('TokenVotingProposal', 0); + assert.entityCount('Action', 0); - clearStore(); + // create state + let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues( + '11' + ); + tokenVotingPlugin.buildOrUpdate(); + + // check before handle event + tokenVotingPlugin.assertEntity(); + + let proposal = new ExtendedTokenVotingProposal().withDefaultValues('11'); + let action = new ExtendedAction().withDefaultValues(); + + // create event + let event = proposal.createEvent_ProposalCreated( + [action.getDummyAction()], + STRING_DATA + ); + + // handle event + _handleProposalCreated( + event, + proposal.daoAddress.toHexString(), + STRING_DATA + ); + + // check the proposal and the plugin + assert.entityCount('TokenVotingPlugin', 1); + assert.entityCount('TokenVotingProposal', 1); + + proposal.creationBlockNumber = BigInt.fromString(ONE); + proposal.votingMode = VOTING_MODES.get(parseInt(VOTING_MODE)) as string; + proposal.assertEntity(); + + tokenVotingPlugin.proposalCount = BigInt.fromString(ONE); + tokenVotingPlugin.assertEntity(); + + // check the actions + assert.entityCount('Action', 1); + action.assertEntity(); + }); }); test('Run TokenVoting (handleVoteCast) mappings with mock event', () => { @@ -257,24 +312,46 @@ test('Run TokenVoting (handleProposalExecuted) mappings with mock event', () => clearStore(); }); -test('Run TokenVoting (handleVotingSettingsUpdated) mappings with mock event', () => { - // create state - let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues(); - tokenVotingPlugin.buildOrUpdate(); +describe('handleVotingSettingsUpdated', () => { + afterAll(() => { + clearStore(); + }); - // update plugin configuration - tokenVotingPlugin.setNewPluginSetting(); + test('it should update the plugin setting', () => { + // create state + let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues(); + tokenVotingPlugin.buildOrUpdate(); - // create event - let event = tokenVotingPlugin.createEvent_VotingSettingsUpdated(); + // update plugin configuration + tokenVotingPlugin.setNewPluginSetting(); - // handle event - handleVotingSettingsUpdated(event); + // create event + let event = tokenVotingPlugin.createEvent_VotingSettingsUpdated(); - // checks - tokenVotingPlugin.assertEntity(); + // handle event + handleVotingSettingsUpdated(event); - clearStore(); + // checks + tokenVotingPlugin.assertEntity(); + }); + + test('it should update the plugin setting (with Undefined VotingMode)', () => { + // create state + let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues(); + tokenVotingPlugin.buildOrUpdate(); + + // update plugin configuration + tokenVotingPlugin.setNewPluginSetting('7'); + + // create event + let event = tokenVotingPlugin.createEvent_VotingSettingsUpdated(); + + // handle event + handleVotingSettingsUpdated(event); + + // checks + tokenVotingPlugin.assertEntity(); + }); }); describe('handleMembershipContractAnnounced', () => { From 7b64a78cf4b821867e1a0906e2f8f1eca244f705 Mon Sep 17 00:00:00 2001 From: Claudia Date: Thu, 11 Apr 2024 13:55:36 +0200 Subject: [PATCH 06/25] feat: create a constant for the default index of undefined voting mode --- packages/subgraph/src/plugin/plugin.ts | 11 ++++++++--- packages/subgraph/src/utils/constants.ts | 4 +++- packages/subgraph/tests/helpers/method-classes.ts | 7 ++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index 662851f2..984d9e35 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -14,7 +14,12 @@ import { MembershipContractAnnounced, TokenVoting, } from '../../generated/templates/TokenVoting/TokenVoting'; -import {RATIO_BASE, VOTER_OPTIONS, VOTING_MODES} from '../utils/constants'; +import { + RATIO_BASE, + VOTER_OPTIONS, + VOTING_MODES, + VOTING_MODE_UNDEFINED_INDEX, +} from '../utils/constants'; import {identifyAndFetchOrCreateERC20TokenEntity} from '../utils/erc20'; import {generateMemberEntityId, generateVoteEntityId} from '../utils/ids'; import { @@ -73,7 +78,7 @@ export function _handleProposalCreated( let votingModeIndex = parameters.votingMode; if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' - votingModeIndex = 10; + votingModeIndex = VOTING_MODE_UNDEFINED_INDEX; } const votingMode = VOTING_MODES.get(votingModeIndex); @@ -273,7 +278,7 @@ export function handleVotingSettingsUpdated( let votingModeIndex = event.params.votingMode; if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' - votingModeIndex = 10; + votingModeIndex = VOTING_MODE_UNDEFINED_INDEX; } const votingMode = VOTING_MODES.get(votingModeIndex); diff --git a/packages/subgraph/src/utils/constants.ts b/packages/subgraph/src/utils/constants.ts index e11b9cbd..611a6c30 100644 --- a/packages/subgraph/src/utils/constants.ts +++ b/packages/subgraph/src/utils/constants.ts @@ -17,6 +17,8 @@ export enum TransferType { Deposit, } +export const VOTING_MODE_UNDEFINED_INDEX = 10; + export const DECODE_OFFSET = '0x0000000000000000000000000000000000000000000000000000000000000020'; @@ -40,7 +42,7 @@ export const VOTING_MODES = new Map() .set(0, 'Standard') .set(1, 'EarlyExecution') .set(2, 'VoteReplacement') - .set(10, 'Undefined'); + .set(VOTING_MODE_UNDEFINED_INDEX, 'Undefined'); export const TOKEN_VOTING_INTERFACE_ID = '0x50eb001e'; export const ADDRESSLIST_VOTING_INTERFACE_ID = '0x5f21eb8b'; diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index 8c4c4cdb..ac1755f5 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -28,6 +28,7 @@ import { VOTER_OPTIONS, VOTE_OPTIONS, VOTING_MODES, + VOTING_MODE_UNDEFINED_INDEX, } from '../../src/utils/constants'; import {generateMemberEntityId} from '../../src/utils/ids'; import { @@ -205,7 +206,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.votingModeIndex = votingModeIndex; this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(10) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minVotingPower = BigInt.fromString(MIN_VOTING_POWER); @@ -384,7 +385,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(10) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minParticipation = BigInt.fromString(MIN_PARTICIPATION); @@ -440,7 +441,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.votingModeIndex = votingModeIndex; this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(10) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); this.supportThreshold = newSupportThreshold; this.minParticipation = newMinParticipation; this.minDuration = newMinDuration; From 977937d9182134449d7628ba66d292d715c72ad7 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 12:50:20 +0200 Subject: [PATCH 07/25] ci: rename votingMode that comes from solidity event to avoid confusion --- packages/subgraph/src/plugin/plugin.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index 984d9e35..e78f345d 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -75,15 +75,13 @@ export function _handleProposalCreated( // ProposalParameters const parameters = proposal.value.value2; - let votingModeIndex = parameters.votingMode; - if (!VOTING_MODES.has(votingModeIndex)) { + let votingMode = parameters.votingMode; + if (!VOTING_MODES.has(votingMode)) { // if the voting mode is not defined, set it to 'Undefined' - votingModeIndex = VOTING_MODE_UNDEFINED_INDEX; + votingMode = VOTING_MODE_UNDEFINED_INDEX; } - const votingMode = VOTING_MODES.get(votingModeIndex); - - proposalEntity.votingMode = votingMode as string; + proposalEntity.votingMode = VOTING_MODES.get(votingMode) as string; proposalEntity.supportThreshold = parameters.supportThreshold; proposalEntity.snapshotBlock = parameters.snapshotBlock; proposalEntity.minVotingPower = parameters.minVotingPower; @@ -275,14 +273,13 @@ export function handleVotingSettingsUpdated( generatePluginEntityId(event.address) ); if (pluginEntity) { - let votingModeIndex = event.params.votingMode; - if (!VOTING_MODES.has(votingModeIndex)) { + let votingMode = event.params.votingMode; + if (!VOTING_MODES.has(votingMode)) { // if the voting mode is not defined, set it to 'Undefined' - votingModeIndex = VOTING_MODE_UNDEFINED_INDEX; + votingMode = VOTING_MODE_UNDEFINED_INDEX; } - const votingMode = VOTING_MODES.get(votingModeIndex); - pluginEntity.votingMode = votingMode as string; + pluginEntity.votingMode = VOTING_MODES.get(votingMode) as string; pluginEntity.supportThreshold = event.params.supportThreshold; pluginEntity.minParticipation = event.params.minParticipation; pluginEntity.minDuration = event.params.minDuration; From 6e55c9fc0ad9457e7239a90d110f71aa379927c8 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 12:50:59 +0200 Subject: [PATCH 08/25] ci: rename constant to avoid confusion --- packages/subgraph/src/plugin/plugin.ts | 6 +++--- packages/subgraph/src/utils/constants.ts | 4 ++-- packages/subgraph/tests/helpers/method-classes.ts | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index e78f345d..315b16a0 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -18,7 +18,7 @@ import { RATIO_BASE, VOTER_OPTIONS, VOTING_MODES, - VOTING_MODE_UNDEFINED_INDEX, + VOTING_MODE_UNDEFINED, } from '../utils/constants'; import {identifyAndFetchOrCreateERC20TokenEntity} from '../utils/erc20'; import {generateMemberEntityId, generateVoteEntityId} from '../utils/ids'; @@ -78,7 +78,7 @@ export function _handleProposalCreated( let votingMode = parameters.votingMode; if (!VOTING_MODES.has(votingMode)) { // if the voting mode is not defined, set it to 'Undefined' - votingMode = VOTING_MODE_UNDEFINED_INDEX; + votingMode = VOTING_MODE_UNDEFINED; } proposalEntity.votingMode = VOTING_MODES.get(votingMode) as string; @@ -276,7 +276,7 @@ export function handleVotingSettingsUpdated( let votingMode = event.params.votingMode; if (!VOTING_MODES.has(votingMode)) { // if the voting mode is not defined, set it to 'Undefined' - votingMode = VOTING_MODE_UNDEFINED_INDEX; + votingMode = VOTING_MODE_UNDEFINED; } pluginEntity.votingMode = VOTING_MODES.get(votingMode) as string; diff --git a/packages/subgraph/src/utils/constants.ts b/packages/subgraph/src/utils/constants.ts index 611a6c30..15a6958f 100644 --- a/packages/subgraph/src/utils/constants.ts +++ b/packages/subgraph/src/utils/constants.ts @@ -17,7 +17,7 @@ export enum TransferType { Deposit, } -export const VOTING_MODE_UNDEFINED_INDEX = 10; +export const VOTING_MODE_UNDEFINED = 10; export const DECODE_OFFSET = '0x0000000000000000000000000000000000000000000000000000000000000020'; @@ -42,7 +42,7 @@ export const VOTING_MODES = new Map() .set(0, 'Standard') .set(1, 'EarlyExecution') .set(2, 'VoteReplacement') - .set(VOTING_MODE_UNDEFINED_INDEX, 'Undefined'); + .set(VOTING_MODE_UNDEFINED, 'Undefined'); export const TOKEN_VOTING_INTERFACE_ID = '0x50eb001e'; export const ADDRESSLIST_VOTING_INTERFACE_ID = '0x5f21eb8b'; diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index ac1755f5..631e752a 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -28,7 +28,7 @@ import { VOTER_OPTIONS, VOTE_OPTIONS, VOTING_MODES, - VOTING_MODE_UNDEFINED_INDEX, + VOTING_MODE_UNDEFINED, } from '../../src/utils/constants'; import {generateMemberEntityId} from '../../src/utils/ids'; import { @@ -206,7 +206,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.votingModeIndex = votingModeIndex; this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minVotingPower = BigInt.fromString(MIN_VOTING_POWER); @@ -385,7 +385,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minParticipation = BigInt.fromString(MIN_PARTICIPATION); @@ -441,7 +441,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.votingModeIndex = votingModeIndex; this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); this.supportThreshold = newSupportThreshold; this.minParticipation = newMinParticipation; this.minDuration = newMinDuration; From 2ad7f751b39bb2b18793b3bd834a16daa21a3d91 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 12:55:31 +0200 Subject: [PATCH 09/25] ci: remove voting mode one for more explicit one --- packages/subgraph/tests/helpers/method-classes.ts | 10 +++++----- packages/subgraph/tests/utils/constants.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index 631e752a..b2b8aceb 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -64,7 +64,7 @@ import { SUPPORT_THRESHOLD, TOTAL_VOTING_POWER, TWO, - VOTING_MODE, + VOTING_MODE_ONE, ZERO, MIN_PARTICIPATION, MIN_DURATION, @@ -187,10 +187,10 @@ class TokenVotingVoterMethods extends TokenVotingVoter { } class TokenVotingProposalMethods extends TokenVotingProposal { - votingModeIndex: string = VOTING_MODE; + votingModeIndex: string = ''; withDefaultValues( - votingModeIndex: string = VOTING_MODE + votingModeIndex: string = VOTING_MODE_ONE ): TokenVotingProposalMethods { this.id = PROPOSAL_ENTITY_ID; @@ -369,11 +369,11 @@ class TokenVotingVoteMethods extends TokenVotingVote { } class TokenVotingPluginMethods extends TokenVotingPlugin { - votingModeIndex: string = VOTING_MODE; + votingModeIndex: string = ''; // build entity // if id not changed it will update withDefaultValues( - votingModeIndex: string = VOTING_MODE + votingModeIndex: string = VOTING_MODE_ONE ): TokenVotingPluginMethods { const pluginAddress = Address.fromString(CONTRACT_ADDRESS); const pluginEntityId = generatePluginEntityId(pluginAddress); diff --git a/packages/subgraph/tests/utils/constants.ts b/packages/subgraph/tests/utils/constants.ts index 39eb128b..afa850d9 100644 --- a/packages/subgraph/tests/utils/constants.ts +++ b/packages/subgraph/tests/utils/constants.ts @@ -40,7 +40,7 @@ export const TOKEN_NAME = 'name'; export const HOUR = '3600'; export const TWO_HOURS = '7200'; -export const VOTING_MODE: string = ONE; // EarlyExecution +export const VOTING_MODE_ONE: string = ONE; // EarlyExecution export const SUPPORT_THRESHOLD = '500000'; // 50*10**4 = 50% export const NEW_SUPPORT_THRESHOLD = '400000'; // 40*10**4 = 40% export const MIN_PARTICIPATION = '500000'; // 50*10**4 = 50% From 302514d19e2a37078617cff92cb9425fceca94b0 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 13:25:33 +0200 Subject: [PATCH 10/25] fix: remove the properties definition from the extender --- packages/subgraph/tests/schema-extender.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/subgraph/tests/schema-extender.ts b/packages/subgraph/tests/schema-extender.ts index 9ec34770..149915fb 100644 --- a/packages/subgraph/tests/schema-extender.ts +++ b/packages/subgraph/tests/schema-extender.ts @@ -70,19 +70,6 @@ function main() { // add methods to generated classes sourceMethodClasses.forEach(classDeclaration => { if (classDeclaration.getName() === `${originalClassName}Methods`) { - const properties = classDeclaration.getProperties(); - properties.forEach(property => { - newClass.addProperty( - property.getStructure() as { - name: string; - type: string; - hasQuestionToken: boolean; - initializer: string; - decorators: {name: string; arguments: string[]}[]; - } - ); - }); - const methods = classDeclaration.getMethods(); methods.forEach(method => { From e3b51abe93ebd6fc899218d468bab79d1f277186 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 13:27:14 +0200 Subject: [PATCH 11/25] fix: remove the votingModeIndex from the extended class because is already on the entity --- packages/subgraph/tests/helpers/method-classes.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index b2b8aceb..11329f16 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -187,8 +187,6 @@ class TokenVotingVoterMethods extends TokenVotingVoter { } class TokenVotingProposalMethods extends TokenVotingProposal { - votingModeIndex: string = ''; - withDefaultValues( votingModeIndex: string = VOTING_MODE_ONE ): TokenVotingProposalMethods { @@ -369,7 +367,6 @@ class TokenVotingVoteMethods extends TokenVotingVote { } class TokenVotingPluginMethods extends TokenVotingPlugin { - votingModeIndex: string = ''; // build entity // if id not changed it will update withDefaultValues( From ea62699c2b8e9b124cce7a840eccfed28c251415 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 13:34:32 +0200 Subject: [PATCH 12/25] feat: add voting mode index to the plugin and proposal entity --- packages/subgraph/schema.graphql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 23277608..a5f348f7 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -58,6 +58,7 @@ type TokenVotingPlugin implements IPlugin @entity { proposals: [TokenVotingProposal!]! @derivedFrom(field: "plugin") votingMode: VotingMode + votingModeIndex: Int supportThreshold: BigInt minParticipation: BigInt minDuration: BigInt @@ -111,6 +112,7 @@ type TokenVotingProposal implements IProposal @entity { metadata: String votingMode: VotingMode! + votingModeIndex: Int! supportThreshold: BigInt! minVotingPower: BigInt! snapshotBlock: BigInt! From 34400d667d1693b130cdf8c8c69e4cdc48341a3b Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 13:38:31 +0200 Subject: [PATCH 13/25] feat: store the voting mode index manager in the handlers --- packages/subgraph/src/plugin/plugin.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index 315b16a0..42ef035d 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -75,13 +75,13 @@ export function _handleProposalCreated( // ProposalParameters const parameters = proposal.value.value2; - let votingMode = parameters.votingMode; - if (!VOTING_MODES.has(votingMode)) { + let votingModeIndex = parameters.votingMode; + if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' - votingMode = VOTING_MODE_UNDEFINED; + votingModeIndex = VOTING_MODE_UNDEFINED; } - - proposalEntity.votingMode = VOTING_MODES.get(votingMode) as string; + proposalEntity.votingModeIndex = votingModeIndex; + proposalEntity.votingMode = VOTING_MODES.get(votingModeIndex) as string; proposalEntity.supportThreshold = parameters.supportThreshold; proposalEntity.snapshotBlock = parameters.snapshotBlock; proposalEntity.minVotingPower = parameters.minVotingPower; @@ -273,13 +273,14 @@ export function handleVotingSettingsUpdated( generatePluginEntityId(event.address) ); if (pluginEntity) { - let votingMode = event.params.votingMode; - if (!VOTING_MODES.has(votingMode)) { + let votingModeIndex = event.params.votingMode; + if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' - votingMode = VOTING_MODE_UNDEFINED; + votingModeIndex = VOTING_MODE_UNDEFINED; } - pluginEntity.votingMode = VOTING_MODES.get(votingMode) as string; + pluginEntity.votingModeIndex = votingModeIndex; + pluginEntity.votingMode = VOTING_MODES.get(votingModeIndex) as string; pluginEntity.supportThreshold = event.params.supportThreshold; pluginEntity.minParticipation = event.params.minParticipation; pluginEntity.minDuration = event.params.minDuration; From ee8a0f753b628f3e2a251dbb18dbea71a3684cb3 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 13:40:51 +0200 Subject: [PATCH 14/25] ci: undo the voting mode constant rename --- packages/subgraph/tests/utils/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subgraph/tests/utils/constants.ts b/packages/subgraph/tests/utils/constants.ts index afa850d9..39eb128b 100644 --- a/packages/subgraph/tests/utils/constants.ts +++ b/packages/subgraph/tests/utils/constants.ts @@ -40,7 +40,7 @@ export const TOKEN_NAME = 'name'; export const HOUR = '3600'; export const TWO_HOURS = '7200'; -export const VOTING_MODE_ONE: string = ONE; // EarlyExecution +export const VOTING_MODE: string = ONE; // EarlyExecution export const SUPPORT_THRESHOLD = '500000'; // 50*10**4 = 50% export const NEW_SUPPORT_THRESHOLD = '400000'; // 40*10**4 = 40% export const MIN_PARTICIPATION = '500000'; // 50*10**4 = 50% From ddd2761e243ef14f0c5e590b2ae28b9c919fdc6a Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 13:41:09 +0200 Subject: [PATCH 15/25] ci: rename the constant name undo --- .../subgraph/tests/helpers/method-classes.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index 11329f16..399f1236 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -64,7 +64,7 @@ import { SUPPORT_THRESHOLD, TOTAL_VOTING_POWER, TWO, - VOTING_MODE_ONE, + VOTING_MODE, ZERO, MIN_PARTICIPATION, MIN_DURATION, @@ -188,7 +188,7 @@ class TokenVotingVoterMethods extends TokenVotingVoter { class TokenVotingProposalMethods extends TokenVotingProposal { withDefaultValues( - votingModeIndex: string = VOTING_MODE_ONE + votingModeIndex: number = parseInt(VOTING_MODE) ): TokenVotingProposalMethods { this.id = PROPOSAL_ENTITY_ID; @@ -202,8 +202,8 @@ class TokenVotingProposalMethods extends TokenVotingProposal { // for event we need the index of the mapping to simulate the contract event this.votingModeIndex = votingModeIndex; - this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) - ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) + this.votingMode = VOTING_MODES.has(votingModeIndex) + ? (VOTING_MODES.get(votingModeIndex) as string) : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); @@ -238,7 +238,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.pluginProposalId.toString(), this.open, this.executed, - this.votingModeIndex as string, // we need the index for this mocked call + this.votingModeIndex.toString(), // we need the index for this mocked call this.supportThreshold.toString(), this.minVotingPower.toString(), this.startDate.toString(), @@ -370,7 +370,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { // build entity // if id not changed it will update withDefaultValues( - votingModeIndex: string = VOTING_MODE_ONE + votingModeIndex: number = parseInt(VOTING_MODE) ): TokenVotingPluginMethods { const pluginAddress = Address.fromString(CONTRACT_ADDRESS); const pluginEntityId = generatePluginEntityId(pluginAddress); @@ -380,8 +380,8 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.pluginAddress = pluginAddress; this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event - this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) - ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) + this.votingMode = VOTING_MODES.has(votingModeIndex) + ? (VOTING_MODES.get(votingModeIndex) as string) : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); @@ -403,7 +403,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { createEvent_VotingSettingsUpdated(): VotingSettingsUpdated { let event = createNewVotingSettingsUpdatedEvent( - this.votingModeIndex as string, // we need the index for simulate the event + this.votingModeIndex.toString(), // we need the index for simulate the event (this.supportThreshold as BigInt).toString(), (this.minParticipation as BigInt).toString(), (this.minDuration as BigInt).toString(), @@ -427,7 +427,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { } setNewPluginSetting( - votingModeIndex: string = TWO, + votingModeIndex: number = parseInt(TWO), newSupportThreshold: BigInt = BigInt.fromString(NEW_SUPPORT_THRESHOLD), newMinParticipation: BigInt = BigInt.fromString(NEW_MIN_PARTICIPATION), newMinDuration: BigInt = BigInt.fromString(NEW_MIN_DURATION), @@ -436,8 +436,8 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { ) ): TokenVotingPluginMethods { this.votingModeIndex = votingModeIndex; - this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) - ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) + this.votingMode = VOTING_MODES.has(votingModeIndex) + ? (VOTING_MODES.get(votingModeIndex) as string) : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); this.supportThreshold = newSupportThreshold; this.minParticipation = newMinParticipation; From 7d0c0dd147096278d388ffac8d21e1d36514ee9d Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 14:25:16 +0200 Subject: [PATCH 16/25] ci: change voting mode index type to int8 --- packages/subgraph/schema.graphql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index a5f348f7..06b43bec 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -58,7 +58,7 @@ type TokenVotingPlugin implements IPlugin @entity { proposals: [TokenVotingProposal!]! @derivedFrom(field: "plugin") votingMode: VotingMode - votingModeIndex: Int + votingModeIndex: Int8 supportThreshold: BigInt minParticipation: BigInt minDuration: BigInt @@ -112,7 +112,7 @@ type TokenVotingProposal implements IProposal @entity { metadata: String votingMode: VotingMode! - votingModeIndex: Int! + votingModeIndex: Int8! supportThreshold: BigInt! minVotingPower: BigInt! snapshotBlock: BigInt! From bc2c91d2869c676b5c3911502b5325e6ac753f52 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 14:25:51 +0200 Subject: [PATCH 17/25] feat: modify the extended method class to cast the voting mode index types --- packages/subgraph/tests/helpers/method-classes.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index 399f1236..b3b6edf1 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -85,7 +85,7 @@ import { createDummyAction, generateActionEntityId, } from '@aragon/osx-commons-subgraph'; -import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts'; +import {Address, BigInt, Bytes, ethereum, Int8} from '@graphprotocol/graph-ts'; class ERC20WrapperContractMethods extends ERC20WrapperContract { withDefaultValues(): ERC20WrapperContractMethods { @@ -201,7 +201,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.executed = false; // for event we need the index of the mapping to simulate the contract event - this.votingModeIndex = votingModeIndex; + this.votingModeIndex = votingModeIndex as Int8; this.votingMode = VOTING_MODES.has(votingModeIndex) ? (VOTING_MODES.get(votingModeIndex) as string) : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); @@ -379,7 +379,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.daoAddress = Bytes.fromHexString(DAO_ADDRESS); this.pluginAddress = pluginAddress; - this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event + this.votingModeIndex = votingModeIndex as Int8; // for event we need the index of the mapping to simulate the contract event this.votingMode = VOTING_MODES.has(votingModeIndex) ? (VOTING_MODES.get(votingModeIndex) as string) : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); @@ -435,7 +435,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { NEW_MIN_PROPOSER_VOTING_POWER ) ): TokenVotingPluginMethods { - this.votingModeIndex = votingModeIndex; + this.votingModeIndex = votingModeIndex as Int8; this.votingMode = VOTING_MODES.has(votingModeIndex) ? (VOTING_MODES.get(votingModeIndex) as string) : (VOTING_MODES.get(VOTING_MODE_UNDEFINED) as string); From e80094048f3e41eb2f6329e23ceb74f700a3f7ff Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 14:26:57 +0200 Subject: [PATCH 18/25] feat: update the tests --- packages/subgraph/tests/plugin/plugin.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/subgraph/tests/plugin/plugin.test.ts b/packages/subgraph/tests/plugin/plugin.test.ts index 15bc0217..d0df3908 100644 --- a/packages/subgraph/tests/plugin/plugin.test.ts +++ b/packages/subgraph/tests/plugin/plugin.test.ts @@ -77,7 +77,6 @@ describe('handleProposalCreated', () => { // checks // expected changes proposal.creationBlockNumber = BigInt.fromString(ONE); - proposal.votingMode = VOTING_MODES.get(parseInt(VOTING_MODE)) as string; // check the proposal and the plugin assert.entityCount('TokenVotingPlugin', 1); @@ -98,14 +97,14 @@ describe('handleProposalCreated', () => { // create state let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues( - '11' + 11 ); tokenVotingPlugin.buildOrUpdate(); // check before handle event tokenVotingPlugin.assertEntity(); - let proposal = new ExtendedTokenVotingProposal().withDefaultValues('11'); + let proposal = new ExtendedTokenVotingProposal().withDefaultValues(11); let action = new ExtendedAction().withDefaultValues(); // create event @@ -126,7 +125,6 @@ describe('handleProposalCreated', () => { assert.entityCount('TokenVotingProposal', 1); proposal.creationBlockNumber = BigInt.fromString(ONE); - proposal.votingMode = VOTING_MODES.get(parseInt(VOTING_MODE)) as string; proposal.assertEntity(); tokenVotingPlugin.proposalCount = BigInt.fromString(ONE); @@ -341,7 +339,7 @@ describe('handleVotingSettingsUpdated', () => { tokenVotingPlugin.buildOrUpdate(); // update plugin configuration - tokenVotingPlugin.setNewPluginSetting('7'); + tokenVotingPlugin.setNewPluginSetting(7); // create event let event = tokenVotingPlugin.createEvent_VotingSettingsUpdated(); From c7dd2b72e628c80d7dce3ac83185ea1f7008d544 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 15:10:23 +0200 Subject: [PATCH 19/25] fix: define the received index, not hte fixed one --- packages/subgraph/src/plugin/plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index 42ef035d..eba94df5 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -76,11 +76,11 @@ export function _handleProposalCreated( // ProposalParameters const parameters = proposal.value.value2; let votingModeIndex = parameters.votingMode; + proposalEntity.votingModeIndex = votingModeIndex; if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' votingModeIndex = VOTING_MODE_UNDEFINED; } - proposalEntity.votingModeIndex = votingModeIndex; proposalEntity.votingMode = VOTING_MODES.get(votingModeIndex) as string; proposalEntity.supportThreshold = parameters.supportThreshold; proposalEntity.snapshotBlock = parameters.snapshotBlock; @@ -274,12 +274,12 @@ export function handleVotingSettingsUpdated( ); if (pluginEntity) { let votingModeIndex = event.params.votingMode; + pluginEntity.votingModeIndex = votingModeIndex; if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' votingModeIndex = VOTING_MODE_UNDEFINED; } - pluginEntity.votingModeIndex = votingModeIndex; pluginEntity.votingMode = VOTING_MODES.get(votingModeIndex) as string; pluginEntity.supportThreshold = event.params.supportThreshold; pluginEntity.minParticipation = event.params.minParticipation; From 111979d4d2b96e3a12f74c3ab944545869bb7d1c Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 15:22:24 +0200 Subject: [PATCH 20/25] ci: update the test comment --- packages/subgraph/tests/plugin/governance-erc20.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subgraph/tests/plugin/governance-erc20.test.ts b/packages/subgraph/tests/plugin/governance-erc20.test.ts index 17be10e8..73cb3d03 100644 --- a/packages/subgraph/tests/plugin/governance-erc20.test.ts +++ b/packages/subgraph/tests/plugin/governance-erc20.test.ts @@ -466,7 +466,7 @@ describe('Governance ERC20', () => { assert.entityCount('TokenVotingMember', 2); }); - test("It should initialize with the user's existing voting power and delegation, if she has any", () => { + test("it should initialize with the user's existing voting power and delegation, if has any", () => { let memberOne = new ExtendedTokenVotingMember().withDefaultValues( fromAddress, pluginAddress From 7d54b830430b8c0fb866a34437ae07edd8d1c5b2 Mon Sep 17 00:00:00 2001 From: Claudia Date: Fri, 12 Apr 2024 15:31:04 +0200 Subject: [PATCH 21/25] feat: add mock call to correctly simulate the test --- packages/subgraph/tests/plugin/plugin.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/subgraph/tests/plugin/plugin.test.ts b/packages/subgraph/tests/plugin/plugin.test.ts index d0df3908..00d60072 100644 --- a/packages/subgraph/tests/plugin/plugin.test.ts +++ b/packages/subgraph/tests/plugin/plugin.test.ts @@ -107,6 +107,9 @@ describe('handleProposalCreated', () => { let proposal = new ExtendedTokenVotingProposal().withDefaultValues(11); let action = new ExtendedAction().withDefaultValues(); + // mock call because the votingMode is being gotten from the plugin + proposal.mockCall_getProposal([action.getDummyAction()]); + // create event let event = proposal.createEvent_ProposalCreated( [action.getDummyAction()], From 6752ce9ccb9658cea62092bd8f421a016dbb70ad Mon Sep 17 00:00:00 2001 From: Claudia Barcelo Date: Mon, 15 Apr 2024 10:50:53 +0200 Subject: [PATCH 22/25] Update packages/subgraph/tests/helpers/method-classes.ts Co-authored-by: Jordan <45881807+jordaniza@users.noreply.github.com> --- packages/subgraph/tests/helpers/method-classes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index b3b6edf1..cdd425bb 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -403,7 +403,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { createEvent_VotingSettingsUpdated(): VotingSettingsUpdated { let event = createNewVotingSettingsUpdatedEvent( - this.votingModeIndex.toString(), // we need the index for simulate the event + this.votingModeIndex.toString(), // we need the index to simulate the event (this.supportThreshold as BigInt).toString(), (this.minParticipation as BigInt).toString(), (this.minDuration as BigInt).toString(), From 6dc2a3e11574bb5e59a30cffcdcc471393307095 Mon Sep 17 00:00:00 2001 From: Claudia Barcelo Date: Mon, 15 Apr 2024 10:51:11 +0200 Subject: [PATCH 23/25] Update packages/subgraph/tests/plugin/governance-erc20.test.ts Co-authored-by: Jordan <45881807+jordaniza@users.noreply.github.com> --- packages/subgraph/tests/plugin/governance-erc20.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/subgraph/tests/plugin/governance-erc20.test.ts b/packages/subgraph/tests/plugin/governance-erc20.test.ts index 73cb3d03..e5e5d185 100644 --- a/packages/subgraph/tests/plugin/governance-erc20.test.ts +++ b/packages/subgraph/tests/plugin/governance-erc20.test.ts @@ -466,7 +466,7 @@ describe('Governance ERC20', () => { assert.entityCount('TokenVotingMember', 2); }); - test("it should initialize with the user's existing voting power and delegation, if has any", () => { + test("it should initialize with the user's existing voting power and delegation, if they have any", () => { let memberOne = new ExtendedTokenVotingMember().withDefaultValues( fromAddress, pluginAddress From 4e34a5f63147a71e7f130d3ca984157956fd612e Mon Sep 17 00:00:00 2001 From: Claudia Date: Mon, 15 Apr 2024 10:54:47 +0200 Subject: [PATCH 24/25] feat: define constants to remove magic numbers in subgraph tests --- packages/subgraph/tests/plugin/plugin.test.ts | 9 ++++++--- packages/subgraph/tests/utils/constants.ts | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/subgraph/tests/plugin/plugin.test.ts b/packages/subgraph/tests/plugin/plugin.test.ts index 00d60072..94156f66 100644 --- a/packages/subgraph/tests/plugin/plugin.test.ts +++ b/packages/subgraph/tests/plugin/plugin.test.ts @@ -23,6 +23,7 @@ import { ZERO, TWO, ERC20_AMOUNT_FULL, + UNDEFINED_VOTING_MODE, } from '../utils/constants'; import {bigInt, BigInt} from '@graphprotocol/graph-ts'; import { @@ -97,14 +98,16 @@ describe('handleProposalCreated', () => { // create state let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues( - 11 + UNDEFINED_VOTING_MODE ); tokenVotingPlugin.buildOrUpdate(); // check before handle event tokenVotingPlugin.assertEntity(); - let proposal = new ExtendedTokenVotingProposal().withDefaultValues(11); + let proposal = new ExtendedTokenVotingProposal().withDefaultValues( + UNDEFINED_VOTING_MODE + ); let action = new ExtendedAction().withDefaultValues(); // mock call because the votingMode is being gotten from the plugin @@ -342,7 +345,7 @@ describe('handleVotingSettingsUpdated', () => { tokenVotingPlugin.buildOrUpdate(); // update plugin configuration - tokenVotingPlugin.setNewPluginSetting(7); + tokenVotingPlugin.setNewPluginSetting(UNDEFINED_VOTING_MODE); // create event let event = tokenVotingPlugin.createEvent_VotingSettingsUpdated(); diff --git a/packages/subgraph/tests/utils/constants.ts b/packages/subgraph/tests/utils/constants.ts index 420441eb..c03b8f17 100644 --- a/packages/subgraph/tests/utils/constants.ts +++ b/packages/subgraph/tests/utils/constants.ts @@ -32,6 +32,7 @@ export const HOUR = '3600'; export const TWO_HOURS = '7200'; export const VOTING_MODE: string = ONE; // EarlyExecution +export const UNDEFINED_VOTING_MODE = 11; export const SUPPORT_THRESHOLD = '500000'; // 50*10**4 = 50% export const NEW_SUPPORT_THRESHOLD = '400000'; // 40*10**4 = 40% export const MIN_PARTICIPATION = '500000'; // 50*10**4 = 50% From 3ef486dddcb3f5f871f2eef1d434788e3136e9c2 Mon Sep 17 00:00:00 2001 From: Claudia Date: Mon, 15 Apr 2024 10:55:06 +0200 Subject: [PATCH 25/25] ci: remove not needed imports --- packages/subgraph/tests/plugin/plugin.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/subgraph/tests/plugin/plugin.test.ts b/packages/subgraph/tests/plugin/plugin.test.ts index 94156f66..10b19483 100644 --- a/packages/subgraph/tests/plugin/plugin.test.ts +++ b/packages/subgraph/tests/plugin/plugin.test.ts @@ -5,7 +5,6 @@ import { _handleProposalCreated, handleMembershipContractAnnounced, } from '../../src/plugin/plugin'; -import {VOTING_MODES} from '../../src/utils/constants'; import {GOVERNANCE_WRAPPED_ERC20_INTERFACE_ID} from '../../src/utils/constants'; import { ExtendedERC20Contract, @@ -18,7 +17,6 @@ import { } from '../helpers/extended-schema'; import { STRING_DATA, - VOTING_MODE, ONE, ZERO, TWO,