Skip to content

Commit b00d1ea

Browse files
authored
Merge pull request #172 from ai16z/64__basic-tests
adjusting test setup and adding a basic test
2 parents eda2b14 + 6086311 commit b00d1ea

File tree

13 files changed

+93
-29
lines changed

13 files changed

+93
-29
lines changed

.github/workflows/ci.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,13 @@ jobs:
2525
- name: Run Prettier
2626
run: pnpm run prettier --check .
2727

28+
- name: Create test env file
29+
run: |
30+
echo "TEST_DATABASE_CLIENT=sqlite" > core/.env.test
31+
echo "NODE_ENV=test" >> core/.env.test
32+
33+
- name: Run tests
34+
run: cd core && pnpm test
35+
2836
- name: Build packages
2937
run: pnpm run build

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,28 @@ downloads the model from huggingface and queries it locally
143143
## Discord Bot
144144

145145
For help with setting up your Discord Bot, check out here: https://discordjs.guide/preparations/setting-up-a-bot-application.html
146+
147+
# Development
148+
149+
## Testing
150+
151+
To run the test suite:
152+
153+
```bash
154+
pnpm test # Run tests once
155+
pnpm test:watch # Run tests in watch mode
156+
```
157+
158+
For database-specific tests:
159+
```bash
160+
pnpm test:sqlite # Run tests with SQLite
161+
pnpm test:sqljs # Run tests with SQL.js
162+
```
163+
164+
Tests are written using Jest and can be found in `src/**/*.test.ts` files. The test environment is configured to:
165+
- Load environment variables from `.env.test`
166+
- Use a 2-minute timeout for long-running tests
167+
- Support ESM modules
168+
- Run tests in sequence (--runInBand)
169+
170+
To create new tests, add a `.test.ts` file adjacent to the code you're testing.

core/.env.test

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TEST_DATABASE_CLIENT=sqlite
2+
NODE_ENV=test

core/jest.config.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
export default {
33
preset: "ts-jest",
4-
testEnvironment: "jest-environment-node",
4+
testEnvironment: "node",
55
rootDir: "./src",
66
testMatch: ["**/*.test.ts"],
7+
setupFilesAfterEnv: ["<rootDir>/test_resources/testSetup.ts"],
8+
testTimeout: 120000,
79
globals: {
810
__DEV__: true,
911
__TEST__: true,
1012
__VERSION__: "0.0.1",
1113
},
12-
// collectCoverage: true,
13-
// collectCoverageFrom: ["**/*.{ts}", "!**/*.test.{ts}", "!**/node_modules/**", "!**/vendor/**"],
14-
// coverageDirectory: "../coverage",
1514
transform: {
1615
"^.+\\.tsx?$": [
1716
"ts-jest",
@@ -24,4 +23,4 @@ export default {
2423
"^(\\.{1,2}/.*)\\.js$": "$1",
2524
},
2625
extensionsToTreatAsEsm: [".ts"],
27-
};
26+
}

core/package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
"dev": "tsc && nodemon",
3030
"build:docs": "cd docs && pnpm run build",
3131
"postinstall": "npx playwright install-deps && npx playwright install",
32-
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --runInBand --watch -f",
33-
"test:sqlite": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqlite jest --runInBand --watch -f",
34-
"test:sqljs": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqljs jest --runInBand --watch -f"
32+
"test": "jest --runInBand",
33+
"test:watch": "jest --runInBand --watch",
34+
"test:sqlite": "cross-env TEST_DATABASE_CLIENT=sqlite jest --runInBand --watch",
35+
"test:sqljs": "cross-env TEST_DATABASE_CLIENT=sqljs jest --runInBand --watch"
3536
},
3637
"author": "",
3738
"license": "MIT",
@@ -66,7 +67,8 @@
6667
"ts-node": "10.9.2",
6768
"tslib": "2.8.0",
6869
"typescript": "5.6.3",
69-
"wrangler": "3.84.0"
70+
"wrangler": "3.84.0",
71+
"@types/pdfjs-dist": "^2.10.378"
7072
},
7173
"pnpm": {
7274
"overrides": {

core/src/core/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Readable } from "stream";
2-
import { ImageGenModel } from "./imageGenModels";
2+
import { ImageGenModel } from "./imageGenModels.ts";
33

44
/**
55
* Represents a UUID, which is a universally unique identifier conforming to the UUID standard.

core/src/providers/token.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Connection } from "@solana/web3.js";
22
// import fetch from "cross-fetch";
33
import { IAgentRuntime, Memory, Provider, State } from "../core/types.ts";
44
import settings from "../core/settings.ts";
5-
import BigNumber from "bignumber.js";
5+
import { toBN, BN } from '../utils/bignumber.js';
66
import {
77
ProcessedTokenData,
88
TokenSecurityData,
@@ -609,40 +609,38 @@ export class TokenProvider {
609609
): Promise<Array<{ holderAddress: string; balanceUsd: string }>> {
610610
const holdersData = await this.fetchHolderList();
611611

612-
const tokenPriceUsd = new BigNumber(tradeData.price);
612+
const tokenPriceUsd = toBN(tradeData.price);
613613

614614
const highValueHolders = holdersData
615615
.filter((holder) => {
616-
const balanceUsd = new BigNumber(holder.balance).multipliedBy(
616+
const balanceUsd = toBN(holder.balance).multipliedBy(
617617
tokenPriceUsd
618618
);
619619
return balanceUsd.isGreaterThan(5);
620620
})
621621
.map((holder) => ({
622622
holderAddress: holder.address,
623-
balanceUsd: new BigNumber(holder.balance)
624-
.multipliedBy(tokenPriceUsd)
625-
.toFixed(2),
623+
balanceUsd: toBN(holder.balance).multipliedBy(tokenPriceUsd).toFixed(2),
626624
}));
627625

628626
return highValueHolders;
629627
}
630628

631629
async checkRecentTrades(tradeData: TokenTradeData): Promise<boolean> {
632-
return new BigNumber(tradeData.volume_24h_usd).isGreaterThan(0);
630+
return toBN(tradeData.volume_24h_usd).isGreaterThan(0);
633631
}
634632

635633
async countHighSupplyHolders(
636634
securityData: TokenSecurityData
637635
): Promise<number> {
638636
try {
639-
const ownerBalance = new BigNumber(securityData.ownerBalance);
637+
const ownerBalance = toBN(securityData.ownerBalance);
640638
const totalSupply = ownerBalance.plus(securityData.creatorBalance);
641639

642640
const highSupplyHolders = await this.fetchHolderList();
643641
const highSupplyHoldersCount = highSupplyHolders.filter(
644642
(holder) => {
645-
const balance = new BigNumber(holder.balance);
643+
const balance = toBN(holder.balance);
646644
return balance.dividedBy(totalSupply).isGreaterThan(0.02);
647645
}
648646
).length;
@@ -738,8 +736,8 @@ export class TokenProvider {
738736
output += `- Unique Wallets (24h): ${data.tradeData.unique_wallet_24h}\n`;
739737
output += `- Price Change (24h): ${data.tradeData.price_change_24h_percent}%\n`;
740738
output += `- Price Change (12h): ${data.tradeData.price_change_12h_percent}%\n`;
741-
output += `- Volume (24h USD): $${new BigNumber(data.tradeData.volume_24h_usd).toFixed(2)}\n`;
742-
output += `- Current Price: $${new BigNumber(data.tradeData.price).toFixed(2)}\n\n`;
739+
output += `- Volume (24h USD): $${toBN(data.tradeData.volume_24h_usd).toFixed(2)}\n`;
740+
output += `- Current Price: $${toBN(data.tradeData.price).toFixed(2)}\n\n`;
743741

744742
// Holder Distribution Trend
745743
output += `**Holder Distribution Trend:** ${data.holderDistributionTrend}\n\n`;
@@ -771,10 +769,10 @@ export class TokenProvider {
771769
output += `\n**Pair ${index + 1}:**\n`;
772770
output += `- DEX: ${pair.dexId}\n`;
773771
output += `- URL: ${pair.url}\n`;
774-
output += `- Price USD: $${new BigNumber(pair.priceUsd).toFixed(6)}\n`;
775-
output += `- Volume (24h USD): $${new BigNumber(pair.volume.h24).toFixed(2)}\n`;
772+
output += `- Price USD: $${toBN(pair.priceUsd).toFixed(6)}\n`;
773+
output += `- Volume (24h USD): $${toBN(pair.volume.h24).toFixed(2)}\n`;
776774
output += `- Boosts Active: ${pair.boosts && pair.boosts.active}\n`;
777-
output += `- Liquidity USD: $${new BigNumber(pair.liquidity.usd).toFixed(2)}\n`;
775+
output += `- Liquidity USD: $${toBN(pair.liquidity.usd).toFixed(2)}\n`;
778776
});
779777
}
780778
output += `\n`;

core/src/test_resources/basic.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
describe('Basic Test Suite', () => {
2+
it('should run a basic test', () => {
3+
expect(true).toBe(true);
4+
});
5+
6+
it('should have access to environment variables', () => {
7+
expect(process.env.NODE_ENV).toBe('test');
8+
expect(process.env.TEST_DATABASE_CLIENT).toBe('sqlite');
9+
});
10+
});

core/src/test_resources/testSetup.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import dotenv from "dotenv";
2+
import path from 'path';
3+
4+
// Load test environment variables
5+
dotenv.config({ path: '.env.test' });
6+
7+
// Set longer timeout for tests
8+
jest.setTimeout(120000);

core/src/utils/bignumber.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import BigNumber from 'bignumber.js';
2+
3+
// Re-export BigNumber constructor
4+
export const BN = BigNumber;
5+
6+
// Helper function to create new BigNumber instances
7+
export function toBN(value: string | number | BigNumber): BigNumber {
8+
return new BigNumber(value);
9+
}

core/src/utils/youtube.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import youtubeDl from 'youtube-dl-exec';
2+
3+
export const youtube = (url: string, options?: any) => youtubeDl(url, options);

core/tsconfig.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
3-
"target": "es2022",
4-
"module": "es2022",
5-
"lib": ["es2023", "dom"],
6-
"moduleResolution": "bundler",
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"lib": ["ESNext", "dom"],
6+
"moduleResolution": "Bundler",
77
"outDir": "./dist",
88
"rootDir": "./src",
99
"strict": false,

pnpm-lock.yaml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)