-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor tests for the new entity relations
- Loading branch information
Showing
3 changed files
with
102 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 14 additions & 106 deletions
120
packages/subgraph/tests/dao/permission-manager.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,46 @@ | ||
import {assert, clearStore, test} from 'matchstick-as/assembly/index'; | ||
import {Address, ByteArray, Bytes, crypto} from '@graphprotocol/graph-ts'; | ||
import {Address} from '@graphprotocol/graph-ts'; | ||
|
||
import {handleGranted, handleRevoked} from '../../src/dao/dao_v1_0_0'; | ||
import {Permission} from '../../generated/schema'; | ||
import { | ||
DAO_ADDRESS, | ||
ADDRESS_ONE, | ||
CONTRACT_ADDRESS, | ||
ADDRESS_TWO, | ||
ADDRESS_THREE | ||
} from '../constants'; | ||
import { | ||
createNewGrantedEvent, | ||
createNewRevokedEvent, | ||
getEXECUTE_PERMISSION_ID, | ||
getEXECUTE_PERMISSION_IDreverted | ||
} from './utils'; | ||
|
||
const contractPermissionId = Bytes.fromByteArray( | ||
crypto.keccak256(ByteArray.fromUTF8('EXECUTE_PERMISSION')) | ||
); | ||
import {DAO_ADDRESS} from '../constants'; | ||
import {getEXECUTE_PERMISSION_ID} from './utils'; | ||
import {ExtendedPermission} from '../helpers/extended-schema'; | ||
|
||
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, | ||
actor.toHexString(), | ||
where.toHexString(), | ||
who.toHexString(), | ||
conditionAddress, | ||
daoId | ||
); | ||
|
||
// handle event | ||
handleGranted(grantedEvent); | ||
|
||
// checks | ||
let permissionEntityID = [ | ||
daoId, | ||
where.toHexString(), | ||
contractPermissionId.toHexString(), | ||
who.toHexString() | ||
].join('_'); | ||
|
||
assert.fieldEquals( | ||
'Permission', | ||
permissionEntityID, | ||
'id', | ||
permissionEntityID | ||
); | ||
|
||
clearStore(); | ||
}); | ||
|
||
test('Run dao (handleGranted) mappings with reverted mocke call', () => { | ||
// create event and run it's handler | ||
let grantedEvent = createNewGrantedEvent( | ||
contractPermissionId, | ||
ADDRESS_ONE, | ||
DAO_ADDRESS, | ||
CONTRACT_ADDRESS, | ||
ADDRESS_TWO, | ||
DAO_ADDRESS | ||
); | ||
let permission = new ExtendedPermission().withDefaultValues(daoId); | ||
permission.dao = daoId; | ||
|
||
// launch calls | ||
getEXECUTE_PERMISSION_IDreverted(DAO_ADDRESS); | ||
let grantedEvent = permission.createEvent_Granted(daoId); | ||
|
||
// handle event | ||
handleGranted(grantedEvent); | ||
|
||
// checks | ||
|
||
// governance | ||
let daoPluginEntityID = | ||
Address.fromString(DAO_ADDRESS).toHexString() + | ||
'_' + | ||
Address.fromString(CONTRACT_ADDRESS).toHexString(); | ||
|
||
assert.notInStore('DaoPlugin', daoPluginEntityID); | ||
permission.assertEntity(); | ||
|
||
clearStore(); | ||
}); | ||
|
||
test('Run dao (handleRevoked) mappings with mock event', () => { | ||
// permission | ||
let permissionEntityID = [ | ||
daoId, | ||
where.toHexString(), | ||
contractPermissionId.toHexString(), | ||
who.toHexString() | ||
].join('_'); | ||
let permission = new ExtendedPermission().withDefaultValues(daoId); | ||
permission.dao = daoId; | ||
|
||
let permissionEntity = new Permission(permissionEntityID); | ||
permissionEntity.where = Address.fromString(CONTRACT_ADDRESS); | ||
permissionEntity.permissionId = contractPermissionId; | ||
permissionEntity.who = Address.fromString(ADDRESS_ONE); | ||
permissionEntity.actor = Address.fromString(ADDRESS_ONE); | ||
|
||
permissionEntity.dao = Address.fromString(DAO_ADDRESS).toHexString(); | ||
|
||
permissionEntity.save(); | ||
permission.save(); | ||
|
||
// check state exist | ||
assert.fieldEquals( | ||
'Permission', | ||
permissionEntityID, | ||
'id', | ||
permissionEntityID | ||
); | ||
permission.assertEntity(); | ||
|
||
// create event and run it's handler | ||
let revokedEvent = createNewRevokedEvent( | ||
contractPermissionId, | ||
actor.toHexString(), | ||
where.toHexString(), | ||
who.toHexString(), | ||
daoId | ||
); | ||
|
||
getEXECUTE_PERMISSION_ID(DAO_ADDRESS, contractPermissionId); | ||
let revokedEvent = permission.createEvent_Revoked(daoId); | ||
|
||
// handle event | ||
handleRevoked(revokedEvent); | ||
|
||
// checks | ||
|
||
assert.notInStore('Permission', permissionEntityID); | ||
assert.notInStore('Permission', permission.id); | ||
|
||
clearStore(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters