Skip to content

Commit

Permalink
✅ server: add fail when tracing test
Browse files Browse the repository at this point in the history
  • Loading branch information
nfmelendez committed Nov 5, 2024
1 parent 244fa5c commit 16a1764
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/test/hooks/cryptomate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import app from "../../hooks/cryptomate";
import deriveAddress from "../../utils/deriveAddress";
import keeper from "../../utils/keeper";
import publicClient from "../../utils/publicClient";
import traceClient from "../../utils/traceClient";

const appClient = testClient(app);

Expand Down Expand Up @@ -101,6 +102,15 @@ const receipt = {
type: "0x0",
} as const;

const callFrame = {
type: "CALL",
from: "",
to: "",
gas: "0x",
gasUsed: "0x",
input: "0x",
} as const;

async function collectorBalance() {
return await publicClient
.call({
Expand Down Expand Up @@ -178,6 +188,8 @@ describe("card operations", () => {
});
});

afterEach(() => vi.restoreAllMocks());

it("authorizes credit", async () => {
const response = await appClient.index.$post({
...authorization,
Expand Down Expand Up @@ -212,6 +224,27 @@ describe("card operations", () => {
expect(response.status).toBe(200);
await expect(response.json()).resolves.toStrictEqual({ response_code: "00" });
});

it("fails when tracing", async () => {
const captureException = vi.spyOn(sentry, "captureException");
captureException.mockImplementation(() => "");

const trace = vi.spyOn(traceClient, "traceCall").mockResolvedValue({ ...callFrame, output: "0x" });

await database.insert(cards).values([{ id: "failed_trace", credentialId: "cred", lastFour: "2222", mode: 4 }]);
const response = await appClient.index.$post({
...authorization,
json: {
...authorization.json,
data: { ...authorization.json.data, card_id: "failed_trace", metadata: { account } },
},
});

expect(trace).toHaveBeenCalledOnce();
expect(captureException).toHaveBeenCalledWith(new Error("0x"), expect.anything());
expect(response.status).toBe(200);
await expect(response.json()).resolves.toStrictEqual({ response_code: "69" });
});
});
});

Expand Down

0 comments on commit 16a1764

Please sign in to comment.