From 1eb89a4e13f33309baa543b88afd0c0eb58d149f Mon Sep 17 00:00:00 2001 From: MarcoMandar Date: Tue, 5 Nov 2024 12:07:10 +0200 Subject: [PATCH 1/3] fix jest config for tests Signed-off-by: MarcoMandar --- core/jest.config.js | 6 +- core/tests/token.test.ts | 129 +++++++++++++++++++++++++++++++++++---- 2 files changed, 121 insertions(+), 14 deletions(-) diff --git a/core/jest.config.js b/core/jest.config.js index 9d609fa6785..46684bcb9bc 100644 --- a/core/jest.config.js +++ b/core/jest.config.js @@ -2,9 +2,9 @@ export default { preset: "ts-jest", testEnvironment: "node", - rootDir: "./src", + rootDir: "./", testMatch: ["**/*.test.ts"], - setupFilesAfterEnv: ["/test_resources/testSetup.ts"], + setupFilesAfterEnv: ["/src/test_resources/testSetup.ts"], testTimeout: 120000, globals: { __DEV__: true, @@ -23,4 +23,4 @@ export default { "^(\\.{1,2}/.*)\\.js$": "$1", }, extensionsToTreatAsEsm: [".ts"], -} +}; diff --git a/core/tests/token.test.ts b/core/tests/token.test.ts index 46abfe6f8a1..9f6edf8b969 100644 --- a/core/tests/token.test.ts +++ b/core/tests/token.test.ts @@ -8,12 +8,9 @@ jest.mock("fs"); jest.mock("node-cache"); describe("TokenProvider Tests", () => { - // let connection: Connection; let tokenProvider: TokenProvider; beforeEach(() => { - // Initialize the connection and token provider before each test - // connection = new Connection("https://api.mainnet-beta.solana.com"); tokenProvider = new TokenProvider( "2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh" ); @@ -28,12 +25,123 @@ describe("TokenProvider Tests", () => { const mockFetchResponse = { success: true, data: { - ownerBalance: "100", - creatorBalance: "50", - ownerPercentage: 10, - creatorPercentage: 5, - top10HolderBalance: "200", - top10HolderPercent: 20, + // Security Data + security: { + ownerBalance: "1000", + creatorBalance: "500", + ownerPercentage: 10, // Represents 10% + creatorPercentage: 5, // Represents 5% + top10HolderBalance: "2000", + top10HolderPercent: 20, // Represents 20% + }, + // Trade Data + tradeData: { + holder: 1500, + unique_wallet_24h: 120, + price_change_24h_percent: 4.5, // 4.5% + price_change_12h_percent: 2.3, // 2.3% + volume_24h_usd: "75000.50", // String representation for consistency + price: "2.50", // Current price in USD as a string + // Add additional trade-related fields if necessary + }, + // Holder Distribution Trend + holderDistributionTrend: "increasing", // Possible values: 'increasing', 'decreasing', 'stable' + // High-Value Holders + highValueHolders: [ + { + holderAddress: "0xHolderAddress1", + balanceUsd: "6000.00", + }, + { + holderAddress: "0xHolderAddress2", + balanceUsd: "5500.00", + }, + // Add more high-value holders as needed + ], + // Recent Trades Indicator + recentTrades: true, // Indicates whether there have been recent trades in the last 24 hours + // High-Supply Holders Count + highSupplyHoldersCount: 15, // Number of holders holding more than 2% of the total supply + // DexScreener Data + dexScreenerData: { + schemaVersion: "1.0", + pairs: [ + { + chainId: "1", // Example Chain ID (e.g., Ethereum Mainnet) + dexId: "Uniswap", // Decentralized Exchange Identifier + url: "https://uniswap.org", // URL to the DEX + pairAddress: "0xPairAddress1", + baseToken: { + address: "0xBaseTokenAddress1", + name: "Base Token Name", + symbol: "BASE", + }, + quoteToken: { + address: "0xQuoteTokenAddress1", + name: "Quote Token Name", + symbol: "QUOTE", + }, + priceNative: "0.002", // Price in native blockchain currency (e.g., ETH) + priceUsd: "2.50", // Price in USD as a string + txns: { + m5: { buys: 15, sells: 10 }, // Transactions in the last 5 minutes + h1: { buys: 60, sells: 45 }, // Transactions in the last hour + h6: { buys: 300, sells: 270 }, // Transactions in the last 6 hours + h24: { buys: 1200, sells: 1100 }, // Transactions in the last 24 hours + }, + volume: { + h24: 50000, // Volume in the last 24 hours in USD + h6: 30000, // Volume in the last 6 hours in USD + h1: 15000, // Volume in the last hour in USD + m5: 5000, // Volume in the last 5 minutes in USD + }, + priceChange: { + m5: 0.5, // Price change in the last 5 minutes + h1: 1.2, // Price change in the last hour + h6: 3.5, // Price change in the last 6 hours + h24: 5.0, // Price change in the last 24 hours + }, + liquidity: { + usd: 1000000, // Liquidity in USD + base: 500000, // Liquidity in base token + quote: 500000, // Liquidity in quote token + }, + fdv: 2000000, // Fully Diluted Valuation in USD + marketCap: 1500000, // Market Capitalization in USD + pairCreatedAt: 1633036800, // Unix timestamp for pair creation + info: { + imageUrl: "https://example.com/image.png", // URL to the pair's image + websites: [ + { + label: "Official Website", + url: "https://example.com", + }, + { + label: "Documentation", + url: "https://docs.example.com", + }, + ], + socials: [ + { + type: "Twitter", + url: "https://twitter.com/example", + }, + { + type: "Discord", + url: "https://discord.gg/example", + }, + ], + }, + boosts: { + active: 2, // Number of active boosts + }, + }, + // Add more DexScreenerPair objects as needed + ], + }, + // DexScreener Listing Status + isDexScreenerListed: true, // Indicates if the token is listed on DexScreener + isDexScreenerPaid: false, // Indicates if the listing on DexScreener is paid }, }; @@ -67,8 +175,7 @@ describe("TokenProvider Tests", () => { // const dexScreenerData = await tokenProvider.fetchDexScreenerData(); // console.log({ dexScreenerData }); - const tokenReport = - await tokenProvider.getFormattedTokenReport(runtime); + const tokenReport = await tokenProvider.getFormattedTokenReport(); console.log({ tokenReport }); // Ensure the mock was called From d1a3a689dafcaac9ad84cb4012d9cccecb6e8685 Mon Sep 17 00:00:00 2001 From: MarcoMandar Date: Tue, 5 Nov 2024 12:42:29 +0200 Subject: [PATCH 2/3] fixing tests Signed-off-by: MarcoMandar --- core/tests/browser.test.ts | 14 +++++++--- core/tests/continue.test.ts | 15 ++++++++--- core/tests/evaluation.test.ts | 9 ++++++- core/tests/fact.test.ts | 8 +++++- core/tests/goal.test.ts | 7 ++++- core/tests/goals.test.ts | 6 ++++- core/tests/ignore.test.ts | 13 +++++++-- core/tests/memory.test.ts | 46 ++++++++++++++++++++++++++------ core/tests/messages.test.ts | 10 ++++++- core/tests/providers.test.ts | 7 ++++- core/tests/relationships.test.ts | 7 ++++- core/tests/runtime.test.ts | 8 +++++- core/tests/time.test.ts | 14 ++++++++-- 13 files changed, 137 insertions(+), 27 deletions(-) diff --git a/core/tests/browser.test.ts b/core/tests/browser.test.ts index b8c5d1fc940..02580f082e0 100644 --- a/core/tests/browser.test.ts +++ b/core/tests/browser.test.ts @@ -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(); @@ -12,7 +13,10 @@ describe("BrowserService", () => { env: process.env as Record, 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(); }); @@ -25,7 +29,9 @@ describe("BrowserService", () => { env: process.env as Record, 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(); }); diff --git a/core/tests/continue.test.ts b/core/tests/continue.test.ts index 9e2d4c7c766..8e736c91dc3 100644 --- a/core/tests/continue.test.ts +++ b/core/tests/continue.test.ts @@ -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" }); @@ -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, @@ -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!; @@ -104,6 +108,7 @@ describe("User Profile", () => { action: "CONTINUE", }, roomId: roomId as UUID, + agentId: runtime.agentId, }; const result2 = await validate(runtime, message2); @@ -121,6 +126,7 @@ describe("User Profile", () => { action: "CONTINUE", }, roomId, + agentId: runtime.agentId, }; const handler = action.handler!; @@ -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 = @@ -196,6 +203,7 @@ describe("User Profile", () => { text: "Tell me more about your favorite food.", }, roomId: roomId as UUID, + agentId: runtime.agentId, }; const initialMessageCount = @@ -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!; diff --git a/core/tests/evaluation.test.ts b/core/tests/evaluation.test.ts index 55d4c220873..17d43643146 100644 --- a/core/tests/evaluation.test.ts +++ b/core/tests/evaluation.test.ts @@ -25,7 +25,10 @@ describe("Evaluation Process", () => { env: process.env as Record, 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({ @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/core/tests/fact.test.ts b/core/tests/fact.test.ts index ab13da53ee3..1e155638031 100644 --- a/core/tests/fact.test.ts +++ b/core/tests/fact.test.ts @@ -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"); @@ -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); @@ -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); @@ -124,6 +129,7 @@ async function addFacts( content: { text: fact }, roomId: roomId, embedding: existingEmbedding, + agentId: runtime.agentId, }); await runtime.factManager.createMemory(bakedMemory); if (!existingEmbedding) { diff --git a/core/tests/goal.test.ts b/core/tests/goal.test.ts index 5105a311f75..7aefa70a0b0 100644 --- a/core/tests/goal.test.ts +++ b/core/tests/goal.test.ts @@ -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, @@ -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 @@ -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, { diff --git a/core/tests/goals.test.ts b/core/tests/goals.test.ts index 6938adfac36..b5319bb3e11 100644 --- a/core/tests/goals.test.ts +++ b/core/tests/goals.test.ts @@ -18,7 +18,11 @@ describe("Goals", () => { const result = await createRuntime({ env: process.env as Record, }); - 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); }); diff --git a/core/tests/ignore.test.ts b/core/tests/ignore.test.ts index 51191502596..818b08072c4 100644 --- a/core/tests/ignore.test.ts +++ b/core/tests/ignore.test.ts @@ -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( @@ -42,6 +42,7 @@ async function handleMessage( }, roomId, embedding: embeddingZeroVector, + agentId: runtime.agentId, }); } }; @@ -76,6 +77,7 @@ async function handleMessage( content: response, roomId, embedding: embeddingZeroVector, + agentId: runtime.agentId, }; if (responseMessage.content.text?.trim()) { @@ -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, @@ -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, [ @@ -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, [ @@ -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, [ @@ -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]); diff --git a/core/tests/memory.test.ts b/core/tests/memory.test.ts index 849bf0c7dfd..fbc0b31323c 100644 --- a/core/tests/memory.test.ts +++ b/core/tests/memory.test.ts @@ -8,13 +8,18 @@ import { createRuntime } from "../src/test_resources/createRuntime.ts"; import { getOrCreateRelationship } from "../src/test_resources/getOrCreateRelationship.ts"; import { type User } from "../src/test_resources/types.ts"; import { MemoryManager } from "../src/core/memory.ts"; -import { type Content, type Memory, type UUID } from "../src/core/types.ts"; +import { + type Content, + type Memory, + type UUID, + IAgentRuntime, +} from "../src/core/types.ts"; import { embed } from "../src/core/embedding.ts"; dotenv.config({ path: ".dev.vars" }); describe("Memory", () => { let memoryManager: MemoryManager; - let runtime = null; + let runtime: IAgentRuntime | null = null; let user: User; let roomId: UUID = zeroUuid; @@ -22,7 +27,10 @@ describe("Memory", () => { const result = await createRuntime({ env: process.env as Record, }); - runtime = result.runtime; + if (result.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + runtime = result.runtime as IAgentRuntime; user = result.session.user; const data = await getOrCreateRelationship({ @@ -73,6 +81,7 @@ describe("Memory", () => { content: { text: similarMemoryContent }, roomId: roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -89,6 +98,7 @@ describe("Memory", () => { content: { text: dissimilarMemoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -139,6 +149,7 @@ describe("Memory", () => { content: { text: queryMemoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -155,6 +166,7 @@ describe("Memory", () => { content: { text: highSimilarityContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -170,6 +182,7 @@ describe("Memory", () => { content: { text: lowSimilarityContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -203,7 +216,7 @@ describe("Memory", () => { }); describe("Memory - Basic tests", () => { let memoryManager: MemoryManager; - let runtime = null; + let runtime: IAgentRuntime | null = null; let user: User; let roomId: UUID; @@ -212,7 +225,11 @@ describe("Memory - Basic tests", () => { const result = await createRuntime({ env: process.env as Record, }); - runtime = result.runtime; + if (result.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + + runtime = result.runtime as IAgentRuntime; user = result.session.user; const data = await getOrCreateRelationship({ @@ -248,6 +265,7 @@ describe("Memory - Basic tests", () => { content: { text: "Test content for memory lifecycle" }, roomId: roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -259,7 +277,7 @@ describe("Memory - Basic tests", () => { const createdMemories = await memoryManager.getMemories({ roomId, - agentId: runtime.agentId, + agentId: runtime?.agentId as UUID, count: 100, }); @@ -290,7 +308,7 @@ describe("Memory - Basic tests", () => { }); describe("Memory - Extended Tests", () => { let memoryManager: MemoryManager; - let runtime = null; + let runtime: IAgentRuntime | null = null; let user: User; let roomId: UUID; @@ -298,7 +316,10 @@ describe("Memory - Extended Tests", () => { const result = await createRuntime({ env: process.env as Record, }); - runtime = result.runtime; + if (result.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + runtime = result.runtime as IAgentRuntime; user = result.session.user; const data = await getOrCreateRelationship({ @@ -349,6 +370,7 @@ describe("Memory - Extended Tests", () => { content: { text: similarMemoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -394,6 +416,7 @@ describe("Memory - Extended Tests", () => { content: { text: similarMemoryContent }, roomId: roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -435,6 +458,7 @@ describe("Memory - Extended Tests", () => { content: { text: memoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -452,6 +476,7 @@ describe("Memory - Extended Tests", () => { content: { text: similarMemoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -488,6 +513,7 @@ describe("Memory - Extended Tests", () => { content: { text: similarMemoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -504,6 +530,7 @@ describe("Memory - Extended Tests", () => { content: { text: dissimilarMemoryContent }, roomId, embedding: await getCachedEmbeddings(dissimilarMemoryContent), + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -553,6 +580,7 @@ describe("Memory - Extended Tests", () => { content: { text: queryMemoryContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -569,6 +597,7 @@ describe("Memory - Extended Tests", () => { content: { text: highSimilarityContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( @@ -584,6 +613,7 @@ describe("Memory - Extended Tests", () => { content: { text: lowSimilarityContent }, roomId, embedding, + agentId: runtime?.agentId as UUID, }); if (!embedding) { writeCachedEmbedding( diff --git a/core/tests/messages.test.ts b/core/tests/messages.test.ts index 3b454f9e5f4..bf3fcb2fd9e 100644 --- a/core/tests/messages.test.ts +++ b/core/tests/messages.test.ts @@ -27,7 +27,11 @@ describe("Messages Library", () => { const setup = await createRuntime({ env: process.env as Record, }); - runtime = setup.runtime; + if (setup.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + + runtime = setup.runtime as IAgentRuntime; user = setup.session.user; actors = await getActorDetails({ runtime, @@ -78,11 +82,13 @@ describe("Messages Library", () => { content: { text: "Hello" }, userId: user.id as UUID, roomId: "00000000-0000-0000-0000-000000000000", + agentId: runtime.agentId, }, { content: { text: "How are you?" }, userId: "00000000-0000-0000-0000-000000000000", roomId: "00000000-0000-0000-0000-000000000000", + agentId: runtime.agentId, }, ]; const formattedMessages = formatMessages({ messages, actors }); @@ -99,11 +105,13 @@ describe("Messages Library", () => { content: { text: "Reflecting on the day" }, userId: user.id as UUID, roomId: "00000000-0000-0000-0000-000000000000", + agentId: runtime.agentId, }, { content: { text: "Thoughts and musings" }, userId: "00000000-0000-0000-0000-000000000000", roomId: "00000000-0000-0000-0000-000000000000room", + agentId: runtime.agentId, }, ]; const formattedFacts = formatFacts(facts); diff --git a/core/tests/providers.test.ts b/core/tests/providers.test.ts index 17fb24f952e..e641625d429 100644 --- a/core/tests/providers.test.ts +++ b/core/tests/providers.test.ts @@ -26,7 +26,11 @@ describe("TestProvider", () => { env: process.env as Record, providers: [TestProvider], }); - runtime = setup.runtime; + if (setup.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + + runtime = setup.runtime as IAgentRuntime; roomId = zeroUuid; }); @@ -35,6 +39,7 @@ describe("TestProvider", () => { userId: zeroUuid, content: { text: "" }, roomId: roomId, + agentId: zeroUuid, }; const testProviderResponse = await TestProvider.get( diff --git a/core/tests/relationships.test.ts b/core/tests/relationships.test.ts index 83e0b1759ff..7e3c3c8a440 100644 --- a/core/tests/relationships.test.ts +++ b/core/tests/relationships.test.ts @@ -19,7 +19,12 @@ describe("Relationships Module", () => { const setup = await createRuntime({ env: process.env as Record, }); - runtime = setup.runtime; + + if (setup.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + + runtime = setup.runtime as IAgentRuntime; user = setup.session.user; if (!user.id) { throw new Error("User ID is undefined"); diff --git a/core/tests/runtime.test.ts b/core/tests/runtime.test.ts index fdf2a5a0cc2..8d78678d009 100644 --- a/core/tests/runtime.test.ts +++ b/core/tests/runtime.test.ts @@ -40,6 +40,7 @@ describe("Agent Runtime", () => { content, roomId, embedding, + agentId: runtime.agentId, }); if (!embedding) { writeCachedEmbedding( @@ -60,7 +61,11 @@ describe("Agent Runtime", () => { env: process.env as Record, }); - runtime = result.runtime; + if (result.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + + runtime = result.runtime as IAgentRuntime; user = result.session.user; const data = await getOrCreateRelationship({ @@ -102,6 +107,7 @@ describe("Agent Runtime", () => { userId: user.id as UUID, content: { text: "test message" }, roomId: roomId as UUID, + agentId: runtime.agentId, }; const state = await runtime.composeState(message); diff --git a/core/tests/time.test.ts b/core/tests/time.test.ts index 83489d05dc4..daae3b43af6 100644 --- a/core/tests/time.test.ts +++ b/core/tests/time.test.ts @@ -8,7 +8,7 @@ import { } from "../src/core/types.ts"; import { zeroUuid } from "../src/test_resources/constants.ts"; import { createRuntime } from "../src/test_resources/createRuntime.ts"; -import timeProvider from "../src/providers/time.ts"; +import {timeProvider} from "../src/providers/time.ts"; dotenv.config({ path: ".dev.vars" }); @@ -22,7 +22,11 @@ describe("Time Provider", () => { env: process.env as Record, providers: [timeProvider], }); - runtime = setup.runtime; + if (setup.runtime.llamaService === null) { + throw new Error("llamaService cannot be null"); + } + + runtime = setup.runtime as IAgentRuntime; user = { id: setup.session.user?.id as UUID }; roomId = zeroUuid; }); @@ -32,6 +36,8 @@ describe("Time Provider", () => { userId: user.id, content: { text: "" }, roomId: roomId, + agentId:runtime.agentId, + }; const currentTimeResponse = await timeProvider.get( @@ -49,6 +55,8 @@ describe("Time Provider", () => { userId: user.id, content: { text: "" }, roomId: roomId, + agentId:runtime.agentId, + }; // Manually integrate the time provider's response into the state @@ -74,6 +82,8 @@ describe("Time Provider", () => { userId: user.id, content: { text: "" }, roomId: roomId, + agentId:runtime.agentId, + }; const currentTimeResponse = await timeProvider.get(runtime, message); From 36380f269fdc4f0e0bfa988a54da3bcd38b0cd46 Mon Sep 17 00:00:00 2001 From: MarcoMandar Date: Tue, 5 Nov 2024 13:22:10 +0200 Subject: [PATCH 3/3] fix tsconfig typeRoots, update imports Signed-off-by: MarcoMandar --- core/src/providers/trustScoreProvider.ts | 29 ++++++++++++++++++++++-- core/tests/utils.test.ts | 14 ++++++------ core/tsconfig.json | 6 ++--- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/core/src/providers/trustScoreProvider.ts b/core/src/providers/trustScoreProvider.ts index 84ab77f91fa..6f0fb8e7555 100644 --- a/core/src/providers/trustScoreProvider.ts +++ b/core/src/providers/trustScoreProvider.ts @@ -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); @@ -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 @@ -147,6 +151,9 @@ export class TrustScoreProvider { ): Promise { const recommenderMetrics = await this.trustScoreDb.getRecommenderMetrics(recommenderId); + if (!recommenderMetrics) { + throw new Error("Recommender not found"); + } const totalRecommendations = recommenderMetrics.totalRecommendations + 1; @@ -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; } @@ -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; } @@ -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; diff --git a/core/tests/utils.test.ts b/core/tests/utils.test.ts index 8fe285ee509..6c7a5c474f0 100644 --- a/core/tests/utils.test.ts +++ b/core/tests/utils.test.ts @@ -1,14 +1,14 @@ import Database from "better-sqlite3"; import fs from "fs"; import path from "path"; -import { SqliteDatabaseAdapter } from "../../adapters/sqlite.ts"; -import defaultCharacter from "../../core/defaultCharacter.ts"; -import { AgentRuntime } from "../../core/runtime.ts"; -import settings from "../../core/settings.ts"; -import { TwitterInteractionClient } from "./interactions.ts"; -import { buildConversationThread } from "./utils.ts"; +import { SqliteDatabaseAdapter } from "../src/adapters/sqlite.ts"; +import defaultCharacter from "../src/core/defaultCharacter.ts"; +import { AgentRuntime } from "../src/core/runtime.ts"; +import settings from "../src/core/settings.ts"; +import { TwitterInteractionClient } from "../src/clients/twitter/interactions.ts"; +import { buildConversationThread } from "../src/clients/twitter/utils.ts"; import { fileURLToPath } from "url"; -import { ModelProvider } from "../../core/types.ts"; +import { ModelProvider } from "../src/core/types.ts"; // const __dirname = path.dirname(new URL(".", import.meta.url).pathname); diff --git a/core/tsconfig.json b/core/tsconfig.json index f10a566a259..ef9de447bc9 100644 --- a/core/tsconfig.json +++ b/core/tsconfig.json @@ -5,7 +5,7 @@ "lib": ["ESNext", "dom"], "moduleResolution": "Bundler", "outDir": "./dist", - "rootDir": "./src", + "rootDir": "./", "strict": false, "esModuleInterop": true, "skipLibCheck": true, @@ -20,8 +20,8 @@ "noEmitOnError": false, "moduleDetection": "force", "allowArbitraryExtensions": true, - "typeRoots": ["./node_modules/@types", "./types", "./node_modules/jest/types"] + "typeRoots": ["./node_modules/@types", "./types", "./node_modules/jest/types", "../node_modules/@types", "../types", "../node_modules/jest/types"], }, - "include": ["src/**/*"], + "include": ["src/**/*", "tests/**/*.test.ts"], "exclude": ["node_modules", "dist", "src/**/*.d.ts", "types/**/*.test.ts"] }