Skip to content

Commit

Permalink
OS-754 : re-organize entity relations & add testing (#15)
Browse files Browse the repository at this point in the history
* re organize entity relations

* add testing for OSx & Plugin

* remove extra files

* Update Satsuma deploy node url

* Clean up

* fix lint

* fix subgraph scripts

* fix subgraph test flow

* ci: fixed linting work flow

* add comment

* OSx: Remove redundant code

* flow: build contracts for subgraph testing

* flow: build root for subgraph testing

* flow: remove comments

* subgraph: update test constants and comments

* subgraph: refactor & add comments

* ci: skip js-client linting

* docs: fix typo

---------

Co-authored-by: Michael Heuer <[email protected]>
  • Loading branch information
Rekard0 and heueristik authored Nov 14, 2023
1 parent fa55216 commit a4a768b
Show file tree
Hide file tree
Showing 20 changed files with 381 additions and 724 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ GRAPH_KEY="zzzzzzzzzzzz"

## Subgraph
SUBGRAPH_NAME="osx"
SUBGRAPH_VERSION="alice-debug-1s"
SUBGRAPH_VERSION="v1.0.0"
SUBGRAPH_NETWORK_NAME="mainnet" # ["mainnet", "goerli", "sepolia", "polygon", "polygonMumbai", "base", "baseGoerli"]
4 changes: 2 additions & 2 deletions .github/workflows/formatting-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: 'Lint contracts ts and js'
run: yarn lint:contracts:ts >> $GITHUB_STEP_SUMMARY

- name: 'Lint js-client ts and js'
run: yarn lint:js-client:ts >> $GITHUB_STEP_SUMMARY
#- name: 'Lint js-client ts and js'
# run: yarn lint:js-client:ts >> $GITHUB_STEP_SUMMARY

- name: 'Lint subgraph ts and js'
run: yarn lint:subgraph:ts >> $GITHUB_STEP_SUMMARY
30 changes: 21 additions & 9 deletions .github/workflows/subgraph-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ on:
push:
paths:
- 'packages/subgraph/**'
- 'packages/contracts/**'
- '.github/workflows/subgraph-*.yml'

jobs:
formatting-linting:
uses: ./.github/workflows/formatting-linting.yml
tests:
runs-on: 'ubuntu-latest'
defaults:
run:
working-directory: packages/subgraph

steps:
- name: 'Check out the repo'
uses: 'actions/checkout@v3'
Expand All @@ -25,14 +24,27 @@ jobs:
cache: 'yarn'
node-version: 18

- name: 'Install the dependencies'
run: 'yarn install'
- name: 'Install root dependencies'
run: yarn install
working-directory: .

- name: 'Install dependencies for contracts'
run: yarn install
working-directory: packages/contracts

- name: 'Install the dependencies for subgraph'
run: yarn install
working-directory: packages/subgraph

- name: 'Build the subgraph'
run: 'yarn build'
run: yarn build
working-directory: packages/subgraph
env:
INFURA_API_KEY: ${{secrets.INFURA_API_KEY}}
NETWORK_NAME: 'goerli'
SUBGRAPH_NETWORK_NAME: ${{ vars.SUBGRAPH_NETWORK_NAME }}
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

- name: 'Test the subgraph'
run: 'yarn test >> $GITHUB_STEP_SUMMARY'
run: yarn test
working-directory: packages/subgraph
env:
GITHUB_STEP_SUMMARY: ${{ secrets.GITHUB_STEP_SUMMARY }}
23 changes: 0 additions & 23 deletions packages/subgraph/commons/erc165.ts

This file was deleted.

44 changes: 3 additions & 41 deletions packages/subgraph/commons/ids.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,14 @@
// TODO: Remove this file and import from OSx-commons-subgraph,
// once the OSx-commons-subgraph npm package is published
import {
Address,
Bytes,
ethereum,
crypto,
ByteArray,
log,
} from '@graphprotocol/graph-ts';

export function getDaoId(dao: Address): string {
return dao.toHexString();
}

export function getPluginPreparationId(
dao: Address,
plugin: Address,
setupId: Bytes
): string | null {
const installationId = getPluginInstallationId(dao, plugin);
if (!installationId) {
log.critical('Failed to get installationId for dao {}, plugin {}', [
dao.toHexString(),
plugin.toHexString(),
]);

return null;
}

const preparationId = installationId
.toHexString()
.concat('_')
.concat(setupId.toHexString());

return preparationId;
}

export function getPluginInstallationId(
export function generatePluginInstallationEntityId(
dao: Address,
plugin: Address
): Bytes | null {
Expand All @@ -58,15 +32,3 @@ export function getPluginInstallationId(
}
return null;
}

export function getPluginVersionId(
pluginRepo: string,
release: i32,
build: i32
): string {
return pluginRepo
.concat('_')
.concat(release.toString())
.concat('_')
.concat(build.toString());
}
84 changes: 84 additions & 0 deletions packages/subgraph/commons/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// TODO: Remove this file and import from OSx-commons-subgraph,
// once the OSx-commons-subgraph npm package is published
import {
InstallationPrepared,
InstallationPreparedPreparedSetupDataStruct,
} from '../generated/PluginSetupProcessor/PluginSetupProcessor';
import {Address, Bytes, ethereum} from '@graphprotocol/graph-ts';
import {newMockEvent} from 'matchstick-as';

export function createInstallationPreparedEvent(
sender: string,
dao: string,
plugin: string,
preparedSetupId: Bytes,
pluginSetupRepo: string,
versionTag: ethereum.Tuple,
data: Bytes,
helpers: string[],
requestedPermissions: ethereum.Value[][]
): InstallationPrepared {
const newEvent = changetype<InstallationPrepared>(newMockEvent());
newEvent.parameters = [];

const permissions: ethereum.Tuple[] = [];
for (let i = 0; i < requestedPermissions.length; i++) {
const permissionTuple = new ethereum.Tuple();
for (let a = 0; a < requestedPermissions[i].length; a++) {
permissionTuple.push(requestedPermissions[i][a]);
}
permissions.push(permissionTuple);
}

const helpersArray: Address[] = [];
for (let i = 0; i < helpers.length; i++) {
helpersArray.push(Address.fromString(helpers[i]));
}

const preparedSetupData = new InstallationPreparedPreparedSetupDataStruct();
preparedSetupData.push(ethereum.Value.fromAddressArray(helpersArray));
preparedSetupData.push(ethereum.Value.fromTupleArray(permissions));

const senderParam = new ethereum.EventParam(
'sender',
ethereum.Value.fromAddress(Address.fromString(sender))
);
const daoParam = new ethereum.EventParam(
'dao',
ethereum.Value.fromAddress(Address.fromString(dao))
);
const preparedSetupIdParam = new ethereum.EventParam(
'preparedSetupId',
ethereum.Value.fromBytes(preparedSetupId)
);
const pluginSetupRepoParam = new ethereum.EventParam(
'pluginSetupRepo',
ethereum.Value.fromAddress(Address.fromString(pluginSetupRepo))
);
const versionTagParam = new ethereum.EventParam(
'versionTag',
ethereum.Value.fromTuple(versionTag)
);
const dataParam = new ethereum.EventParam(
'data',
ethereum.Value.fromBytes(data)
);
const pluginParam = new ethereum.EventParam(
'plugin',
ethereum.Value.fromAddress(Address.fromString(plugin))
);
const preparedSetupDataParam = new ethereum.EventParam(
'preparedSetupData',
ethereum.Value.fromTuple(preparedSetupData)
);

newEvent.parameters.push(senderParam);
newEvent.parameters.push(daoParam);
newEvent.parameters.push(preparedSetupIdParam);
newEvent.parameters.push(pluginSetupRepoParam);
newEvent.parameters.push(versionTagParam);
newEvent.parameters.push(dataParam);
newEvent.parameters.push(pluginParam);
newEvent.parameters.push(preparedSetupDataParam);
return newEvent;
}
13 changes: 13 additions & 0 deletions packages/subgraph/manifest/data/sepolia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"info": "# Do not edit subgraph.yaml,this is a generated file. \n# Instead, edit subgraph.placeholder.yaml and run: yarn manifest",
"network": "sepolia",
"dataSources": {
"PluginSetupProcessors": [
{
"name": "PluginSetupProcessor",
"address": "0xC24188a73dc09aA7C721f96Ad8857B469C01dC9f",
"startBlock": 4415294
}
]
}
}
14 changes: 1 addition & 13 deletions packages/subgraph/manifest/subgraph.placeholder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,9 @@ dataSources:
abis:
- name: PluginSetupProcessor
file: ./imported/PluginSetupProcessor.json
- name: ERC165
file: ./abis/ERC165.json
eventHandlers:
- event: InstallationPrepared(indexed address,indexed address,bytes32,indexed address,(uint8,uint16),bytes,address,(address[],(uint8,address,address,address,bytes32)[]))
handler: handleInstallationPrepared
- event: InstallationApplied(indexed address,indexed address,bytes32,bytes32)
handler: handleInstallationApplied
- event: UpdatePrepared(indexed address,indexed address,bytes32,indexed address,(uint8,uint16),(address,address[],bytes),(address[],(uint8,address,address,address,bytes32)[]),bytes)
handler: handleUpdatePrepared
- event: UpdateApplied(indexed address,indexed address,bytes32,bytes32)
handler: handleUpdateApplied
- event: UninstallationPrepared(indexed address,indexed address,bytes32,indexed address,(uint8,uint16),(address,address[],bytes),(uint8,address,address,address,bytes32)[])
handler: handleUninstallationPrepared
- event: UninstallationApplied(indexed address,indexed address,bytes32)
handler: handleUninstallationApplied
file: ./src/osx/pluginSetupProcessor.ts
{{/dataSources.PluginSetupProcessors}}
# templates
Expand All @@ -58,7 +46,7 @@ templates:
- Dao
abis:
- name: Plugin
file: $PLUGIN_MODULE/artifacts/src/MyPlugin.sol/MyPlugin.json
file: $PLUGIN_MODULE/contracts/artifacts/src/MyPlugin.sol/MyPlugin.json
eventHandlers:
- event: NumberStored(uint256)
handler: handleNumberStored
Expand Down
106 changes: 4 additions & 102 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,108 +1,10 @@
# Types

# Executions

type Action @entity {
id: ID!
to: Bytes!
value: BigInt!
data: Bytes!
dao: Dao!
proposal: IProposal!
execResult: Bytes
}

# Dao

type Dao @entity {
id: ID! # use address as id
actions: [Action!]! @derivedFrom(field: "dao")
proposals: [IProposal!]! @derivedFrom(field: "dao")
plugins: [Plugin!]! @derivedFrom(field: "dao")
}

# Plugins

type PluginPreparation @entity(immutable: true) {
# OSX related data
id: ID! # psp setupId + installationId

# Set plugin specific related data below:
}

interface PluginInstallation @entity {
# OSX related data
id: ID! # psp installationId
dao: Dao!

# Set plugin specific related data below:
}

# Plugin

type Plugin implements PluginInstallation @entity {
type DaoPlugin @entity {
"OSX related data"
id: ID! # psp installationId
dao: Dao!
dao: Bytes!
pluginAddress: Bytes!

"Set plugin specific related data below:"
number: BigInt!
proposals: [PluginProposal!]! @derivedFrom(field: "plugin")
members: [PluginMember!]! @derivedFrom(field: "plugin")
}

type PluginMember @entity {
id: ID! # plugin_address + member_address
address: String # address as string to facilitate filtering by address on the UI
proposals: [PluginProposalMember!]! @derivedFrom(field: "approver")
plugin: Plugin!
}

type PluginProposalMember @entity(immutable: true) {
"MemberProposal for Many-to-Many"
id: ID! # approver + proposal
approver: PluginMember!
proposal: PluginProposal!
createdAt: BigInt!
}

# Proposal
interface IProposal {
id: ID! # package + proposalId
dao: Dao!
creator: Bytes!
metadata: String
actions: [Action!]! @derivedFrom(field: "proposal")
allowFailureMap: BigInt!
failureMap: BigInt
executed: Boolean!
createdAt: BigInt!
startDate: BigInt!
endDate: BigInt!
executionTxHash: Bytes
}

type PluginProposal implements IProposal @entity {
id: ID! # plugin + proposalId
dao: Dao!
actions: [Action!]! @derivedFrom(field: "proposal")
allowFailureMap: BigInt!
failureMap: BigInt
plugin: Plugin!
pluginProposalId: BigInt!
creator: Bytes!
metadata: String
createdAt: BigInt!
startDate: BigInt!
endDate: BigInt!
creationBlockNumber: BigInt!
snapshotBlock: BigInt!
minApprovals: Int!
approvals: Int
potentiallyExecutable: Boolean!
executed: Boolean!
executionDate: BigInt
executionBlockNumber: BigInt
executionTxHash: Bytes
approvers: [PluginProposalMember!]! @derivedFrom(field: "proposal")
number: BigInt
}
Loading

0 comments on commit a4a768b

Please sign in to comment.