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: registry processor #14

Merged
merged 13 commits into from
Oct 23, 2024
Merged

feat: registry processor #14

merged 13 commits into from
Oct 23, 2024

Conversation

0xkenj1
Copy link
Collaborator

@0xkenj1 0xkenj1 commented Oct 22, 2024

🤖 Linear

Closes GIT-86 GIT-87 GIT-88 GIT-89

Description

  • RegistryProcessor
  • RoleGrantedHandler
  • ProfileCreatedHandler

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

Copy link

linear bot commented Oct 22, 2024

@0xkenj1 0xkenj1 changed the title Feat/registry processor feat: registry processor Oct 22, 2024
@0xkenj1 0xkenj1 requested a review from 0xnigir1 October 22, 2024 15:20
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, just a few comments

@@ -1,6 +1,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { Registry } from "../../generated";

// Handler for ProfileNameUpdated event
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Handler for ProfileNameUpdated event
// Handler for RoleGranted event

// Handler for ProfileNameUpdated event
Registry.RoleGranted.handler(async ({}) => {});

// Handler for ProfileOwnerUpdated event
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Handler for ProfileOwnerUpdated event
// Handler for RoleRevoked event

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in file name

@@ -0,0 +1,2 @@
export * from "./profileCreated.hanlder.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -1,3 +1,5 @@
import { Branded } from "../internal.js";

export type ChainId = Branded<number, "ChainId">;

export type Bytes32String = Branded<`0x${string}`, "Bytes32String">;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this type different from Hex from Viem?

await expect(handler.handle()).rejects.toThrow(InvalidAddressError);
});

it("should throw an error if projectRepository throws an error", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should throw an error if projectRepository throws an error", async () => {
it("throw an error if projectRepository throws an error", async () => {

mockedEvent["params"]["role"] = "0x1231231234" as Bytes32String;
const event = mockedEvent;

mockProjectRepository.getProjectById.mockResolvedValueOnce(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we test undefined case too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we only need to test undefined since this is the signature getProjectById(chainId: ChainId, projectId: string): Promise<Project | undefined>;

0xnigir1
0xnigir1 previously approved these changes Oct 22, 2024
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

@0xkenj1 0xkenj1 requested review from jahabeebs and 0xyaco October 22, 2024 18:40
Copy link
Collaborator

@jahabeebs jahabeebs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice pr, made a couple of comments 🤠

) {}
async handle(): Promise<Changeset[]> {
const { projectRepository } = this.dependencies;
const role = this.event.params.role.toLocaleLowerCase();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be toLocaleLowerCase rather than toLowerCase()? Not sure if you want different behavior depending on locale-specific case mappings

}

const account = getAddress(this.event.params.account);
const project = await projectRepository.getProjectById(this.chainId, role);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just double checking that the role will definitely be the profileId unless role === ALLO_OWNER_ROLE. No other validation needed?

Copy link
Collaborator Author

@0xkenj1 0xkenj1 Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no other needed, i will double check it anyways :)

@@ -1,6 +1,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { Registry } from "../../generated";

// Handler for RoleGranted event
Registry.RoleGranted.handler(async ({}) => {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a TODO for this file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing to do here. Won't need to fill the handler with any code, this line is just needed to save the event on the database :)

vi.resetAllMocks();
});

it("should throw UnsupportedEventException for unsupported events", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should 😄

const { metadataProvider, evmProvider, projectRepository } = this.dependencies;
const profileId = this.event.params.profileId;
const metadataCid = this.event.params.metadata[1];
const metadata = await metadataProvider.getMetadata(metadataCid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there's no error handling here--are you okay with the error bubbling up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea is to buble the error up to the Processors and finally handle the errors there. But will figure it out on a specific milestone that we set up specifically for error handling :)


// The member role for an Allo V2 profile, is the profileId itself.
// If a project exists with that id, we create the member role
// If it doesn't exists we create a pending project role. This can happens
Copy link
Collaborator

@jahabeebs jahabeebs Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*exist
*happen

@0xkenj1 0xkenj1 requested review from jahabeebs and 0xnigir1 October 23, 2024 16:51
Copy link
Collaborator

@jahabeebs jahabeebs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just two test naming fixes but can fix it in another PR, let's gooo

await expect(processor.process(event)).rejects.toThrow(UnsupportedEventException);
});

it("should call ProfileCreatedHandler", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should call ProfileCreatedHandler", async () => {
it("calls ProfileCreatedHandler", async () => {

expect(result).toEqual([]); // Check if handle returns []
});

it("should call RoleGrantedHandler", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should call RoleGrantedHandler", async () => {
it("calls RoleGrantedHandler", async () => {

@0xkenj1 0xkenj1 merged commit 28dcae6 into dev Oct 23, 2024
6 checks passed
@0xkenj1 0xkenj1 deleted the feat/registry-processor branch October 23, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants