Skip to content

Commit

Permalink
Merge pull request #68 from aragon/f/generate-action-id
Browse files Browse the repository at this point in the history
feat: update generateActionEntityId to include all of data on caller, dao, callId and actionIndex
  • Loading branch information
jordaniza authored Mar 28, 2024
2 parents 96b2eda + d3e79d9 commit 403c441
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 25 deletions.
6 changes: 6 additions & 0 deletions subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v0.0.5

### Changed

`getActionEntityId` now is composed of the caller, daoAddress, callId and the actionIndex.

## v0.0.4

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aragon/osx-commons-subgraph",
"version": "0.0.4",
"version": "0.0.5",
"description": "The Aragon OSx subgraph package containing common utilities",
"module": "index.ts",
"types": "index.ts",
Expand Down
28 changes: 28 additions & 0 deletions subgraph/src/ids/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {generateEntityIdFromAddress} from './ids';
import {Address} from '@graphprotocol/graph-ts';

/**
* @param caller the user/plugin that will invoke the execute function on the DAO
* @param daoAddress the DAO address
* @param callId the callID determined by the user or plugin
* @param index the index # of the action in the batch
*
* @returns a deterministic Action ID for an action on the DAO.
* This implementation only relies on data that can be fetched
* from the event logs of the `Executed` event, so can be used
* by client applications to query both the OSx core and the plugin
* subgraphs.
*/
export function generateActionEntityId(
caller: Address,
daoAddress: Address,
callId: string,
index: i32
): string {
return [
generateEntityIdFromAddress(caller),
generateEntityIdFromAddress(daoAddress),
callId,
index.toString(),
].join('_');
}
1 change: 1 addition & 0 deletions subgraph/src/ids/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './actions';
export * from './balance';
export * from './callbacks';
export * from './dao';
Expand Down
14 changes: 0 additions & 14 deletions subgraph/src/ids/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import {
} from './ids';
import {Address, BigInt, Bytes} from '@graphprotocol/graph-ts';

/**
* 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 {
return [proposalEntityId, index.toString()].join('_');
}

/**
* Generates a unique identifier for a transaction action proposal entity.
* @param proposalEntityId - The ID of the proposal entity.
Expand Down
31 changes: 31 additions & 0 deletions subgraph/tests/ids/actions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {generateActionEntityId} from '../../src';
import {ADDRESS_ONE, ADDRESS_TWO} from '../constants';
import {Address} from '@graphprotocol/graph-ts';
import {describe, test, assert} from 'matchstick-as';

function checksum(s: string): string {
return Address.fromHexString(s).toHexString();
}

describe('Actions ID generation', () => {
test('We correctly generate the action ID', () => {
const caller = ADDRESS_ONE;
const daoAddress = ADDRESS_TWO;
const callId = 'c4ll me';
const index = 255;

const actionId = generateActionEntityId(
Address.fromString(caller),
Address.fromString(daoAddress),
callId,
index
);

assert.stringEquals(
actionId,
[checksum(caller), checksum(daoAddress), callId, index.toString()].join(
'_'
)
);
});
});
11 changes: 1 addition & 10 deletions subgraph/tests/ids/proposal.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import {
generateActionEntityId,
generateProposalEntityId,
generateTransactionActionsProposalEntityId,
} from '../../src/ids/proposal';
import {bigIntToBytes32} from '../../src/utils/utils';
import {ADDRESS_ONE, DUMMY_BYTES32_HEX, DUMMY_PROPOSAL_ID} from '../constants';
import {ADDRESS_ONE, DUMMY_BYTES32_HEX} from '../constants';
import {Address, BigInt, Bytes} from '@graphprotocol/graph-ts';
import {assert, describe, test} from 'matchstick-as';

describe('Transaction Actions 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);
});
test('`generateTransactionActionsProposalEntityId` should return the id representation of a transaction actions proposal', () => {
const proposalEntityId = generateProposalEntityId(
Address.fromString(ADDRESS_ONE),
Expand Down

0 comments on commit 403c441

Please sign in to comment.