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

fix(subgraph): remove call handler and use events for poll init #348

Merged
merged 1 commit into from
Sep 18, 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
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
Loading