Skip to content

Commit

Permalink
chore: e2e agent process (#74)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Closes GRT-234

## Description
Given that the agent is an "infinite loop" we need to wrap it inside a
forked process during each E2E scenario to be able to kill it whenever
the test is completed.

Create a `spawnAgent` util function that allows the developer to spawn
agents inside processes to be able to terminate them.
  • Loading branch information
0xyaco authored Oct 28, 2024
1 parent d65f07b commit 2705b91
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ out/
build
dist
cache
tmp/


# Coverage
Expand Down
1 change: 1 addition & 0 deletions apps/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"devDependencies": {
"execa": "9.4.0",
"prool": "0.0.16",
"tsx": "4.19.1",
"viem": "2.21.10",
"vitest": "2.0.3"
}
Expand Down
40 changes: 31 additions & 9 deletions apps/agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
import { inspect } from "util";
import { isNativeError } from "util/types";
import {
DiscordNotifier,
EboActorsManager,
EboProcessor,
NotificationService,
ProtocolProvider,
} from "@ebo-agent/automated-dispute";
import { BlockNumberService } from "@ebo-agent/blocknumber";
import { Logger } from "@ebo-agent/shared";
import { Logger, stringify } from "@ebo-agent/shared";

import { config } from "./config/index.js";

const logger = Logger.getInstance();

const main = async (): Promise<void> => {
logger.debug("Initializing agent...");

logger.debug("Initializing block number service...");
logger.debug(stringify(config.blockNumberService));

const blockNumberService = new BlockNumberService(
config.blockNumberService.chainRpcUrls,
config.blockNumberService.blockmetaConfig,
logger,
);

logger.debug("Block number service initialized.");

logger.debug("Initializing protocol provider...");
logger.debug(stringify(config.protocolProvider));

const protocolProvider = new ProtocolProvider(
config.protocolProvider.rpcsConfig,
config.protocolProvider.contracts,
config.protocolProvider.privateKey,
blockNumberService,
);

logger.debug("Protocol provider initialized.");

const discordConfig = {
discordBotToken: config.DISCORD_BOT_TOKEN,
discordChannelId: config.DISCORD_CHANNEL_ID,
};

logger.debug("Initializing notifier...");
logger.debug(stringify(discordConfig));

// const notifier = await DiscordNotifier.create(discordConfig, logger);
// FIXME: during E2E DiscordNotifier is not able to start even if setting a valid token
const notifier = { notifyError: (_e, _ctx) => {} } as NotificationService;

const actorsManager = new EboActorsManager();

const notifier = await DiscordNotifier.create(
{
discordBotToken: config.DISCORD_BOT_TOKEN,
discordChannelId: config.DISCORD_CHANNEL_ID,
},
logger,
);
logger.debug("Initializing EBO processor...");
logger.debug(stringify(config.processor));

const processor = new EboProcessor(
config.processor.accountingModules,
Expand All @@ -46,6 +65,9 @@ const main = async (): Promise<void> => {
notifier,
);

logger.debug("EBO processor initialized.");
logger.debug("Starting processing...");

await processor.start(config.processor.msBetweenChecks);
};

Expand Down
Loading

0 comments on commit 2705b91

Please sign in to comment.