Skip to content

Commit

Permalink
fix: formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
okhaimie-dev authored and fracek committed Dec 9, 2023
1 parent 3d665d5 commit 8608ba8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
29 changes: 14 additions & 15 deletions packages/indexer/src/starknet/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import { Contract } from './parser';
import { describe, expect, it } from "vitest"
import { Contract } from "./parser";
import { describe, expect, it } from "vitest";
import { FieldElement } from "./felt";
import { EventAbi } from "starknet";

describe('Contract class tests', () => {
const mockContractAddress: FieldElement = '0x0';
describe("Contract class tests", () => {
const mockContractAddress: FieldElement = "0x0";
const mockEventAbi: EventAbi = {
type: 'event',
name: 'MockEvent',
kind: 'struct',
members: [{ name: 'param1', type: 'felt', kind: 'key' }],
type: "event",
name: "MockEvent",
kind: "struct",
members: [{ name: "param1", type: "felt", kind: "key" }],
};

const mockContractAbi = [mockEventAbi];

it('should create an EventFilter for a valid event name', () => {
it("should create an EventFilter for a valid event name", () => {
const contract = new Contract(mockContractAddress, mockContractAbi);
const filter = contract.eventFilter('MockEvent');
const filter = contract.eventFilter("MockEvent");

expect(filter).toBeDefined();
expect(filter.fromAddress).toBe(mockContractAddress);
// Further assertions can be made based on the expected structure of EventFilter
});

it('should throw an error for an invalid event name', () => {
it("should throw an error for an invalid event name", () => {
const contract = new Contract(mockContractAddress, mockContractAbi);

expect(() => {
contract.eventFilter('InvalidEvent');
}).toThrow('Event InvalidEvent not found in contract ABI');
contract.eventFilter("InvalidEvent");
}).toThrow("Event InvalidEvent not found in contract ABI");
});

});
});
3 changes: 1 addition & 2 deletions packages/indexer/src/starknet/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { EventFilter } from "./filter";

import { type Abi, EventAbi, hash } from "starknet";


// The Contract class implements the EventFilterParser interface.
export class Contract {
// Read-only properties for the contract's address and its ABI.
Expand All @@ -19,7 +18,7 @@ export class Contract {
private _findEvent(name: string): EventAbi | undefined {
// Find the event in the ABI matching the provided name.
const event: EventAbi | undefined = this.contractAbi.find(
(item) => item.type === "event" && item.name === name
(item) => item.type === "event" && item.name === name,
);

return event;
Expand Down

0 comments on commit 8608ba8

Please sign in to comment.