Skip to content

Commit

Permalink
feat(native): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jagnani73 committed Feb 27, 2024
1 parent 4232721 commit 80ebf0a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion services/decoder/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export class GoldRushDecoder {

const nativeDecoderPath: string = join(
__dirname,
`native-transfer.decoder.${this.fileExtension}`
"native",
`native.decoder.${this.fileExtension}`
);
require(join(nativeDecoderPath));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GoldRushDecoder } from "./decoder";
import { type EventType } from "./decoder.types";
import { GoldRushDecoder } from "../decoder";
import { type EventType } from "../decoder.types";

import { DECODED_ACTION, DECODED_EVENT_CATEGORY } from "./decoder.constants";
import { DECODED_ACTION, DECODED_EVENT_CATEGORY } from "../decoder.constants";

GoldRushDecoder.native((tx): EventType => {
return {
Expand Down
23 changes: 23 additions & 0 deletions services/decoder/native/native.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import request from "supertest";
import app from "../../../api";
import { type EventType } from "../decoder.types";

describe("Native", () => {
test("Native Transfer", async () => {
const res = await request(app)
.post("/api/v1/tx/decode")
.set({ "x-covalent-api-key": process.env.TEST_COVALENT_API_KEY })
.send({
chain_name: "eth-mainnet",
tx_hash:
"0xfa6d5bd3041f6d904e96e592d5d339907637d1c445b8464184dba92d728e7234",
});
const { events } = res.body as { events: EventType[] };
const event = events.find(({ name }) => name === "Native Transfer");
if (!event) {
throw Error("Event not found");
}
expect(event.details?.length).toEqual(2);
expect(event.tokens?.length).toEqual(1);
});
});

0 comments on commit 80ebf0a

Please sign in to comment.