-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
770 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
zkeys/ | ||
proofs/ | ||
tally.json | ||
|
||
session-keys.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { genPimlicoRPCUrl } from "../accountAbstraction"; | ||
import { ErrorCodes } from "../errors"; | ||
|
||
describe("common", () => { | ||
describe("genPimlicoRPCUrl", () => { | ||
test("should return the correct RPCUrl", () => { | ||
const rpcUrl = genPimlicoRPCUrl("optimism-sepolia"); | ||
expect(rpcUrl).toBeDefined(); | ||
expect(rpcUrl).toContain("https://api.pimlico.io/v2/optimism-sepolia/rpc"); | ||
}); | ||
|
||
test("should throw when PIMLICO_API_KEY is not set", () => { | ||
delete process.env.PIMLICO_API_KEY; | ||
expect(() => genPimlicoRPCUrl("optimism-sepolia")).toThrow(ErrorCodes.PIMLICO_API_KEY_NOT_SET); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import dotenv from "dotenv"; | ||
|
||
import { ErrorCodes } from "./errors"; | ||
|
||
dotenv.config(); | ||
|
||
/** | ||
* Generate the RPCUrl for Pimlico based on the chain we need to interact with | ||
* @param network - the network we want to interact with | ||
* @returns the RPCUrl for the network | ||
*/ | ||
export const genPimlicoRPCUrl = (network: string): string => { | ||
const pimlicoAPIKey = process.env.PIMLICO_API_KEY; | ||
|
||
if (!pimlicoAPIKey) { | ||
throw new Error(ErrorCodes.PIMLICO_API_KEY_NOT_SET); | ||
} | ||
|
||
return `https://api.pimlico.io/v2/${network}/rpc?apikey=${pimlicoAPIKey}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/coordinator/ts/sessionKeys/__tests__/sessionKeys.controller.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Test } from "@nestjs/testing"; | ||
import { zeroAddress } from "viem"; | ||
|
||
import type { IGenerateSessionKeyReturn } from "../types"; | ||
|
||
import { SessionKeysController } from "../sessionKeys.controller"; | ||
import { SessionKeysService } from "../sessionKeys.service"; | ||
|
||
describe("SessionKeysController", () => { | ||
let sessionKeysController: SessionKeysController; | ||
|
||
const mockSessionKeysService = { | ||
generateSessionKey: jest.fn(), | ||
deactivateSessionKey: jest.fn(), | ||
}; | ||
|
||
const defaultGenerateSessionKeyReturn: IGenerateSessionKeyReturn = { | ||
sessionKeyAddress: zeroAddress, | ||
}; | ||
|
||
beforeEach(async () => { | ||
const app = await Test.createTestingModule({ | ||
controllers: [SessionKeysController], | ||
}) | ||
.useMocker((token) => { | ||
if (token === SessionKeysService) { | ||
mockSessionKeysService.generateSessionKey.mockResolvedValue(defaultGenerateSessionKeyReturn); | ||
return mockSessionKeysService; | ||
} | ||
|
||
return jest.fn(); | ||
}) | ||
.compile(); | ||
|
||
sessionKeysController = app.get<SessionKeysController>(SessionKeysController); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("v1/session-keys/generate", () => { | ||
test("should return a session key address", async () => { | ||
const data = await sessionKeysController.generateSessionKey(); | ||
expect(data).toStrictEqual(defaultGenerateSessionKeyReturn); | ||
}); | ||
}); | ||
|
||
describe("v1/session-keys/delete", () => { | ||
test("should delete a session key", () => { | ||
sessionKeysController.deactivateSessionKey({ | ||
sessionKeyAddress: zeroAddress, | ||
}); | ||
expect(mockSessionKeysService.deactivateSessionKey).toHaveBeenCalledWith(zeroAddress); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.