Skip to content

Commit

Permalink
Merge pull request #504 from ai16z/solana-dep
Browse files Browse the repository at this point in the history
fix: remove sol dep
  • Loading branch information
ponderingdemocritus authored Nov 22, 2024
2 parents 084a1ea + fe90b94 commit 5deecbe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 68 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"@ai16z/adapter-sqlite": "workspace:*",
"@ai16z/adapter-sqljs": "workspace:*",
"@ai16z/adapter-supabase": "workspace:*",
"@ai16z/plugin-solana": "workspace:*",
"@anthropic-ai/sdk": "^0.30.1",
"@types/uuid": "^10.0.0",
"ai": "^3.4.23",
Expand Down
134 changes: 67 additions & 67 deletions packages/core/src/tests/token.test.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
// Now import other modules
import { createRuntime } from "../test_resources/createRuntime";
import { TokenProvider, WalletProvider } from "@ai16z/plugin-solana";
import { Connection, PublicKey } from "@solana/web3.js";
import { describe, test, expect, beforeEach, vi } from "vitest";
import NodeCache from "node-cache";
// // Now import other modules
// import { createRuntime } from "../test_resources/createRuntime";
// import { TokenProvider, WalletProvider } from "@ai16z/plugin-solana";
// import { Connection, PublicKey } from "@solana/web3.js";
// import { describe, test, expect, beforeEach, vi } from "vitest";
// import NodeCache from "node-cache";

describe("TokenProvider Tests", async () => {
let tokenProvider: TokenProvider;
// describe("TokenProvider Tests", async () => {
// let tokenProvider: TokenProvider;

beforeEach(async () => {
// Clear all mocks before each test
vi.clearAllMocks();
// beforeEach(async () => {
// // Clear all mocks before each test
// vi.clearAllMocks();

const { runtime } = await createRuntime({
env: process.env,
conversationLength: 10,
});
// const { runtime } = await createRuntime({
// env: process.env,
// conversationLength: 10,
// });

const walletProvider = new WalletProvider(
new Connection(runtime.getSetting("RPC_URL")),
new PublicKey(runtime.getSetting("WALLET_PUBLIC_KEY"))
);
// Create new instance of TokenProvider
tokenProvider = new TokenProvider(
"2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh",
walletProvider
);
// const walletProvider = new WalletProvider(
// new Connection(runtime.getSetting("RPC_URL")),
// new PublicKey(runtime.getSetting("WALLET_PUBLIC_KEY"))
// );
// // Create new instance of TokenProvider
// tokenProvider = new TokenProvider(
// "2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh",
// walletProvider
// );

// Clear the cache and ensure it's empty
(tokenProvider as any).cache.flushAll();
(tokenProvider as any).cache.close();
(tokenProvider as any).cache = new NodeCache();
// // Clear the cache and ensure it's empty
// (tokenProvider as any).cache.flushAll();
// (tokenProvider as any).cache.close();
// (tokenProvider as any).cache = new NodeCache();

// Mock the getCachedData method instead
vi.spyOn(tokenProvider as any, "getCachedData").mockReturnValue(null);
});
// // Mock the getCachedData method instead
// vi.spyOn(tokenProvider as any, "getCachedData").mockReturnValue(null);
// });

test("should fetch token security data", async () => {
// Mock the response for the fetchTokenSecurity call
const mockFetchResponse = {
success: true,
data: {
ownerBalance: "100",
creatorBalance: "50",
ownerPercentage: 10,
creatorPercentage: 5,
top10HolderBalance: "200",
top10HolderPercent: 20,
},
};
// test("should fetch token security data", async () => {
// // Mock the response for the fetchTokenSecurity call
// const mockFetchResponse = {
// success: true,
// data: {
// ownerBalance: "100",
// creatorBalance: "50",
// ownerPercentage: 10,
// creatorPercentage: 5,
// top10HolderBalance: "200",
// top10HolderPercent: 20,
// },
// };

// Mock fetchWithRetry function
const fetchSpy = vi
.spyOn(tokenProvider as any, "fetchWithRetry")
.mockResolvedValue(mockFetchResponse);
// // Mock fetchWithRetry function
// const fetchSpy = vi
// .spyOn(tokenProvider as any, "fetchWithRetry")
// .mockResolvedValue(mockFetchResponse);

// Run the fetchTokenSecurity method
const securityData = await tokenProvider.fetchTokenSecurity();
// Check if the data returned is correct
expect(securityData).toEqual({
ownerBalance: "100",
creatorBalance: "50",
ownerPercentage: 10,
creatorPercentage: 5,
top10HolderBalance: "200",
top10HolderPercent: 20,
});
// // Run the fetchTokenSecurity method
// const securityData = await tokenProvider.fetchTokenSecurity();
// // Check if the data returned is correct
// expect(securityData).toEqual({
// ownerBalance: "100",
// creatorBalance: "50",
// ownerPercentage: 10,
// creatorPercentage: 5,
// top10HolderBalance: "200",
// top10HolderPercent: 20,
// });

// Ensure the mock was called with correct URL
expect(fetchSpy).toHaveBeenCalledWith(
expect.stringContaining(
"https://public-api.birdeye.so/defi/token_security?address=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh"
)
);
});
});
// // Ensure the mock was called with correct URL
// expect(fetchSpy).toHaveBeenCalledWith(
// expect.stringContaining(
// "https://public-api.birdeye.so/defi/token_security?address=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh"
// )
// );
// });
// });

0 comments on commit 5deecbe

Please sign in to comment.