Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use commons subgraph #29

Merged
merged 6 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions packages/subgraph/commons/ids.ts

This file was deleted.

8 changes: 6 additions & 2 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
"clean": "rimraf deploy-output.txt subgraph.yaml ./build ./imported ./generated ./tests/.bin tests/.latest.json && yarn postinstall"
},
"devDependencies": {
"@aragon/osx-ethers": "1.3.0",
"@graphprotocol/graph-cli": "^0.51.0",
"@graphprotocol/graph-ts": "^0.31.0",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"matchstick-as": "^0.5.2",
"mustache": "^4.2.0",
"@aragon/osx-ethers": "1.4.0-alpha.0",
"@aragon/osx-commons-configs": "0.2.0",
"ts-morph": "^17.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2",
"dotenv": "^16.3.1"
"typescript": "^5.2.2"
},
"dependencies": {
"@aragon/osx-commons-subgraph": "^0.0.4"
}
}
7 changes: 3 additions & 4 deletions packages/subgraph/src/osx/pluginSetupProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {generatePluginInstallationEntityId} from '../../commons/ids';
import {InstallationPrepared} from '../../generated/PluginSetupProcessor/PluginSetupProcessor';
import {DaoPlugin} from '../../generated/schema';
import {Plugin as PluginTemplate} from '../../generated/templates';
import {PLUGIN_REPO_ADDRESS} from '../../imported/repo-address';
import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph';
import {Address, DataSourceContext, log} from '@graphprotocol/graph-ts';

export function handleInstallationPrepared(event: InstallationPrepared): void {
Expand All @@ -29,11 +29,10 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
]);
return;
}

// Load or create a new entry for the this plugin using the generated installation ID.
let pluginEntity = DaoPlugin.load(installationId.toHexString());
let pluginEntity = DaoPlugin.load(installationId!);
if (!pluginEntity) {
pluginEntity = new DaoPlugin(installationId.toHexString());
pluginEntity = new DaoPlugin(installationId!);
}

// Set the DAO and plugin address for the plugin entity.
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {generatePluginInstallationEntityId} from '../../commons/ids';
import {DaoPlugin} from '../../generated/schema';
import {NumberStored} from '../../generated/templates/Plugin/Plugin';
import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph';
import {Address, dataSource} from '@graphprotocol/graph-ts';

export function handleNumberStored(event: NumberStored): void {
Expand All @@ -15,7 +15,7 @@ export function handleNumberStored(event: NumberStored): void {
);

if (installationId) {
const pluginEntity = DaoPlugin.load(installationId.toHexString());
const pluginEntity = DaoPlugin.load(installationId);
if (pluginEntity) {
pluginEntity.number = event.params.number;
pluginEntity.save();
Expand Down
15 changes: 4 additions & 11 deletions packages/subgraph/tests/osx/pluginSetupProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {generatePluginInstallationEntityId} from '../../commons/ids';
import {createInstallationPreparedEvent} from '../../commons/test';
import {PLUGIN_REPO_ADDRESS} from '../../imported/repo-address';
import {handleInstallationPrepared} from '../../src/osx/pluginSetupProcessor';
import {
Expand All @@ -13,6 +11,8 @@ import {
DAO_ADDRESS,
PLUGIN_SETUP_ID,
} from '../utils/constants';
import {createInstallationPreparedEvent} from '../utils/events';
import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph';
import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts';
import {assert, afterEach, clearStore, test, describe} from 'matchstick-as';

Expand Down Expand Up @@ -60,8 +60,6 @@ describe('OSx', () => {
],
];

let installationIdString = installationId.toHexString();

const otherPluginSetupRepo = ADDRESS_TWO;

const event1 = createInstallationPreparedEvent(
Expand All @@ -78,7 +76,7 @@ describe('OSx', () => {

handleInstallationPrepared(event1);

assert.notInStore('DaoPlugin', installationIdString);
assert.notInStore('DaoPlugin', installationId!);
assert.entityCount('DaoPlugin', 0);

const thisPluginRepoAddress = PLUGIN_REPO_ADDRESS;
Expand All @@ -97,13 +95,8 @@ describe('OSx', () => {

handleInstallationPrepared(event2);

assert.fieldEquals(
'DaoPlugin',
installationIdString,
'id',
installationIdString
);
assert.entityCount('DaoPlugin', 1);
assert.fieldEquals('DaoPlugin', installationId!, 'id', installationId!);
});
});
});
Expand Down
17 changes: 5 additions & 12 deletions packages/subgraph/tests/plugin/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {generatePluginInstallationEntityId} from '../../commons/ids';
import {DaoPlugin} from '../../generated/schema';
import {handleNumberStored} from '../../src/plugin/plugin';
import {CONTRACT_ADDRESS, DAO_ADDRESS} from '../utils/constants';
import {createNewNumberStoredEvent} from './utils';
import {createNewNumberStoredEvent} from '../utils/events';
import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph';
import {Address, DataSourceContext} from '@graphprotocol/graph-ts';
import {
assert,
Expand Down Expand Up @@ -37,10 +37,8 @@ describe('Plugin', () => {
if (!installationId) {
throw new Error('Failed to get installationId');
}
const installationIdHex = installationId.toHexString();

// Create state
let daoPlugin = new DaoPlugin(installationIdHex);
let daoPlugin = new DaoPlugin(installationId!);
daoPlugin.dao = daoAddress;
daoPlugin.pluginAddress = pluginAddress;
daoPlugin.save();
Expand All @@ -54,13 +52,8 @@ describe('Plugin', () => {

handleNumberStored(event);

assert.fieldEquals(
'DaoPlugin',
installationIdHex,
'id',
installationIdHex
);
assert.fieldEquals('DaoPlugin', installationIdHex, 'number', number);
assert.fieldEquals('DaoPlugin', installationId!, 'id', installationId!);
assert.fieldEquals('DaoPlugin', installationId!, 'number', number);
assert.entityCount('DaoPlugin', 1);
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/tests/utils/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './osx';
export * from './plugin';
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// 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';
} from '../../../generated/PluginSetupProcessor/PluginSetupProcessor';
import {Address, Bytes, ethereum} from '@graphprotocol/graph-ts';
import {newMockEvent} from 'matchstick-as';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NumberStored} from '../../generated/templates/Plugin/Plugin';
import {NumberStored} from '../../../generated/templates/Plugin/Plugin';
import {Address, BigInt, ethereum} from '@graphprotocol/graph-ts';
import {newMockEvent} from 'matchstick-as';

Expand Down
9 changes: 8 additions & 1 deletion packages/subgraph/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
dependencies:
tslib "^2.6.2"

"@aragon/osx-commons-subgraph@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@aragon/osx-commons-subgraph/-/osx-commons-subgraph-0.0.4.tgz#2aa52f3089d21189c9152d2f3d14c0d7c66d129f"
integrity sha512-cqhusJ3HNvMx+t9lXfN+Hy/5ipefNs1Tdxe+y0GvD4qgBMVU4tCbsxOpB9U2JEJNBCzFQj4E/872FFLpIErB4w==
dependencies:
"@graphprotocol/graph-ts" "0.31.0"

"@aragon/[email protected]":
version "1.4.0-alpha.0"
resolved "https://registry.yarnpkg.com/@aragon/osx-ethers/-/osx-ethers-1.4.0-alpha.0.tgz#329f1ac27660b486fa0b296dddeb004ce352001c"
Expand Down Expand Up @@ -444,7 +451,7 @@
which "2.0.2"
yaml "1.10.2"

"@graphprotocol/graph-ts@^0.31.0":
"@graphprotocol/graph-ts@0.31.0", "@graphprotocol/graph-ts@^0.31.0":
version "0.31.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.31.0.tgz#730668c0369828b31bef81e8d9bc66b9b48e3480"
integrity sha512-xreRVM6ho2BtolyOh2flDkNoGZximybnzUnF53zJVp0+Ed0KnAlO1/KOCUYw06euVI9tk0c9nA2Z/D5SIQV2Rg==
Expand Down
Loading