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

adjusting test setup and adding a basic test #172

Merged
merged 6 commits into from
Nov 3, 2024
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ jobs:
- name: Run Prettier
run: pnpm run prettier --check .

- name: Create test env file
run: |
echo "TEST_DATABASE_CLIENT=sqlite" > core/.env.test
echo "NODE_ENV=test" >> core/.env.test

- name: Run tests
run: cd core && pnpm test

- name: Build packages
run: pnpm run build
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,28 @@ downloads the model from huggingface and queries it locally
## Discord Bot

For help with setting up your Discord Bot, check out here: https://discordjs.guide/preparations/setting-up-a-bot-application.html

# Development

## Testing

To run the test suite:

```bash
pnpm test # Run tests once
pnpm test:watch # Run tests in watch mode
```

For database-specific tests:
```bash
pnpm test:sqlite # Run tests with SQLite
pnpm test:sqljs # Run tests with SQL.js
```

Tests are written using Jest and can be found in `src/**/*.test.ts` files. The test environment is configured to:
- Load environment variables from `.env.test`
- Use a 2-minute timeout for long-running tests
- Support ESM modules
- Run tests in sequence (--runInBand)

To create new tests, add a `.test.ts` file adjacent to the code you're testing.
2 changes: 2 additions & 0 deletions core/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TEST_DATABASE_CLIENT=sqlite
NODE_ENV=test
9 changes: 4 additions & 5 deletions core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: "ts-jest",
testEnvironment: "jest-environment-node",
testEnvironment: "node",
rootDir: "./src",
testMatch: ["**/*.test.ts"],
setupFilesAfterEnv: ["<rootDir>/test_resources/testSetup.ts"],
testTimeout: 120000,
globals: {
__DEV__: true,
__TEST__: true,
__VERSION__: "0.0.1",
},
// collectCoverage: true,
// collectCoverageFrom: ["**/*.{ts}", "!**/*.test.{ts}", "!**/node_modules/**", "!**/vendor/**"],
// coverageDirectory: "../coverage",
transform: {
"^.+\\.tsx?$": [
"ts-jest",
Expand All @@ -24,4 +23,4 @@ export default {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
extensionsToTreatAsEsm: [".ts"],
};
}
10 changes: 6 additions & 4 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
"dev": "tsc && nodemon",
"build:docs": "cd docs && pnpm run build",
"postinstall": "npx playwright install-deps && npx playwright install",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --runInBand --watch -f",
"test:sqlite": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqlite jest --runInBand --watch -f",
"test:sqljs": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqljs jest --runInBand --watch -f"
"test": "jest --runInBand",
"test:watch": "jest --runInBand --watch",
"test:sqlite": "cross-env TEST_DATABASE_CLIENT=sqlite jest --runInBand --watch",
"test:sqljs": "cross-env TEST_DATABASE_CLIENT=sqljs jest --runInBand --watch"
},
"author": "",
"license": "MIT",
Expand Down Expand Up @@ -66,7 +67,8 @@
"ts-node": "10.9.2",
"tslib": "2.8.0",
"typescript": "5.6.3",
"wrangler": "3.84.0"
"wrangler": "3.84.0",
"@types/pdfjs-dist": "^2.10.378"
},
"pnpm": {
"overrides": {
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Readable } from "stream";
import { ImageGenModel } from "./imageGenModels";
import { ImageGenModel } from "./imageGenModels.ts";

/**
* Represents a UUID, which is a universally unique identifier conforming to the UUID standard.
Expand Down
26 changes: 12 additions & 14 deletions core/src/providers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Connection } from "@solana/web3.js";
// import fetch from "cross-fetch";
import { IAgentRuntime, Memory, Provider, State } from "../core/types.ts";
import settings from "../core/settings.ts";
import BigNumber from "bignumber.js";
import { toBN, BN } from '../utils/bignumber.js';
import {
ProcessedTokenData,
TokenSecurityData,
Expand Down Expand Up @@ -609,40 +609,38 @@ export class TokenProvider {
): Promise<Array<{ holderAddress: string; balanceUsd: string }>> {
const holdersData = await this.fetchHolderList();

const tokenPriceUsd = new BigNumber(tradeData.price);
const tokenPriceUsd = toBN(tradeData.price);

const highValueHolders = holdersData
.filter((holder) => {
const balanceUsd = new BigNumber(holder.balance).multipliedBy(
const balanceUsd = toBN(holder.balance).multipliedBy(
tokenPriceUsd
);
return balanceUsd.isGreaterThan(5);
})
.map((holder) => ({
holderAddress: holder.address,
balanceUsd: new BigNumber(holder.balance)
.multipliedBy(tokenPriceUsd)
.toFixed(2),
balanceUsd: toBN(holder.balance).multipliedBy(tokenPriceUsd).toFixed(2),
}));

return highValueHolders;
}

async checkRecentTrades(tradeData: TokenTradeData): Promise<boolean> {
return new BigNumber(tradeData.volume_24h_usd).isGreaterThan(0);
return toBN(tradeData.volume_24h_usd).isGreaterThan(0);
}

async countHighSupplyHolders(
securityData: TokenSecurityData
): Promise<number> {
try {
const ownerBalance = new BigNumber(securityData.ownerBalance);
const ownerBalance = toBN(securityData.ownerBalance);
const totalSupply = ownerBalance.plus(securityData.creatorBalance);

const highSupplyHolders = await this.fetchHolderList();
const highSupplyHoldersCount = highSupplyHolders.filter(
(holder) => {
const balance = new BigNumber(holder.balance);
const balance = toBN(holder.balance);
return balance.dividedBy(totalSupply).isGreaterThan(0.02);
}
).length;
Expand Down Expand Up @@ -738,8 +736,8 @@ export class TokenProvider {
output += `- Unique Wallets (24h): ${data.tradeData.unique_wallet_24h}\n`;
output += `- Price Change (24h): ${data.tradeData.price_change_24h_percent}%\n`;
output += `- Price Change (12h): ${data.tradeData.price_change_12h_percent}%\n`;
output += `- Volume (24h USD): $${new BigNumber(data.tradeData.volume_24h_usd).toFixed(2)}\n`;
output += `- Current Price: $${new BigNumber(data.tradeData.price).toFixed(2)}\n\n`;
output += `- Volume (24h USD): $${toBN(data.tradeData.volume_24h_usd).toFixed(2)}\n`;
output += `- Current Price: $${toBN(data.tradeData.price).toFixed(2)}\n\n`;

// Holder Distribution Trend
output += `**Holder Distribution Trend:** ${data.holderDistributionTrend}\n\n`;
Expand Down Expand Up @@ -771,10 +769,10 @@ export class TokenProvider {
output += `\n**Pair ${index + 1}:**\n`;
output += `- DEX: ${pair.dexId}\n`;
output += `- URL: ${pair.url}\n`;
output += `- Price USD: $${new BigNumber(pair.priceUsd).toFixed(6)}\n`;
output += `- Volume (24h USD): $${new BigNumber(pair.volume.h24).toFixed(2)}\n`;
output += `- Price USD: $${toBN(pair.priceUsd).toFixed(6)}\n`;
output += `- Volume (24h USD): $${toBN(pair.volume.h24).toFixed(2)}\n`;
output += `- Boosts Active: ${pair.boosts && pair.boosts.active}\n`;
output += `- Liquidity USD: $${new BigNumber(pair.liquidity.usd).toFixed(2)}\n`;
output += `- Liquidity USD: $${toBN(pair.liquidity.usd).toFixed(2)}\n`;
});
}
output += `\n`;
Expand Down
10 changes: 10 additions & 0 deletions core/src/test_resources/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe('Basic Test Suite', () => {
it('should run a basic test', () => {
expect(true).toBe(true);
});

it('should have access to environment variables', () => {
expect(process.env.NODE_ENV).toBe('test');
expect(process.env.TEST_DATABASE_CLIENT).toBe('sqlite');
});
});
8 changes: 8 additions & 0 deletions core/src/test_resources/testSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import dotenv from "dotenv";
import path from 'path';

// Load test environment variables
dotenv.config({ path: '.env.test' });

// Set longer timeout for tests
jest.setTimeout(120000);
9 changes: 9 additions & 0 deletions core/src/utils/bignumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import BigNumber from 'bignumber.js';

// Re-export BigNumber constructor
export const BN = BigNumber;

// Helper function to create new BigNumber instances
export function toBN(value: string | number | BigNumber): BigNumber {
return new BigNumber(value);
}
3 changes: 3 additions & 0 deletions core/src/utils/youtube.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import youtubeDl from 'youtube-dl-exec';

export const youtube = (url: string, options?: any) => youtubeDl(url, options);
8 changes: 4 additions & 4 deletions core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"lib": ["es2023", "dom"],
"moduleResolution": "bundler",
"target": "ESNext",
"module": "ESNext",
"lib": ["ESNext", "dom"],
"moduleResolution": "Bundler",
"outDir": "./dist",
"rootDir": "./src",
"strict": false,
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.