Skip to content

Commit

Permalink
Merge pull request #348 from privacy-scaling-explorations/fix/subgrap…
Browse files Browse the repository at this point in the history
…h-parsing

fix(subgraph): remove call handler and use events for poll init
  • Loading branch information
ctrlc03 authored Sep 18, 2024
2 parents dc5a31f + c6906b0 commit ae1355f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
3 changes: 3 additions & 0 deletions packages/contracts/contracts/maci/Poll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract Poll is Ownable, BasePoll, ICommon {

/// @notice events
event SetRegistry(address indexed registry);
event PollInit();

/// @notice custom errors
error RegistryAlreadyInitialized();
Expand Down Expand Up @@ -113,6 +114,8 @@ contract Poll is Ownable, BasePoll, ICommon {
function init() public override onlyOwner isRegistryInitialized {
initTime = block.timestamp;
super.init();

emit PollInit();
}

/// @inheritdoc BasePoll
Expand Down
8 changes: 4 additions & 4 deletions packages/subgraph/config/network.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": "optimism-sepolia",
"maciContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3",
"registryManagerContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3",
"registryManagerContractStartBlock": 13160483,
"maciContractStartBlock": 13160483
"maciContractAddress": "0xac4d16D0541ca7255579b501A2F1D6F3a436521E",
"registryManagerContractAddress": "0xed5875D05DebcDdDbd902f471447dA97c6d26d7E",
"registryManagerContractStartBlock": 17396799,
"maciContractStartBlock": 17396799
}
8 changes: 4 additions & 4 deletions packages/subgraph/src/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { Poll, Vote, MACI } from "../generated/schema";
import {
InitCall,
MergeMaciState as MergeMaciStateEvent,
MergeMessageAq as MergeMessageAqEvent,
MergeMessageAqSubRoots as MergeMessageAqSubRootsEvent,
PollInit as PollInitEvent,
PublishMessage as PublishMessageEvent,
SetRegistry as SetRegistryEvent,
} from "../generated/templates/Poll/Poll";
Expand Down Expand Up @@ -84,13 +84,13 @@ export function handleSetRegistry(event: SetRegistryEvent): void {
poll.save();
}

export function handleInitPoll(call: InitCall): void {
const poll = Poll.load(call.to);
export function handleInitPoll(event: PollInitEvent): void {
const poll = Poll.load(event.address);

if (!poll) {
return;
}

poll.initTime = call.block.timestamp;
poll.initTime = event.block.timestamp;
poll.save();
}
3 changes: 1 addition & 2 deletions packages/subgraph/templates/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ templates:
handler: handlePublishMessage
- event: SetRegistry(indexed address)
handler: handleSetRegistry
callHandlers:
- function: init()
- event: PollInit()
handler: handleInitPoll
file: ./src/poll.ts

Expand Down
10 changes: 5 additions & 5 deletions packages/subgraph/tests/poll/poll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
createMergeMessageAqSubRootsEvent,
createPublishMessageEvent,
createSetRegistryEvent,
createInitPollCall,
createInitPollEvent,
} from "./utils";

export {
Expand Down Expand Up @@ -49,13 +49,13 @@ describe("Poll", () => {
});

test("should handle merge maci state properly", () => {
const call = createInitPollCall(DEFAULT_POLL_ADDRESS);
const event = createInitPollEvent(DEFAULT_POLL_ADDRESS);

handleInitPoll(call);
handleInitPoll(event);

const poll = Poll.load(call.to)!;
const poll = Poll.load(event.address)!;

assert.fieldEquals("Poll", poll.id.toHex(), "initTime", call.block.timestamp.toString());
assert.fieldEquals("Poll", poll.id.toHex(), "initTime", event.block.timestamp.toString());
});

test("should handle poll initialization properly", () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/subgraph/tests/poll/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Address, BigInt as GraphBN, ethereum } from "@graphprotocol/graph-ts";
// eslint-disable-next-line import/no-extraneous-dependencies
import { newMockEvent, newMockCall } from "matchstick-as";
import { newMockEvent } from "matchstick-as";

import {
InitCall,
MergeMaciState,
MergeMessageAq,
MergeMessageAqSubRoots,
PublishMessage,
SetRegistry,
PollInit,
} from "../../generated/templates/Poll/Poll";

export function createInitPollCall(address: Address): InitCall {
const call = changetype<InitCall>(newMockCall());
call.to = address;
export function createInitPollEvent(address: Address): PollInit {
const event = changetype<PollInit>(newMockEvent());
event.address = address;

return call;
return event;
}

export function createMergeMaciStateEvent(address: Address, stateRoot: GraphBN, numSignups: GraphBN): MergeMaciState {
Expand Down

0 comments on commit ae1355f

Please sign in to comment.