Skip to content

Commit

Permalink
add testing for plugin repo permissions events
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 committed Sep 21, 2023
1 parent 727ab8f commit fa2fca1
Showing 1 changed file with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
Expand All @@ -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<RepoGranted>(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<RepoRevoked>(revokedEvent));

// checks
assert.notInStore('Permission', permission.id);
Expand Down

0 comments on commit fa2fca1

Please sign in to comment.