index.test.ts•5.65 kB
import { tools } from "../../tools";
import { getAccounts } from "../../tools/ethereum/getAccounts";
import { getEthBalance } from "../../tools/ethereum/getBalance.js";
import { getTransactionCount } from "../../tools/ethereum/getTransactionCount.js";
import { getBlobBaseFee } from "../../tools/ethereum/getBlobBaseFee";
import { getBlockNumber } from "../../tools/ethereum/getBlockNumber";
import { getGasEstimate } from "../../tools/ethereum/getGasEstimate";
import { getFeeHistory } from "../../tools/ethereum/getFeeHistory";
import { getGasPrice } from "../../tools/ethereum/getGasPrice";
import { getBlockByHash } from "../../tools/ethereum/getBlockByHash";
import { getBlockByNumber } from "../../tools/ethereum/getBlockByNumber";
import { getBlockReceipts } from "../../tools/ethereum/getBlockReceipts";
import { getBlockTransactionCountByHash } from "../../tools/ethereum/getBlockTransactionCountByHash";
import { getBlockTransactionCountByNumber } from "../../tools/ethereum/getBlockTransactionCountByNumber";
import { getCode } from "../../tools/ethereum/getCode";
import { getLogs } from "../../tools/ethereum/getLogs";
import { getProof } from "../../tools/ethereum/getProof";
import { getStorageAt } from "../../tools/ethereum/getStorageAt";
import { getTransactionByBlockHashAndIndex } from "../../tools/ethereum/getTransactionByBlockHashAndIndex";
import { getTransactionByBlockNumberAndIndex } from "../../tools/ethereum/getTransactionByBlockNumberAndIndex";
import { getTransactionByHash } from "../../tools/ethereum/getTransactionByHash";
import { getTransactionReceipt } from "../../tools/ethereum/getTransactionReceipt";
import { getUncleByBlockHashAndIndex } from "../../tools/ethereum/getUncleByBlockHashAndIndex";
import { getUncleByBlockNumberAndIndex } from "../../tools/ethereum/getUncleByBlockNumberAndIndex";
import { getUncleCountByBlockHash } from "../../tools/ethereum/getUncleCountByBlockHash";
import { getUncleCountByBlockNumber } from "../../tools/ethereum/getUncleCountByBlockNumber";
import { getWork } from "../../tools/ethereum/getWork";
import { getHashrate } from "../../tools/ethereum/getHashRate";
import { getMaxPriorityFeePerGas } from "../../tools/ethereum/getMaxPriorityFeePerGas";
import { getMiningStatus } from "../../tools/ethereum/getMiningStatus";
import { getProtocolVersion } from "../../tools/ethereum/getProtocolVersion";
import { sendRawTransaction } from "../../tools/ethereum/sendRawTransaction";
import { getSimulatedTransactions } from "../../tools/ethereum/getSimulatedTransactions";
import { submitWork } from "../../tools/ethereum/submitWork";
import { getSyncStatus } from "../../tools/ethereum/getSyncStatus";
import { getClientVersion } from "../../tools/ethereum/getClientVersion";
describe("tools module", () => {
it("should export an array", () => {
expect(Array.isArray(tools)).toBe(true);
});
it("should contain the expected read-only tools", () => {
expect(tools).toContain(getEthBalance);
expect(tools).toContain(getTransactionCount);
expect(tools).toContain(getAccounts);
expect(tools).toContain(getBlobBaseFee);
expect(tools).toContain(getBlockNumber);
expect(tools).toContain(getGasEstimate);
expect(tools).toContain(getFeeHistory);
expect(tools).toContain(getGasPrice);
expect(tools).toContain(getBlockByHash);
expect(tools).toContain(getBlockByNumber);
expect(tools).toContain(getBlockReceipts);
expect(tools).toContain(getBlockTransactionCountByHash);
expect(tools).toContain(getBlockTransactionCountByNumber);
expect(tools).toContain(getCode);
expect(tools).toContain(getLogs);
expect(tools).toContain(getProof);
expect(tools).toContain(getStorageAt);
expect(tools).toContain(getTransactionByBlockHashAndIndex);
expect(tools).toContain(getTransactionByBlockNumberAndIndex);
expect(tools).toContain(getTransactionByHash);
expect(tools).toContain(getTransactionReceipt);
expect(tools).toContain(getUncleByBlockHashAndIndex);
expect(tools).toContain(getUncleByBlockNumberAndIndex);
expect(tools).toContain(getUncleCountByBlockHash);
expect(tools).toContain(getUncleCountByBlockNumber);
expect(tools).toContain(getWork);
expect(tools).toContain(getHashrate);
expect(tools).toContain(getMaxPriorityFeePerGas);
expect(tools).toContain(getMiningStatus);
expect(tools).toContain(getProtocolVersion);
expect(tools).toContain(getSimulatedTransactions);
expect(tools).toContain(submitWork);
expect(tools).toContain(getSyncStatus);
expect(tools).toContain(getClientVersion);
});
it("should have tools with correct names", () => {
const names = tools.map((tool) => tool.name);
expect(names).toContain("eth_get_balance");
expect(names).toContain("eth_get_transaction_count");
expect(names).toContain("eth_get_block_number");
});
it("should respect WRITE_TOOLS_ENABLED=false (default)", async () => {
jest.resetModules();
jest.doMock("../../config/chains", () => ({
WRITE_TOOLS_ENABLED: false,
INFURA_CHAIN_URLS: {},
}));
const { tools: readonlyTools } = await import("../../tools");
expect(readonlyTools).not.toContain(sendRawTransaction);
});
it("should include sendRawTransaction when WRITE_TOOLS_ENABLED=true", async () => {
jest.resetModules();
jest.doMock("../../config/chains", () => ({
WRITE_TOOLS_ENABLED: true,
INFURA_CHAIN_URLS: {},
}));
const { tools: writableTools } = await import("../../tools");
const names = writableTools.map((tool) => tool.name);
expect(names).toContain("eth_send_raw_transaction");
});
});