Skip to content

Commit

Permalink
chore(packages/decoder): fix prettier path
Browse files Browse the repository at this point in the history
  • Loading branch information
dandheedge committed May 6, 2024
1 parent f6594a1 commit f82aeaf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/decoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "tsup src/index.ts --watch",
"lint": "eslint \"src/**/*.ts*\"",
"format": "prettier \"src/**/*.ts*\" --write",
"format:check": "prettier \"src/**/*.ts*\" --check",
"format:check": "prettier \"**/*.{ts,tsx}\" --check",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"test:watch": "vitest",
"test:ci": "vitest run --coverage"
},
Expand Down
82 changes: 41 additions & 41 deletions packages/decoder/test/decodeVoucherPayload.test.ts
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);
});
});
5 changes: 3 additions & 2 deletions packages/decoder/test/mock.ts
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";

0 comments on commit f82aeaf

Please sign in to comment.