From 0e1020d8ab3a2884a3c4e0a58fd6d9bbf26e1021 Mon Sep 17 00:00:00 2001 From: jahabeebs <47253537+jahabeebs@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:41:14 -0500 Subject: [PATCH] fix: fix tests and logger --- apps/agent/src/index.ts | 5 ++- .../e2e/scenarios/01_happy_path/index.spec.ts | 3 +- .../tests/services/protocolProvider.spec.ts | 32 ++++++------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/apps/agent/src/index.ts b/apps/agent/src/index.ts index d5b287a..1a63c24 100644 --- a/apps/agent/src/index.ts +++ b/apps/agent/src/index.ts @@ -7,12 +7,11 @@ import { ProtocolProvider, } from "@ebo-agent/automated-dispute"; import { BlockNumberService } from "@ebo-agent/blocknumber"; -import { NotificationService, stringify } from "@ebo-agent/shared"; +import { Logger, NotificationService, stringify } from "@ebo-agent/shared"; import { config } from "./config/index.js"; -// TODO: Replace with logger.getInstance() when working -const logger = console; +const logger = Logger.getInstance(); const main = async (): Promise => { logger.debug("Initializing agent..."); diff --git a/apps/agent/test/e2e/scenarios/01_happy_path/index.spec.ts b/apps/agent/test/e2e/scenarios/01_happy_path/index.spec.ts index 8ea074a..7f2f69b 100644 --- a/apps/agent/test/e2e/scenarios/01_happy_path/index.spec.ts +++ b/apps/agent/test/e2e/scenarios/01_happy_path/index.spec.ts @@ -106,6 +106,7 @@ describe.sequential("single agent", () => { }); beforeEach(async () => { + Logger.getInstance(); l2ProtocolAnvil = await createAnvilServer( PROTOCOL_L2_LOCAL_RPC_HOST, PROTOCOL_L2_LOCAL_RPC_PORT, @@ -181,7 +182,7 @@ describe.sequential("single agent", () => { } }); - test.skip("basic flow", { timeout: E2E_TEST_TIMEOUT }, async () => { + test("basic flow", { timeout: E2E_TEST_TIMEOUT }, async () => { if (!accounts || accounts[0] === undefined || accounts[0]?.privateKey === undefined) { throw new Error("Accounts not found"); } diff --git a/packages/automated-dispute/tests/services/protocolProvider.spec.ts b/packages/automated-dispute/tests/services/protocolProvider.spec.ts index c5412e8..ebbc03a 100644 --- a/packages/automated-dispute/tests/services/protocolProvider.spec.ts +++ b/packages/automated-dispute/tests/services/protocolProvider.spec.ts @@ -9,6 +9,8 @@ import { getContract, Hex, http, + keccak256, + toBytes, WaitForTransactionReceiptTimeoutError, } from "viem"; import { privateKeyToAccount, privateKeyToAddress } from "viem/accounts"; @@ -1228,6 +1230,12 @@ describe("ProtocolProvider", () => { }); describe("getAvailableChains", () => { + const ARBITRUM_SEPOLIA_ID = "eip155:421614" as const; + const ETHEREUM_ID = "eip155:1" as const; + + const ETHEREUM_ID_HASH = keccak256(toBytes(ETHEREUM_ID)).toLowerCase(); + const ARBITRUM_SEPOLIA_ID_HASH = keccak256(toBytes(ARBITRUM_SEPOLIA_ID)).toLowerCase(); + it("successfully retrieves available chains", async () => { const protocolProvider = new ProtocolProvider( mockRpcConfigBase, @@ -1238,16 +1246,13 @@ describe("ProtocolProvider", () => { mockBlockNumberService, ); - const mockAllowedChainIdsBytes32: `0x${string}`[] = [ - "0x6569703135353a31000000000000000000000000000000000000000000000000", - "0x6569703135353a34323136313400000000000000000000000000000000000000", - ]; + const mockAllowedChainIdsBytes32 = [ETHEREUM_ID_HASH, ARBITRUM_SEPOLIA_ID_HASH]; ( protocolProvider["eboRequestCreatorContract"].read.getAllowedChainIds as Mock ).mockResolvedValue(mockAllowedChainIdsBytes32); - const expectedChains: Caip2ChainId[] = ["eip155:1", "eip155:421614"]; + const expectedChains: Caip2ChainId[] = [ETHEREUM_ID, ARBITRUM_SEPOLIA_ID]; const chains = await protocolProvider.getAvailableChains(); @@ -1299,23 +1304,6 @@ describe("ProtocolProvider", () => { }); }); - describe("getAccountingModuleAddress", () => { - it("returns the correct accounting module address", () => { - const protocolProvider = new ProtocolProvider( - mockRpcConfigBase, - mockContractAddress, - mockedPrivateKey, - mockServiceProviderAddress, - mockLogger(), - mockBlockNumberService, - ); - - expect(protocolProvider.getAccountingModuleAddress()).toBe( - mockContractAddress.horizonAccountingExtension, - ); - }); - }); - describe("Service Provider Address", () => { it("uses the provided serviceProviderAddress from config", () => { const protocolProvider = new ProtocolProvider(