Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeon committed Nov 7, 2023
1 parent 18fbb9f commit cbd1fb1
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 9 deletions.
59 changes: 54 additions & 5 deletions packages/subgraph/tests/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import {handlePluginSettingsUpdated} from '../src/plugin/plugin';
import {createPlugin, pluginSettingsUpdatedEvent} from './utils';
import {Address, log} from '@graphprotocol/graph-ts';
import {
handlePluginSettingsUpdated,
handleProposalCreated,
} from '../src/plugin/plugin';
import {
createPlugin,
pluginProposalCreatedEvent,
pluginSettingsUpdatedEvent,
} from './utils';
import {Address, BigInt, ethereum, log} from '@graphprotocol/graph-ts';
import {
describe,
test,
Expand All @@ -11,13 +18,14 @@ import {
} from 'matchstick-as/assembly/index';

const PLUGIN_ENTITY_TYPE = 'Plugin';
const PROPOSAL_ENTITY_TYPE = 'PluginProposal';

describe('Events', () => {
describe('Plugin Events', () => {
afterEach(() => {
clearStore();
});

test('Plugin Creation and update', () => {
test('Plugin entity creation and update', () => {
const firstDaoAString = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
const firstPluginAString = '0x758b8178A9A4B7206D1f648c4a77C515CbaC7000';
const firstDaoTokenAString = '0xa66ab9d321273fb415ff2539d38dd1a6e8b78a25';
Expand Down Expand Up @@ -90,4 +98,45 @@ describe('Events', () => {
'false'
);
});

test('Proposal creation', () => {
const firstDaoAString = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
const firstPluginAString = '0x758b8178A9A4B7206D1f648c4a77C515CbaC7000';
const firstDaoTokenAString = '0xa66ab9d321273fb415ff2539d38dd1a6e8b78a25';
const firstPluginId = createPlugin(
Address.fromString(firstDaoAString),
Address.fromString(firstPluginAString)
);

let newPluginEvent = pluginSettingsUpdatedEvent(
firstPluginAString,
firstDaoAString,
true,
1,
1,
1,
1,
1,
firstDaoTokenAString,
'0x2a1290d5d0Dd792Ad8e1C257a691F24E97675644',
1
);
handlePluginSettingsUpdated(newPluginEvent);

let newProposalEvent = pluginProposalCreatedEvent(
firstPluginAString,
firstDaoAString,
1,
'0x2a1290d5d0dd792ad8e1c257a691f24e97675644'
);

handleProposalCreated(newProposalEvent);
logStore();
});

// test('Proposal execution', () => {});
// test('Committee members added', () => {});
// test('Committee members removed', () => {});
// test('Tally set', () => {});
// test('Tally approve', () => {});
});
51 changes: 47 additions & 4 deletions packages/subgraph/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { getPluginInstallationId } from '../commons/ids';
import { Plugin } from '../generated/schema';
import {PluginSettingsUpdated} from '../generated/templates/Plugin/VocdoniVoting';
import {handlePluginSettingsUpdated} from '../src/plugin/plugin';
import {Address, Bytes, DataSourceContext, Value, ethereum} from '@graphprotocol/graph-ts';
import {dataSourceMock, newMockEvent} from 'matchstick-as';
import {PluginSettingsUpdated, ProposalCreated} from '../generated/templates/Plugin/VocdoniVoting';
import {Address, BigInt, Bytes, DataSourceContext, Value, ethereum} from '@graphprotocol/graph-ts';
import {dataSourceMock, log, newMockEvent} from 'matchstick-as';

export function createPlugin(dao: Address, plugin: Address): Bytes{
const installationId = getPluginInstallationId(dao, plugin);
Expand Down Expand Up @@ -91,3 +90,47 @@ export function pluginSettingsUpdatedEvent(

return newPluginSettingsUpdatedEvent;
}

export function pluginProposalCreatedEvent(
eventAddress: string,
daoAddress: string,
proposalId: number,
// allowFailureMap: number,
// vochainProposalId: string,
creator: string,
// startDate: number,
// voteEndDate: number,
// tallyEndDate: number,
// createdAt: number,
// creationBlockNumber: number,
// snapshotBlock: number
): ProposalCreated {
let newPluginProposalCreatedEvent = changetype<ProposalCreated>(
newMockEvent()
);
newPluginProposalCreatedEvent.address = Address.fromString(eventAddress);

// Set the data context for the event
let context = new DataSourceContext()
context.set('daoAddress', Value.fromString(daoAddress));
dataSourceMock.setContext(context);

let proposalIdParam = new ethereum.EventParam(
'proposalId',
ethereum.Value.fromI32(<i32>proposalId)
);
// let creatorParam = new ethereum.EventParam(
// 'creator',
// ethereum.Value.fromAddress(Address.fromString(creator))
// );
// let allowFailureMapParam = new ethereum.EventParam(
// 'allowFailureMap',
// ethereum.Value.fromI32(0)
// );

newPluginProposalCreatedEvent.parameters = new Array();
newPluginProposalCreatedEvent.parameters.push(proposalIdParam);
// newPluginProposalCreatedEvent.parameters.push(allowFailureMapParam);

return newPluginProposalCreatedEvent;
}

0 comments on commit cbd1fb1

Please sign in to comment.