Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Merge branch 'main' into test/activate-all-indexer-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored Oct 30, 2024
2 parents 5cd93a0 + 2c468f5 commit bbbc9ae
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ lint:
actions:
disabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
enabled:
- trunk-upgrade-available
- trunk-fmt-pre-commit
- trunk-check-pre-push
101 changes: 64 additions & 37 deletions indexer/deno.lock

Large diffs are not rendered by default.

42 changes: 34 additions & 8 deletions indexer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { padString } from "./utils/hex.ts";
import { hash } from "./deps.ts";

// Get Sink Type or returns "console" if the value is null or undefined
export const SINK_TYPE = (() => {
export const SINK_TYPE: "console" | "mongo" = (() => {
const addr = Deno.env.get("SINK_TYPE") ?? "console";
if (addr !== "console" && addr !== "mongo") {
throw new Error("Invalid SINK_TYPE");
Expand All @@ -11,17 +11,23 @@ export const SINK_TYPE = (() => {
})();

// Get the sink options from the sink type
export const SINK_OPTIONS = SINK_TYPE === "mongo"
export const SINK_OPTIONS: {
connectionString?: string;
database?: string;
collectionNames: string[];
} = SINK_TYPE === "mongo"
? {
connectionString: Deno.env.get("MONGO_CONNECTION_STRING") ??
"mongodb://mongo:mongo@mongo:27017",
database: Deno.env.get("MONGO_DATABASE_NAME") ?? "kakarot-test-db",
collectionNames: ["headers", "transactions", "receipts", "logs"],
}
: {};
: {
collectionNames: [],
};

// Get the starting block or returns 0 if the value is null or undefined
export const STARTING_BLOCK = (() => {
export const STARTING_BLOCK: number = (() => {
const startingBlock = Number(Deno.env.get("STARTING_BLOCK") ?? 0);
return Number.isSafeInteger(startingBlock) && startingBlock >= 0
? startingBlock
Expand All @@ -31,16 +37,17 @@ export const STARTING_BLOCK = (() => {
})();

// Get authentication token from Apibara or returns an empty string if the value is null or undefined
export const AUTH_TOKEN = Deno.env.get("APIBARA_AUTH_TOKEN") ?? "";
export const AUTH_TOKEN: string = Deno.env.get("APIBARA_AUTH_TOKEN") ?? "";

// Get stream URL or returns "http://localhost:7171" if the value is null or undefined
export const STREAM_URL = Deno.env.get("STREAM_URL") ?? "http://localhost:7171";
export const STREAM_URL: string = Deno.env.get("STREAM_URL") ??
"http://localhost:7171";

// Creates string that starts with "0x" and is padded to a total length of 64 chars
export const NULL_HASH = padString("0x", 32);
export const NULL_HASH: string = padString("0x", 32);

// Get the hash selector from the transaction executed
export const TRANSACTION_EXECUTED = hash.getSelectorFromName(
export const TRANSACTION_EXECUTED: string = hash.getSelectorFromName(
"transaction_executed",
);

Expand All @@ -50,3 +57,22 @@ export const KAKAROT_ADDRESS: string = (() => {
if (!kakarotAddress) throw new Error("ENV: KAKAROT_ADDRESS is not set");
return kakarotAddress;
})();

// A default block gas limit in case the call to get_block_gas_limit fails.
export const DEFAULT_BLOCK_GAS_LIMIT: string = (() => {
const defaultBlockGasLimitStr = Deno.env.get("DEFAULT_BLOCK_GAS_LIMIT");
if (!defaultBlockGasLimitStr) {
throw new Error("ENV: DEFAULT_BLOCK_GAS_LIMIT is not set");
}
return defaultBlockGasLimitStr;
})();

// Events containing these keys are not
// ETH logs and should be ignored.
export const IGNORED_KEYS: bigint[] = [
BigInt(hash.getSelectorFromName("transaction_executed")),
BigInt(hash.getSelectorFromName("evm_contract_deployed")),
BigInt(hash.getSelectorFromName("Transfer")),
BigInt(hash.getSelectorFromName("Approval")),
BigInt(hash.getSelectorFromName("OwnershipTransferred")),
];
11 changes: 1 addition & 10 deletions indexer/src/types/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ import { JsonRpcBlock } from "./types.ts";
import { KAKAROT } from "../provider.ts";

// Constant
import { NULL_HASH } from "../constants.ts";

// A default block gas limit in case the call to get_block_gas_limit fails.
export const DEFAULT_BLOCK_GAS_LIMIT = (() => {
const defaultBlockGasLimitStr = Deno.env.get("DEFAULT_BLOCK_GAS_LIMIT");
if (!defaultBlockGasLimitStr) {
throw new Error("ENV: DEFAULT_BLOCK_GAS_LIMIT is not set");
}
return defaultBlockGasLimitStr;
})();
import { DEFAULT_BLOCK_GAS_LIMIT, NULL_HASH } from "../constants.ts";

/**
* Converts a Starknet block header to an Ethereum block header in JSON RPC format.
Expand Down
17 changes: 4 additions & 13 deletions indexer/src/types/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import { padBigint } from "../utils/hex.ts";

// Constants
import { KAKAROT_ADDRESS, NULL_HASH } from "../constants.ts";
import { IGNORED_KEYS, KAKAROT_ADDRESS, NULL_HASH } from "../constants.ts";

// Types
import { JsonRpcLog } from "./types.ts";

// Starknet
import { Event, hash } from "../deps.ts";
Expand All @@ -16,18 +19,6 @@ import {
PrefixedHexString,
} from "../deps.ts";

import { JsonRpcLog } from "./types.ts";

// Events containing these keys are not
// ETH logs and should be ignored.
export const IGNORED_KEYS = [
BigInt(hash.getSelectorFromName("transaction_executed")),
BigInt(hash.getSelectorFromName("evm_contract_deployed")),
BigInt(hash.getSelectorFromName("Transfer")),
BigInt(hash.getSelectorFromName("Approval")),
BigInt(hash.getSelectorFromName("OwnershipTransferred")),
];

/**
* @param transaction - A Ethereum transaction.
* @param event - A Starknet event.
Expand Down
3 changes: 2 additions & 1 deletion indexer/tests/header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
PrefixedHexString,
} from "../src/deps.ts";
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
import { DEFAULT_BLOCK_GAS_LIMIT, toEthHeader } from "../src/types/header.ts";
import { toEthHeader } from "../src/types/header.ts";
import { JsonRpcBlock } from "../src/types/types.ts";
import { DEFAULT_BLOCK_GAS_LIMIT } from "../src/constants.ts";
import { padString } from "../src/utils/hex.ts";
import sinon from "npm:sinon";
import { KAKAROT } from "../src/provider.ts";
Expand Down
4 changes: 2 additions & 2 deletions indexer/tests/log.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { fromJsonRpcLog, IGNORED_KEYS, toEthLog } from "../src/types/log.ts";
import { fromJsonRpcLog, toEthLog } from "../src/types/log.ts";
import { JsonRpcLog } from "../src/types/types.ts";
import { bigIntToHex, Event, JsonRpcTx } from "../src/deps.ts";
import { KAKAROT_ADDRESS } from "../src/constants.ts";
import { IGNORED_KEYS, KAKAROT_ADDRESS } from "../src/constants.ts";

// Mock for hexToBytes
const mockHexToBytes = (hex: string): Uint8Array => {
Expand Down

0 comments on commit bbbc9ae

Please sign in to comment.