From fa2fca1e751f7ef2f8ebfb3e25dee0cc4eea8664 Mon Sep 17 00:00:00 2001 From: Rekard0 <5880388+Rekard0@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:37:31 +0200 Subject: [PATCH] add testing for plugin repo permissions events --- .../permission-manager.test.ts | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/subgraph/tests/permission-mamager/permission-manager.test.ts b/packages/subgraph/tests/permission-mamager/permission-manager.test.ts index 4b8d91e70..a6888a01e 100644 --- a/packages/subgraph/tests/permission-mamager/permission-manager.test.ts +++ b/packages/subgraph/tests/permission-mamager/permission-manager.test.ts @@ -1,10 +1,21 @@ import {assert, clearStore, test} from 'matchstick-as/assembly/index'; import {Address} from '@graphprotocol/graph-ts'; -import {handleGranted, handleRevoked} from '../../src/dao/dao_v1_0_0'; +import { + handleGranted as daoHandleGranted, + handleRevoked as daoHandleRevoked +} from '../../src/dao/dao_v1_0_0'; +import { + handleGranted as repoHandleGranted, + handleRevoked as repoHandleRevoked +} from '../../src/plugin/pluginRepo'; import {CONTRACT_ADDRESS, DAO_ADDRESS} from '../constants'; import {ExtendedPermission} from '../helpers/extended-schema'; +import { + Granted as RepoGranted, + Revoked as RepoRevoked +} from '../../generated/templates/PluginRepoTemplate/PluginRepo'; const daoId = Address.fromString(DAO_ADDRESS).toHexString(); const pluginRepoId = Address.fromString(CONTRACT_ADDRESS).toHexString(); @@ -17,7 +28,7 @@ test('Run dao (handleGranted) mappings with mock event', () => { let grantedEvent = permission.createEvent_Granted(daoId); // handle event - handleGranted(grantedEvent); + daoHandleGranted(grantedEvent); // checks permission.assertEntity(true); @@ -38,7 +49,44 @@ test('Run dao (handleRevoked) mappings with mock event', () => { let revokedEvent = permission.createEvent_Revoked(daoId); // handle event - handleRevoked(revokedEvent); + daoHandleRevoked(revokedEvent); + + // checks + assert.notInStore('Permission', permission.id); + + clearStore(); +}); + +// PluginRepo +test('Run PluginRepo (handleGranted) mappings with mock event', () => { + let permission = new ExtendedPermission().withDefaultValues(pluginRepoId); + permission.pluginRepo = pluginRepoId; + + let grantedEvent = permission.createEvent_Granted(pluginRepoId); + + // handle event + repoHandleGranted(changetype(grantedEvent)); + + // checks + permission.assertEntity(true); + + clearStore(); +}); + +test('Run PluginRepo (handleRevoked) mappings with mock event', () => { + let permission = new ExtendedPermission().withDefaultValues(pluginRepoId); + permission.pluginRepo = pluginRepoId; + + permission.save(); + + // check state exist + permission.assertEntity(); + + // create event and run it's handler + let revokedEvent = permission.createEvent_Revoked(pluginRepoId); + + // handle event + repoHandleRevoked(changetype(revokedEvent)); // checks assert.notInStore('Permission', permission.id);