-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Handler for ProfileNameUpdated event | |
// Handler for RoleGranted event |
// Handler for ProfileNameUpdated event | ||
Registry.RoleGranted.handler(async ({}) => {}); | ||
|
||
// Handler for ProfileOwnerUpdated event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Handler for ProfileOwnerUpdated event | |
// Handler for RoleRevoked event |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
packages/shared/src/types/common.ts
Outdated
@@ -1,3 +1,5 @@ | |||
import { Branded } from "../internal.js"; | |||
|
|||
export type ChainId = Branded<number, "ChainId">; | |||
|
|||
export type Bytes32String = Branded<`0x${string}`, "Bytes32String">; |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫡
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ({}) => {}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*exist
*happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
There was a problem hiding this 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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("should call ProfileCreatedHandler", async () => { | |
it("calls ProfileCreatedHandler", async () => { |
expect(result).toEqual([]); // Check if handle returns [] | ||
}); | ||
|
||
it("should call RoleGrantedHandler", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("should call RoleGrantedHandler", async () => { | |
it("calls RoleGrantedHandler", async () => { |
🤖 Linear
Closes GIT-86 GIT-87 GIT-88 GIT-89
Description
RegistryProcessor
RoleGrantedHandler
ProfileCreatedHandler
Checklist before requesting a review