Skip to content

Commit

Permalink
fix: use pluginEntityId (the plugin address as a hex string)
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Mar 15, 2024
1 parent e6d9a98 commit 45cf45c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
interface IPlugin {
id: ID! # PluginInstallationEntityId
id: ID! # PluginEntityId
dao: Dao!
pluginAddress: Bytes!
}

# Types
type MultisigPlugin implements IPlugin @entity {
id: ID! # PluginInstallationEntityId
id: ID! # PluginEntityId
dao: Bytes!
pluginAddress: Bytes!

Expand Down
27 changes: 9 additions & 18 deletions packages/subgraph/src/osx/pluginSetupProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {InstallationPrepared} from '../../generated/PluginSetupProcessor/PluginS
import {MultisigPlugin} 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 {generatePluginEntityId} from '@aragon/osx-commons-subgraph';
import {Address, DataSourceContext, log} from '@graphprotocol/graph-ts';

Check failure on line 6 in packages/subgraph/src/osx/pluginSetupProcessor.ts

View workflow job for this annotation

GitHub Actions / checks

'log' is defined but never used. Allowed unused vars must match /_/u

Check failure on line 6 in packages/subgraph/src/osx/pluginSetupProcessor.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'log' is defined but never used. Allowed unused vars must match /_/u

export function handleInstallationPrepared(event: InstallationPrepared): void {
Expand All @@ -17,34 +17,25 @@ export function handleInstallationPrepared(event: InstallationPrepared): void {
}

const dao = event.params.dao;
const plugin = event.params.plugin;

// Generate a unique ID for the plugin installation.
const installationId = generatePluginInstallationEntityId(dao, plugin);
// Log an error and exit if unable to generate the installation ID.
if (!installationId) {
log.error('Failed to generate installationId', [
dao.toHexString(),
plugin.toHexString(),
]);
return;
}
// Load or create a new entry for the this plugin using the generated installation ID.
let pluginEntity = MultisigPlugin.load(installationId!);
const pluginAddress = event.params.plugin;

const pluginEntityId = generatePluginEntityId(pluginAddress);
let pluginEntity = MultisigPlugin.load(pluginEntityId);

if (!pluginEntity) {
pluginEntity = new MultisigPlugin(installationId!);
pluginEntity = new MultisigPlugin(pluginEntityId);
}

// Set the DAO and plugin address for the plugin entity.
pluginEntity.dao = dao;
pluginEntity.pluginAddress = plugin;
pluginEntity.pluginAddress = pluginAddress;

// Initialize a context for the plugin data source to enable indexing from the moment of preparation.
const context = new DataSourceContext();
// Include the DAO address in the context for future reference.
context.setString('daoAddress', dao.toHexString());
// Deploy a template for the plugin to facilitate individual contract indexing.
PluginTemplate.createWithContext(plugin, context);
PluginTemplate.createWithContext(pluginAddress, context);

pluginEntity.save();
}
18 changes: 10 additions & 8 deletions packages/subgraph/tests/osx/pluginSetupProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
PLUGIN_SETUP_ID,
} from '../utils/constants';
import {createInstallationPreparedEvent} from '../utils/events';
import {generatePluginInstallationEntityId} from '@aragon/osx-commons-subgraph';
import {
generatePluginEntityId,
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 All @@ -27,12 +30,11 @@ describe('OSx', () => {
// Create event
const daoAddress = DAO_ADDRESS;
const pluginAddress = CONTRACT_ADDRESS;
const installationId = generatePluginInstallationEntityId(
Address.fromString(daoAddress),
const pluginEntityId = generatePluginEntityId(
Address.fromString(pluginAddress)
);
if (!installationId) {
throw new Error('Failed to get installationId');
if (!pluginEntityId) {
throw new Error('Failed to get pluginEntityId');
}
const setupId = PLUGIN_SETUP_ID;
const versionTuple = new ethereum.Tuple();
Expand Down Expand Up @@ -76,7 +78,7 @@ describe('OSx', () => {

handleInstallationPrepared(event1);

assert.notInStore('MultisigPlugin', installationId!);
assert.notInStore('MultisigPlugin', pluginEntityId!);
assert.entityCount('MultisigPlugin', 0);

const thisPluginRepoAddress = PLUGIN_REPO_ADDRESS;
Expand All @@ -98,9 +100,9 @@ describe('OSx', () => {
assert.entityCount('MultisigPlugin', 1);
assert.fieldEquals(
'MultisigPlugin',
installationId!,
pluginEntityId!,
'id',
installationId!
pluginEntityId!
);
});
});
Expand Down

0 comments on commit 45cf45c

Please sign in to comment.