Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests issue #208

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
export default {
preset: "ts-jest",
testEnvironment: "node",
rootDir: "./src",
rootDir: "./",
testMatch: ["**/*.test.ts"],
setupFilesAfterEnv: ["<rootDir>/test_resources/testSetup.ts"],
setupFilesAfterEnv: ["<rootDir>/src/test_resources/testSetup.ts"],
testTimeout: 120000,
globals: {
__DEV__: true,
Expand All @@ -23,4 +23,4 @@ export default {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
extensionsToTreatAsEsm: [".ts"],
}
};
29 changes: 27 additions & 2 deletions core/src/providers/trustScoreProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class TrustScoreProvider {

const recommenderMetrics =
await this.trustScoreDb.getRecommenderMetrics(recommenderId);
if (!recommenderMetrics) {
throw new Error("Recommender not found");
}

const isRapidDump = await this.isRapidDump(tokenAddress);
const sustainedGrowth = await this.sustainedGrowth(tokenAddress);
Expand Down Expand Up @@ -109,12 +112,13 @@ export class TrustScoreProvider {
processedData.tradeData.price_change_24h_percent,
volumeChange24h: processedData.tradeData.volume_24h,
trade_24h_change:
processedData.tradeData.trade_24h_change_percent,
processedData.tradeData.trade_24h_change_percent || 0,
liquidity:
processedData.dexScreenerData.pairs[0]?.liquidity.usd || 0,
liquidityChange24h: 0,
holderChange24h:
processedData.tradeData.unique_wallet_24h_change_percent,
processedData.tradeData.unique_wallet_24h_change_percent ||
0,
rugPull: false, // TODO: Implement rug pull detection
isScam: false, // TODO: Implement scam detection
marketCapChange24h: 0, // TODO: Implement market cap change
Expand Down Expand Up @@ -147,6 +151,9 @@ export class TrustScoreProvider {
): Promise<void> {
const recommenderMetrics =
await this.trustScoreDb.getRecommenderMetrics(recommenderId);
if (!recommenderMetrics) {
throw new Error("Recommender not found");
}

const totalRecommendations =
recommenderMetrics.totalRecommendations + 1;
Expand Down Expand Up @@ -269,6 +276,13 @@ export class TrustScoreProvider {
const processedData: ProcessedTokenData =
await this.tokenProvider.getProcessedTokenData();
console.log(`Fetched processed token data for token: ${tokenAddress}`);
if (
!processedData ||
!processedData.tradeData ||
!processedData.tradeData.volume_24h_change_percent
) {
return false;
}

return processedData.tradeData.volume_24h_change_percent > 50;
}
Expand All @@ -278,6 +292,14 @@ export class TrustScoreProvider {
await this.tokenProvider.getProcessedTokenData();
console.log(`Fetched processed token data for token: ${tokenAddress}`);

if (
!processedData ||
!processedData.tradeData ||
!processedData.tradeData.trade_24h_change_percent
) {
return false;
}

return processedData.tradeData.trade_24h_change_percent < -50;
}

Expand Down Expand Up @@ -384,6 +406,9 @@ export class TrustScoreProvider {
recommenderId,
isSimulation
);
if (!trade) {
throw new Error("Trade not found");
}
const buyTimeStamp = trade.buy_timeStamp;
const marketCap =
processedData.dexScreenerData.pairs[0]?.marketCap || 0;
Expand Down
14 changes: 10 additions & 4 deletions core/tests/browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dotenv from "dotenv";
import { createRuntime } from "../test_resources/createRuntime.ts";
import { BrowserService } from "./browser.ts";
import { createRuntime } from "../src/test_resources/createRuntime.ts";
import { BrowserService } from "../src/services/browser.ts";
import { IAgentRuntime } from "../src/core/types.ts";

dotenv.config();

Expand All @@ -12,7 +13,10 @@ describe("BrowserService", () => {
env: process.env as Record<string, string>,
actions: [],
});
browserService = BrowserService.getInstance(runtime);
if (runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
browserService = BrowserService.getInstance(runtime as IAgentRuntime);
await browserService.initialize();
});

Expand All @@ -25,7 +29,9 @@ describe("BrowserService", () => {
env: process.env as Record<string, string>,
actions: [],
});
const newBrowserService = BrowserService.getInstance(runtime);
const newBrowserService = BrowserService.getInstance(
runtime as IAgentRuntime
);
await expect(newBrowserService.initialize()).resolves.not.toThrow();
await expect(newBrowserService.closeBrowser()).resolves.not.toThrow();
});
Expand Down
15 changes: 12 additions & 3 deletions core/tests/continue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { getOrCreateRelationship } from "../src/test_resources/getOrCreateRelati
import { populateMemories } from "../src/test_resources/populateMemories.ts";
import { runAiTest } from "../src/test_resources/runAiTest.ts";
import { type User } from "../src/test_resources/types.ts";
import action from "../src/actions/continue.ts";
import ignore from "../src/actions/ignore.ts";
import { continueAction as action } from "../src/actions/continue.ts";
import { ignore } from "../src/actions/ignore.ts";

dotenv.config({ path: ".dev.vars" });

Expand Down Expand Up @@ -56,7 +56,10 @@ describe("User Profile", () => {
actions: [action, ignore],
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

const data = await getOrCreateRelationship({
runtime,
Expand Down Expand Up @@ -86,6 +89,7 @@ describe("User Profile", () => {
userId: user.id as UUID,
content: { text: "Hello" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const validate = action.validate!;
Expand All @@ -104,6 +108,7 @@ describe("User Profile", () => {
action: "CONTINUE",
},
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const result2 = await validate(runtime, message2);
Expand All @@ -121,6 +126,7 @@ describe("User Profile", () => {
action: "CONTINUE",
},
roomId,
agentId: runtime.agentId,
};

const handler = action.handler!;
Expand All @@ -145,6 +151,7 @@ describe("User Profile", () => {
text: "Write a short story in three parts, using the CONTINUE action for each part.",
},
roomId: roomId,
agentId: runtime.agentId,
};

const initialMessageCount =
Expand Down Expand Up @@ -196,6 +203,7 @@ describe("User Profile", () => {
text: "Tell me more about your favorite food.",
},
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const initialMessageCount =
Expand All @@ -216,6 +224,7 @@ describe("User Profile", () => {
userId: user?.id as UUID,
content: { text: "Bye" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

const handler = action.handler!;
Expand Down
9 changes: 8 additions & 1 deletion core/tests/evaluation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe("Evaluation Process", () => {
env: process.env as Record<string, string>,
evaluators: [TEST_EVALUATOR, TEST_EVALUATOR_FAIL],
});
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;
user = setup.session.user;

const data = await getOrCreateRelationship({
Expand Down Expand Up @@ -61,6 +64,7 @@ describe("Evaluation Process", () => {
userId: user.id as UUID,
content: { text: "Test message for evaluation" },
roomId,
agentId: runtime.agentId,
};

const state = await runtime.composeState(message);
Expand All @@ -79,6 +83,7 @@ describe("Evaluation Process", () => {
userId: user.id as UUID,
content: { text: "Run TEST_EVALUATOR handler" },
roomId,
agentId: runtime.agentId,
};

const result = await TEST_EVALUATOR.handler(runtime, message);
Expand All @@ -93,6 +98,7 @@ describe("Evaluation Process", () => {
text: "We are in testing mode. We want to make sure that the test passes by replying with the evaluator TEST_EVALUATOR in the array of evaluators that are returned. Please run the TEST_EVALUATOR",
},
roomId,
agentId: runtime.agentId,
};

const state = await runtime.composeState(message);
Expand All @@ -113,6 +119,7 @@ describe("Evaluation Process", () => {
userId: user.id as UUID,
content: { text: "Test message for evaluation" },
roomId,
agentId: runtime.agentId,
};

const state = await runtime.composeState(message);
Expand Down
8 changes: 7 additions & 1 deletion core/tests/fact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe("Facts Evaluator", () => {
actions: defaultActions,
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

if (!user.id) {
throw new Error("User ID is undefined");
Expand Down Expand Up @@ -66,6 +69,7 @@ describe("Facts Evaluator", () => {
userId: user.id as UUID,
content: { text: "" },
roomId,
agentId: runtime.agentId,
};

const result = await evaluator.handler(runtime, message);
Expand All @@ -91,6 +95,7 @@ describe("Facts Evaluator", () => {
userId: user.id as UUID,
content: { text: "" },
roomId,
agentId: runtime.agentId,
};

const result = await evaluator.handler(runtime, message);
Expand Down Expand Up @@ -124,6 +129,7 @@ async function addFacts(
content: { text: fact },
roomId: roomId,
embedding: existingEmbedding,
agentId: runtime.agentId,
});
await runtime.factManager.createMemory(bakedMemory);
if (!existingEmbedding) {
Expand Down
7 changes: 6 additions & 1 deletion core/tests/goal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe("Goals Evaluator", () => {
actions: defaultActions,
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

const data = await getOrCreateRelationship({
runtime,
Expand Down Expand Up @@ -108,6 +111,7 @@ describe("Goals Evaluator", () => {
text: "I've completed task 1 and task 2 for the Test Goal. Both are finished. Everything is done and I'm ready for the next goal.",
},
roomId,
agentId: runtime.agentId,
};

// Process the message with the goal evaluator
Expand Down Expand Up @@ -177,6 +181,7 @@ describe("Goals Evaluator", () => {
userId: user.id as UUID,
content: { text: "I've decided to mark Goal Y as failed." },
roomId,
agentId: runtime.agentId,
};

await evaluator.handler(runtime, message, {} as State, {
Expand Down
6 changes: 5 additions & 1 deletion core/tests/goals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ describe("Goals", () => {
const result = await createRuntime({
env: process.env as Record<string, string>,
});
runtime = result.runtime;

if (result.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = result.runtime as IAgentRuntime;
user = result.session.user;
await runtime.databaseAdapter.removeAllGoals(zeroUuid);
});
Expand Down
13 changes: 11 additions & 2 deletions core/tests/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { populateMemories } from "../src/test_resources/populateMemories.ts";
import { runAiTest } from "../src/test_resources/runAiTest.ts";
import { messageHandlerTemplate } from "../src/test_resources/templates.ts";
import { type User } from "../src/test_resources/types.ts";
import action from "../src/actions/ignore.ts";
import { ignore as action } from "../src/actions/ignore.ts";
import { generateMessageResponse } from "../src/core/generation.ts";

async function handleMessage(
Expand All @@ -42,6 +42,7 @@ async function handleMessage(
},
roomId,
embedding: embeddingZeroVector,
agentId: runtime.agentId,
});
}
};
Expand Down Expand Up @@ -76,6 +77,7 @@ async function handleMessage(
content: response,
roomId,
embedding: embeddingZeroVector,
agentId: runtime.agentId,
};

if (responseMessage.content.text?.trim()) {
Expand Down Expand Up @@ -107,7 +109,10 @@ describe("Ignore action tests", () => {
actions: [action],
});
user = setup.session.user;
runtime = setup.runtime;
if (setup.runtime.llamaService === null) {
throw new Error("llamaService cannot be null");
}
runtime = setup.runtime as IAgentRuntime;

const data = await getOrCreateRelationship({
runtime,
Expand Down Expand Up @@ -139,6 +144,7 @@ describe("Ignore action tests", () => {
userId: user?.id as UUID,
content: { text: "Never talk to me again" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [
Expand All @@ -159,6 +165,7 @@ describe("Ignore action tests", () => {
userId: user.id as UUID,
content: { text: "", action: "IGNORE" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [
Expand All @@ -184,6 +191,7 @@ describe("Ignore action tests", () => {
userId: user.id as UUID,
content: { text: "", action: "IGNORE" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [
Expand All @@ -207,6 +215,7 @@ describe("Ignore action tests", () => {
userId: user.id as UUID,
content: { text: "Bye" },
roomId: roomId as UUID,
agentId: runtime.agentId,
};

await populateMemories(runtime, user, roomId, [Goodbye1]);
Expand Down
Loading
Loading