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: update action entity and proposal #11

Merged
merged 14 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@aragon/osx-commons-subgraph": "^0.0.4"
"@aragon/osx-commons-subgraph": "^0.0.5"
}
}
15 changes: 11 additions & 4 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type AdminProposal implements IProposal @entity {
metadata: String
actions: [Action!]! @derivedFrom(field: "proposal")
allowFailureMap: BigInt!
failureMap: BigInt
executed: Boolean!
createdAt: BigInt!
startDate: BigInt!
Expand All @@ -44,14 +43,23 @@ type AdminProposal implements IProposal @entity {
executionTxHash: Bytes
}

type Action @entity {
interface IAction {
id: ID! # ActionEntityId
to: Bytes!
value: BigInt!
data: Bytes!
daoAddress: Bytes!
}

type Action implements IAction @entity(immutable: true) {
id: ID! # ActionEntityId
to: Bytes!
value: BigInt!
data: Bytes!
daoAddress: Bytes!

# proposal data
proposal: IProposal!
execResult: Bytes
}

interface IProposal {
Expand All @@ -61,7 +69,6 @@ interface IProposal {
metadata: String
actions: [Action!]! @derivedFrom(field: "proposal")
allowFailureMap: BigInt!
failureMap: BigInt
executed: Boolean!
createdAt: BigInt!
startDate: BigInt!
Expand Down
7 changes: 6 additions & 1 deletion packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ export function _handleProposalCreated(
for (let index = 0; index < actions.length; index++) {
const action = actions[index];

const actionEntityId = generateActionEntityId(proposalEntityId, index);
const actionEntityId = generateActionEntityId(
pluginAddress,
Address.fromString(daoAddress),
pluginProposalId.toString(),
index
);
const actionEntity = new Action(actionEntityId);
actionEntity.to = action.to;
actionEntity.value = action.value;
Expand Down
60 changes: 44 additions & 16 deletions packages/subgraph/tests/plugin/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,27 @@ describe('Plugin', () => {
ALLOW_FAILURE_MAP
);

// check actions
// check action
assert.entityCount('Action', 1);
const actionEntityId = generateActionEntityId(proposalEntityId, 0);
const actionEntityId = generateActionEntityId(
pluginAddress,
Address.fromString(DAO_ADDRESS),
pluginProposalId.toString(),
0
);
const actionEntity = Action.load(actionEntityId);
if (actionEntity) {
assert.fieldEquals('Action', actionEntityId, 'id', actionEntityId);
assert.fieldEquals('Action', actionEntityId, 'to', ADDRESS_TWO);
assert.fieldEquals('Action', actionEntityId, 'value', actionValue);
assert.fieldEquals('Action', actionEntityId, 'data', actionData);
assert.fieldEquals('Action', actionEntityId, 'daoAddress', DAO_ADDRESS);
assert.fieldEquals(
'Action',
actionEntityId,
'proposal',
proposalEntityId
);
}
assert.entityCount('Action', 1);
assert.fieldEquals('Action', actionEntityId, 'id', actionEntityId);
assert.fieldEquals('Action', actionEntityId, 'to', ADDRESS_TWO);
assert.fieldEquals('Action', actionEntityId, 'value', actionValue);
assert.fieldEquals('Action', actionEntityId, 'data', actionData);
assert.fieldEquals('Action', actionEntityId, 'daoAddress', DAO_ADDRESS);
assert.fieldEquals(
'Action',
actionEntityId,
'proposal',
proposalEntityId
);
});
});

Expand All @@ -194,7 +198,12 @@ describe('Plugin', () => {

createAdminProposalState(proposalEntityId, administratorAddress);

const actionEntityId = generateActionEntityId(proposalEntityId, 0);
const actionEntityId = generateActionEntityId(
pluginAddress,
Address.fromString(DAO_ADDRESS),
pluginProposalId.toString(),
0
);
let action = new Action(actionEntityId);
action.to = Address.fromString(ADDRESS_TWO);
action.value = BigInt.fromString(actionValue);
Expand Down Expand Up @@ -253,4 +262,23 @@ describe('Plugin', () => {
assert.dataSourceExists('AdminMembers', DAO_ADDRESS);
});
});

test('We correctly generate the action ID', () => {
clauBv23 marked this conversation as resolved.
Show resolved Hide resolved
let caller = pluginAddress;
let daoAddress = DAO_ADDRESS;
let callId = 'c4ll me';
let index = 255;

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

assert.stringEquals(
actionId,
[caller.toHexString(), daoAddress, callId, index.toString()].join('_')
);
});
});
8 changes: 4 additions & 4 deletions packages/subgraph/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
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==
"@aragon/osx-commons-subgraph@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@aragon/osx-commons-subgraph/-/osx-commons-subgraph-0.0.5.tgz#7e0c0f854e4ca52de1d937595c9bb6ef0370f840"
integrity sha512-M5edVTYyHbkcDLr2H8ySCbOpLA+5pUdN7tCYCif0pDP99Wb+/njgO23G2B2FjB4Q3hB0fCkLkQwNp9QplJjqGA==
dependencies:
"@graphprotocol/graph-ts" "0.31.0"

Expand Down
Loading