2
2
import { createRuntime } from "../test_resources/createRuntime" ;
3
3
import { TokenProvider , WalletProvider } from "@ai16z/plugin-solana" ;
4
4
import { Connection , PublicKey } from "@solana/web3.js" ;
5
- import { describe , test , expect , beforeEach , vi } from ' vitest' ;
6
- import NodeCache from ' node-cache' ;
5
+ import { describe , test , expect , beforeEach , vi } from " vitest" ;
6
+ import NodeCache from " node-cache" ;
7
7
8
8
describe ( "TokenProvider Tests" , async ( ) => {
9
9
let tokenProvider : TokenProvider ;
@@ -13,14 +13,14 @@ describe("TokenProvider Tests", async () => {
13
13
vi . clearAllMocks ( ) ;
14
14
15
15
const { runtime } = await createRuntime ( {
16
- env : process . env ,
17
- conversationLength : 10 ,
16
+ env : process . env ,
17
+ conversationLength : 10 ,
18
18
} ) ;
19
19
20
20
const walletProvider = new WalletProvider (
21
- new Connection ( runtime . getSetting ( "RPC_URL" ) ) ,
22
- new PublicKey ( runtime . getSetting ( "WALLET_PUBLIC_KEY" ) )
23
- ) ;
21
+ new Connection ( runtime . getSetting ( "RPC_URL" ) ) ,
22
+ new PublicKey ( runtime . getSetting ( "WALLET_PUBLIC_KEY" ) )
23
+ ) ;
24
24
// Create new instance of TokenProvider
25
25
tokenProvider = new TokenProvider (
26
26
"2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh" ,
@@ -31,31 +31,30 @@ describe("TokenProvider Tests", async () => {
31
31
( tokenProvider as any ) . cache . flushAll ( ) ;
32
32
( tokenProvider as any ) . cache . close ( ) ;
33
33
( tokenProvider as any ) . cache = new NodeCache ( ) ;
34
-
34
+
35
35
// Mock the getCachedData method instead
36
- vi . spyOn ( tokenProvider as any , ' getCachedData' ) . mockReturnValue ( null ) ;
36
+ vi . spyOn ( tokenProvider as any , " getCachedData" ) . mockReturnValue ( null ) ;
37
37
} ) ;
38
38
39
39
test ( "should fetch token security data" , async ( ) => {
40
-
41
40
// Mock the response for the fetchTokenSecurity call
42
41
const mockFetchResponse = {
43
- success : true ,
44
- data : {
45
- ownerBalance : "100" ,
46
- creatorBalance : "50" ,
47
- ownerPercentage : 10 ,
48
- creatorPercentage : 5 ,
49
- top10HolderBalance : "200" ,
50
- top10HolderPercent : 20 ,
51
- } ,
42
+ success : true ,
43
+ data : {
44
+ ownerBalance : "100" ,
45
+ creatorBalance : "50" ,
46
+ ownerPercentage : 10 ,
47
+ creatorPercentage : 5 ,
48
+ top10HolderBalance : "200" ,
49
+ top10HolderPercent : 20 ,
50
+ } ,
52
51
} ;
53
-
52
+
54
53
// Mock fetchWithRetry function
55
54
const fetchSpy = vi
56
- . spyOn ( tokenProvider as any , "fetchWithRetry" )
57
- . mockResolvedValue ( mockFetchResponse ) ;
58
-
55
+ . spyOn ( tokenProvider as any , "fetchWithRetry" )
56
+ . mockResolvedValue ( mockFetchResponse ) ;
57
+
59
58
// Run the fetchTokenSecurity method
60
59
const securityData = await tokenProvider . fetchTokenSecurity ( ) ;
61
60
// Check if the data returned is correct
@@ -70,7 +69,9 @@ describe("TokenProvider Tests", async () => {
70
69
71
70
// Ensure the mock was called with correct URL
72
71
expect ( fetchSpy ) . toHaveBeenCalledWith (
73
- expect . stringContaining ( "https://public-api.birdeye.so/defi/token_security?address=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh" ) ,
72
+ expect . stringContaining (
73
+ "https://public-api.birdeye.so/defi/token_security?address=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh"
74
+ )
74
75
) ;
75
76
} ) ;
76
77
} ) ;
0 commit comments