-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(packages/decoder): fix prettier path
- Loading branch information
1 parent
f6594a1
commit f82aeaf
Showing
3 changed files
with
46 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
import { autoload, whatsabi } from "@shazow/whatsabi"; | ||
import { decodeFunctionData } from "viem"; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { decodeVoucherPayload } from '../src/index'; | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { decodeVoucherPayload } from "../src/index"; | ||
import { provider } from "../src/utils/provider"; | ||
|
||
vi.mock("@shazow/whatsabi"); | ||
const whatsAbiMocked = vi.mocked(autoload, true) | ||
const whatsAbiMocked = vi.mocked(autoload, true); | ||
vi.mock("viem"); | ||
const viemMocked = vi.mocked(decodeFunctionData, true) | ||
|
||
describe('decodeVoucherPayload', () => { | ||
it('should decode a valid payload', async () => { | ||
const mockAbi = { abi: 'mockAbi' }; | ||
const mockFunctionName = 'testFunction'; | ||
const mockArgs = ['arg1', 'arg2']; | ||
|
||
whatsAbiMocked.mockResolvedValue(mockAbi as unknown as any); | ||
viemMocked.mockReturnValue({ | ||
functionName: mockFunctionName, | ||
args: mockArgs | ||
} as unknown as any); | ||
|
||
const result = await decodeVoucherPayload({ | ||
destination: '0x123', | ||
payload: '0x456' | ||
const viemMocked = vi.mocked(decodeFunctionData, true); | ||
|
||
describe("decodeVoucherPayload", () => { | ||
it("should decode a valid payload", async () => { | ||
const mockAbi = { abi: "mockAbi" }; | ||
const mockFunctionName = "testFunction"; | ||
const mockArgs = ["arg1", "arg2"]; | ||
|
||
whatsAbiMocked.mockResolvedValue(mockAbi as unknown as any); | ||
viemMocked.mockReturnValue({ | ||
functionName: mockFunctionName, | ||
args: mockArgs, | ||
} as unknown as any); | ||
|
||
const result = await decodeVoucherPayload({ | ||
destination: "0x123", | ||
payload: "0x456", | ||
}); | ||
|
||
expect(result).toEqual({ | ||
functionName: mockFunctionName, | ||
args: mockArgs, | ||
}); | ||
expect(whatsabi.autoload).toHaveBeenCalledWith("0x123", { provider }); | ||
expect(decodeFunctionData).toHaveBeenCalledWith({ | ||
abi: mockAbi.abi, | ||
data: "0x456", | ||
}); | ||
}); | ||
|
||
expect(result).toEqual({ | ||
functionName: mockFunctionName, | ||
args: mockArgs | ||
}); | ||
expect(whatsabi.autoload).toHaveBeenCalledWith('0x123', { provider }); | ||
expect(decodeFunctionData).toHaveBeenCalledWith({ | ||
abi: mockAbi.abi, | ||
data: '0x456' | ||
}); | ||
}); | ||
it("should return the original payload on error", async () => { | ||
const error = new Error("Test error"); | ||
const consoleError = vi.spyOn(console, "error"); | ||
vi.spyOn(whatsabi, "autoload").mockRejectedValue(error); | ||
|
||
it('should return the original payload on error', async () => { | ||
const error = new Error('Test error'); | ||
const consoleError = vi.spyOn(console, 'error'); | ||
vi.spyOn(whatsabi, 'autoload').mockRejectedValue(error); | ||
const result = await decodeVoucherPayload({ | ||
destination: "0x123", | ||
payload: "0x456", | ||
}); | ||
|
||
const result = await decodeVoucherPayload({ | ||
destination: '0x123', | ||
payload: '0x456' | ||
expect(result).toBe("0x456"); | ||
expect(consoleError).toHaveBeenCalledWith(error); | ||
}); | ||
|
||
expect(result).toBe('0x456'); | ||
expect(consoleError).toHaveBeenCalledWith(error); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const destinationAddress = "0x4f3143568D076F171A21C571fE58143475DCCa2c" | ||
export const payload = "0xd0def52100000000000000000000000041070efed9ead91380aae5e164dac1001f64c9910000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005d68747470733a2f2f676174657761792e70696e6174612e636c6f75642f697066732f6261666b72656966347972737562706b64656537326b6676347072696632356c3771346f346c72767562717a6a3765723334726733707237647834000000" | ||
export const destinationAddress = "0x4f3143568D076F171A21C571fE58143475DCCa2c"; | ||
export const payload = | ||
"0xd0def52100000000000000000000000041070efed9ead91380aae5e164dac1001f64c9910000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005d68747470733a2f2f676174657761792e70696e6174612e636c6f75642f697066732f6261666b72656966347972737562706b64656537326b6676347072696632356c3771346f346c72767562717a6a3765723334726733707237647834000000"; |