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: changed the action entity id and added tests #15

Merged
merged 8 commits into from
Apr 2, 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
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 @@ -13,7 +13,6 @@ interface IProposal {
metadata: String
actions: [Action!]! @derivedFrom(field: "proposal")
allowFailureMap: BigInt!
failureMap: BigInt
executed: Boolean!
createdAt: BigInt!
startDate: BigInt!
Expand All @@ -27,6 +26,14 @@ interface Token {
symbol: String
}

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

# Enums

enum VoteOption {
Expand Down Expand Up @@ -98,7 +105,6 @@ type TokenVotingProposal implements IProposal @entity {
daoAddress: Bytes!
actions: [Action!]! @derivedFrom(field: "proposal")
allowFailureMap: BigInt!
failureMap: BigInt
plugin: TokenVotingPlugin!
pluginProposalId: BigInt! # pluginAddress + proposalId padded
creator: Bytes!
Expand Down Expand Up @@ -132,14 +138,15 @@ type TokenVotingProposal implements IProposal @entity {

# Executions

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

# proposal specific data
proposal: IProposal!
execResult: Bytes
}

# Token Contracts
Expand Down
10 changes: 8 additions & 2 deletions packages/subgraph/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import {RATIO_BASE, VOTER_OPTIONS, VOTING_MODES} from '../utils/constants';
import {identifyAndFetchOrCreateERC20TokenEntity} from '../utils/erc20';
import {generateMemberEntityId, generateVoteEntityId} from '../utils/ids';
import {
generateActionEntityId,
generatePluginEntityId,
generateProposalEntityId,
generateActionEntityId,
} from '@aragon/osx-commons-subgraph';
import {
Address,
BigInt,
Bytes,
dataSource,
Expand Down Expand Up @@ -92,7 +93,12 @@ export function _handleProposalCreated(
for (let index = 0; index < actions.length; index++) {
const action = actions[index];

const actionId = generateActionEntityId(proposalEntityId, index);
const actionId = generateActionEntityId(
pluginAddress,
Address.fromString(daoId),
pluginProposalId.toString(),
index
);

const actionEntity = new Action(actionId);
actionEntity.to = action.to;
Expand Down
120 changes: 116 additions & 4 deletions packages/subgraph/tests/plugin/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {ProposalCreated} from '../../generated/templates/TokenVoting/TokenVoting';
import {PLUGIN_REPO_ADDRESS} from '../../imported/repo-address';
import {
handleVoteCast,
handleProposalExecuted,
Expand All @@ -23,12 +25,28 @@ import {
ZERO,
TWO,
ERC20_AMOUNT_FULL,
DAO_ADDRESS,
} from '../utils/constants';
import {createDummyAction} from '@aragon/osx-commons-subgraph';
import {bigInt, BigInt} from '@graphprotocol/graph-ts';
import {assert, clearStore, describe, test} from 'matchstick-as/assembly/index';
import {
createDummyAction,
generateActionEntityId,
} from '@aragon/osx-commons-subgraph';
import {Address, bigInt, BigInt, ethereum} from '@graphprotocol/graph-ts';
import {
assert,
clearStore,
describe,
newMockEvent,
test,
} from 'matchstick-as/assembly/index';

let dummyActionTo = DAO_TOKEN_ADDRESS;
let dummyActionValue = '0';
let dummyActionData = '0x00000000';

let actions = [createDummyAction(DAO_TOKEN_ADDRESS, '0', '0x00000000')];
let actions = [
createDummyAction(dummyActionTo, dummyActionValue, dummyActionData),
];

test('Run TokenVoting (handleProposalCreated) mappings with mock event', () => {
// create state
Expand Down Expand Up @@ -288,3 +306,97 @@ describe('handleMembershipContractAnnounced', () => {
clearStore();
});
});

describe('Testing Actions', () => {
test('A new proposal action is registered during the proposal creation', () => {
// manual re-write so this approach can be ported to other plugins
assert.entityCount('Action', 0);
assert.entityCount('TokenVotingProposal', 0);

let tokenVotingPlugin = new ExtendedTokenVotingPlugin().withDefaultValues();
let proposal = new ExtendedTokenVotingProposal().withDefaultValues();

// step 1: create the mock proposal event
tokenVotingPlugin.proposalCount = BigInt.fromString(ONE);
tokenVotingPlugin.mockCall_getProposalCountCall();
proposal.mockCall_getProposal(actions);
proposal.mockCall_totalVotingPower();

const proposalEvent = changetype<ProposalCreated>(newMockEvent());
proposalEvent.address = Address.fromString(proposal.plugin);

let proposalId = new BigInt(0);
let creator = proposal.creator;
let startDate = proposal.startDate;
let endDate = proposal.endDate;

let metadata: string;
if (proposal.metadata) {
metadata = proposal.metadata as string;
} else {
metadata = 'metadata';
}
let allowFailureMap = proposal.allowFailureMap;

let proposalIdEvent = new ethereum.EventParam(
'proposalId',
ethereum.Value.fromUnsignedBigInt(
BigInt.fromString(proposalId.toString())
)
);

let creatorEvent = new ethereum.EventParam(
'creator',
ethereum.Value.fromAddress(Address.fromBytes(creator))
);
let startDateEvent = new ethereum.EventParam(
'startDate',
ethereum.Value.fromUnsignedBigInt(startDate)
);
let endDateEvent = new ethereum.EventParam(
'endDate',
ethereum.Value.fromUnsignedBigInt(endDate)
);
let metadataEvent = new ethereum.EventParam(
'metadata',
ethereum.Value.fromString(metadata as string)
);
let actionsEvent = new ethereum.EventParam(
'actions',
ethereum.Value.fromTupleArray(actions)
);
let allowFailureMapEvent = new ethereum.EventParam(
'allowFailureMap',
ethereum.Value.fromUnsignedBigInt(allowFailureMap)
);

proposalEvent.parameters = [
proposalIdEvent,
creatorEvent,
startDateEvent,
endDateEvent,
metadataEvent,
actionsEvent,
allowFailureMapEvent,
];

// step 2: handle the proposal event
_handleProposalCreated(proposalEvent, DAO_ADDRESS, metadata);

// step 3: check that the proposal action was created
assert.entityCount('Action', 1);
assert.entityCount('TokenVotingProposal', 1);

// step 3.1: check that the action has the correct fields
const actionID = generateActionEntityId(
Address.fromString(proposal.plugin),
Address.fromString(DAO_ADDRESS),
proposalId.toString(),
0
);
assert.fieldEquals('Action', actionID, 'to', dummyActionTo.toLowerCase());
assert.fieldEquals('Action', actionID, 'value', dummyActionValue);
assert.fieldEquals('Action', actionID, 'data', dummyActionData);
assert.fieldEquals('Action', actionID, 'proposal', proposal.id);
});
});
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