Skip to content

Commit

Permalink
remove test for removed entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 committed Sep 20, 2023
1 parent 8039d7f commit a831198
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 106 deletions.
1 change: 1 addition & 0 deletions packages/subgraph/src/dao/dao_v1_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export function handleGranted(event: Granted): void {
// Permission
let permissionEntity = new Permission(permissionEntityId);
permissionEntity.where = event.params.where;
permissionEntity.permissionId = contractPermissionId;
permissionEntity.who = event.params.who;
permissionEntity.actor = event.params.here;
permissionEntity.condition = event.params.condition;
Expand Down
1 change: 1 addition & 0 deletions packages/subgraph/src/plugin/pluginRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function handleGranted(event: Granted): void {
// Permission
let permissionEntity = new Permission(permissionEntityId);
permissionEntity.where = event.params.where;
permissionEntity.permissionId = contractPermissionId;
permissionEntity.who = event.params.who;
permissionEntity.actor = event.params.here;
permissionEntity.condition = event.params.condition;
Expand Down
141 changes: 35 additions & 106 deletions packages/subgraph/tests/dao/permission-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {assert, clearStore, test} from 'matchstick-as/assembly/index';
import {Address, ByteArray, Bytes, crypto} from '@graphprotocol/graph-ts';

import {handleGranted, handleRevoked} from '../../src/dao/dao_v1_0_0';
import {Permission, ContractPermissionId} from '../../generated/schema';
import {Permission} from '../../generated/schema';
import {
DAO_ADDRESS,
ADDRESS_ONE,
CONTRACT_ADDRESS,
ADDRESS_TWO
ADDRESS_TWO,
ADDRESS_THREE
} from '../constants';
import {
createNewGrantedEvent,
Expand All @@ -16,61 +17,37 @@ import {
getEXECUTE_PERMISSION_IDreverted
} from './utils';

let contractPermissionId = Bytes.fromByteArray(
const contractPermissionId = Bytes.fromByteArray(
crypto.keccak256(ByteArray.fromUTF8('EXECUTE_PERMISSION'))
);

const daoId = Address.fromString(DAO_ADDRESS).toHexString();
const where = Address.fromString(CONTRACT_ADDRESS);
const who = Address.fromString(ADDRESS_ONE);
const actor = Address.fromString(ADDRESS_TWO);
const conditionAddress = ADDRESS_THREE;

test('Run dao (handleGranted) mappings with mock event', () => {
// create event and run it's handler
let grantedEvent = createNewGrantedEvent(
contractPermissionId,
ADDRESS_ONE,
DAO_ADDRESS,
CONTRACT_ADDRESS,
ADDRESS_TWO,
DAO_ADDRESS
actor.toHexString(),
where.toHexString(),
who.toHexString(),
conditionAddress,
daoId
);

// handle event
handleGranted(grantedEvent);

// checks
// contractPermissionId
let contractPermissionIdEntityID =
Address.fromString(DAO_ADDRESS).toHexString() +
'_' +
contractPermissionId.toHexString();

assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'id',
contractPermissionIdEntityID
);
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'dao',
Address.fromString(DAO_ADDRESS).toHexString()
);
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'where',
Address.fromString(DAO_ADDRESS).toHexString()
);
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'permissionId',
contractPermissionId.toHexString()
);

// permission
let permissionEntityID =
contractPermissionIdEntityID +
'_' +
Address.fromString(CONTRACT_ADDRESS).toHexString();
let permissionEntityID = [
daoId,
where.toHexString(),
contractPermissionId.toHexString(),
who.toHexString()
].join('_');

assert.fieldEquals(
'Permission',
Expand Down Expand Up @@ -100,18 +77,6 @@ test('Run dao (handleGranted) mappings with reverted mocke call', () => {
handleGranted(grantedEvent);

// checks
// contractPermissionId
let contractPermissionIdEntityID =
Address.fromString(DAO_ADDRESS).toHexString() +
'_' +
contractPermissionId.toHexString();

assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'id',
contractPermissionIdEntityID
);

// governance
let daoPluginEntityID =
Expand All @@ -125,34 +90,22 @@ test('Run dao (handleGranted) mappings with reverted mocke call', () => {
});

test('Run dao (handleRevoked) mappings with mock event', () => {
// create state
let contractPermissionIdEntityID =
Address.fromString(DAO_ADDRESS).toHexString() +
'_' +
contractPermissionId.toHexString();
// permission
let permissionEntityID =
contractPermissionIdEntityID +
'_' +
Address.fromString(CONTRACT_ADDRESS).toHexString();

let contractPermissionIdEntity = new ContractPermissionId(
contractPermissionIdEntityID
);
contractPermissionIdEntity.dao = Address.fromString(
DAO_ADDRESS
).toHexString();
contractPermissionIdEntity.where = Address.fromString(DAO_ADDRESS);
contractPermissionIdEntity.permissionId = contractPermissionId;
contractPermissionIdEntity.save();
let permissionEntityID = [
daoId,
where.toHexString(),
contractPermissionId.toHexString(),
who.toHexString()
].join('_');

let permissionEntity = new Permission(permissionEntityID);
permissionEntity.contractPermissionId = contractPermissionIdEntity.id;
permissionEntity.dao = Address.fromString(DAO_ADDRESS).toHexString();
permissionEntity.where = Address.fromString(CONTRACT_ADDRESS);
permissionEntity.contractPermissionId = contractPermissionId.toHexString();
permissionEntity.permissionId = contractPermissionId;
permissionEntity.who = Address.fromString(ADDRESS_ONE);
permissionEntity.actor = Address.fromString(ADDRESS_ONE);

permissionEntity.dao = Address.fromString(DAO_ADDRESS).toHexString();

permissionEntity.save();

// check state exist
Expand All @@ -166,10 +119,10 @@ test('Run dao (handleRevoked) mappings with mock event', () => {
// create event and run it's handler
let revokedEvent = createNewRevokedEvent(
contractPermissionId,
ADDRESS_ONE,
DAO_ADDRESS,
CONTRACT_ADDRESS,
DAO_ADDRESS
actor.toHexString(),
where.toHexString(),
who.toHexString(),
daoId
);

getEXECUTE_PERMISSION_ID(DAO_ADDRESS, contractPermissionId);
Expand All @@ -178,30 +131,6 @@ test('Run dao (handleRevoked) mappings with mock event', () => {
handleRevoked(revokedEvent);

// checks
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'id',
contractPermissionIdEntityID
);
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'dao',
Address.fromString(DAO_ADDRESS).toHexString()
);
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'where',
Address.fromString(DAO_ADDRESS).toHexString()
);
assert.fieldEquals(
'ContractPermissionId',
contractPermissionIdEntityID,
'permissionId',
contractPermissionId.toHexString()
);

assert.notInStore('Permission', permissionEntityID);

Expand Down

0 comments on commit a831198

Please sign in to comment.