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

F/os 587 abstract actions and callback ids #14

Merged
merged 2 commits into from
Nov 2, 2023
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
1 change: 1 addition & 0 deletions subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `generateActionEntityId` and `generateStandardCAllbackEntityId`.
- Added `generatePermissionId` and `generatePluginPermissionId`.
- Added `generatePluginRepoEntityId`, `generatePluginSetupEntityId`, `generatePluginInstallationEntityId`, `generatePluginPreparationEntityId`, `generatePluginReleaseEntityId`, and `generatePluginVersionEntityId`.

Expand Down
16 changes: 16 additions & 0 deletions subgraph/src/ids/callbacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Address, Bytes} from '@graphprotocol/graph-ts';

/**
* Generates a unique StandardCallback ID using the given parameters.
*
* @param dao - Address of the DAO
* @param interfaceId - Interface ID of the emitted event
* @returns A concatenated ID string for the StandardCallback entity.
*/
export function generateStandardCallbackEntityId(
dao: Address,
interfaceId: Bytes
): string {
const ids = [dao.toHexString(), interfaceId.toHexString()];
return ids.join('_');
}
14 changes: 14 additions & 0 deletions subgraph/src/ids/proposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Generates a unique action ID using the given parameters.
*
* @param proposalId - The id of the proposal that the action belongs to.
* @param index - The index of the action within the proposal.
* @returns A concatenated ID string for the Action entity.
*/
export function generateActionEntityId(
proposalEntityId: string,
index: i32
): string {
const ids = [proposalEntityId, index.toString()];
return ids.join('_');
}
2 changes: 2 additions & 0 deletions subgraph/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const DUMMY_BYTES32_HEX =
'0x0000000000000000000000000000000000000000000000000000000000000000';
export const DUMMY_INSTALLATION_ID =
'0x000f1e7f040a60eb32b1b2348cf41924f85e221648a4d0a5ba66d2dea1122ee6';

export const DUMMY_PROPOSAL_ID = [ADDRESS_ZERO, DUMMY_BYTES32_HEX].join('_');
18 changes: 18 additions & 0 deletions subgraph/tests/ids/callbacks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {generateStandardCallbackEntityId} from '../../src/ids/callbacks';
import {ADDRESS_ONE, DUMMY_BYTES32_HEX} from '../constants';
import {Address, Bytes} from '@graphprotocol/graph-ts';
import {assert, describe, test} from 'matchstick-as/assembly/index';

describe('Standard Callback Entity ID generation', () => {
test('`generateStandardCallbackEntityId` should return the expected ID', () => {
const dao = Address.fromString(ADDRESS_ONE);
const interfaceId = Bytes.fromHexString(DUMMY_BYTES32_HEX);

const expectedId = `${dao.toHexString()}_${interfaceId.toHexString()}`;

assert.stringEquals(
generateStandardCallbackEntityId(dao, interfaceId),
expectedId
);
});
});
14 changes: 14 additions & 0 deletions subgraph/tests/ids/proposal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {generateActionEntityId} from '../../src/ids/proposal';
import {DUMMY_PROPOSAL_ID} from '../constants';
import {assert, describe, test} from 'matchstick-as/assembly/index';

describe('Proposal ID generation', () => {
test('`generateActionEntityId` should return the id representation of an action', () => {
const proposalId = DUMMY_PROPOSAL_ID;
const index = 0;

const expectedId = `${proposalId}_${index}`;

assert.stringEquals(generateActionEntityId(proposalId, index), expectedId);
});
});