1- import { RPCFailoverManager , DEFAULT_RPC_CONFIG , getRPCManager , initializeRPCManager } from "@/lib/rpc-failover" ;
1+ import {
2+ RPCFailoverManager ,
3+ DEFAULT_RPC_CONFIG ,
4+ getRPCManager ,
5+ initializeRPCManager ,
6+ } from "@/lib/rpc-failover" ;
27
38// Mock the Stellar SDK
49jest . mock ( "@stellar/stellar-sdk" , ( ) => ( {
@@ -8,20 +13,20 @@ jest.mock("@stellar/stellar-sdk", () => ({
813 ledgers : jest . fn ( ) . mockReturnValue ( {
914 order : jest . fn ( ) . mockReturnValue ( {
1015 limit : jest . fn ( ) . mockReturnValue ( {
11- call : jest . fn ( ) . mockResolvedValue ( { records : [ ] } )
12- } )
13- } )
16+ call : jest . fn ( ) . mockResolvedValue ( { records : [ ] } ) ,
17+ } ) ,
18+ } ) ,
1419 } ) ,
15- submitTransaction : jest . fn ( ) . mockResolvedValue ( { hash : "test-hash" } )
20+ submitTransaction : jest . fn ( ) . mockResolvedValue ( { hash : "test-hash" } ) ,
1621 } ) ) ,
1722 SorobanRpc : {
1823 Server : jest . fn ( ) . mockImplementation ( ( url ) => ( {
1924 getNetwork : jest . fn ( ) . mockResolvedValue ( { } ) ,
2025 simulateTransaction : jest . fn ( ) . mockResolvedValue ( {
21- result : { retval : null }
22- } )
23- } ) )
24- }
26+ result : { retval : null } ,
27+ } ) ,
28+ } ) ) ,
29+ } ,
2530} ) ) ;
2631
2732describe ( "RPC Failover Manager" , ( ) => {
@@ -71,8 +76,8 @@ describe("RPC Failover Manager", () => {
7176 ...DEFAULT_RPC_CONFIG ,
7277 horizonUrls : [
7378 "https://primary-horizon.com" ,
74- "https://secondary-horizon.com"
75- ]
79+ "https://secondary-horizon.com" ,
80+ ] ,
7681 } ;
7782
7883 const manager = new RPCFailoverManager ( config ) ;
@@ -88,12 +93,14 @@ describe("RPC Failover Manager", () => {
8893 const manager = new RPCFailoverManager ( DEFAULT_RPC_CONFIG ) ;
8994
9095 // Mark all endpoints as unhealthy
91- manager [ "horizonEndpoints" ] . forEach ( endpoint => {
96+ manager [ "horizonEndpoints" ] . forEach ( ( endpoint ) => {
9297 endpoint . isHealthy = false ;
9398 } ) ;
99+ // Prevent an automatic refresh from re-marking endpoints as healthy.
100+ manager [ "lastHealthCheck" ] = Date . now ( ) ;
94101
95102 await expect ( manager . getHorizonServer ( ) ) . rejects . toThrow (
96- "No healthy Horizon endpoints available"
103+ "No healthy Horizon endpoints available" ,
97104 ) ;
98105 } ) ;
99106
@@ -102,7 +109,7 @@ describe("RPC Failover Manager", () => {
102109 ...DEFAULT_RPC_CONFIG ,
103110 horizonUrls : [ "https://custom-horizon.com" ] ,
104111 sorobanRpcUrls : [ "https://custom-rpc.com" ] ,
105- healthCheckInterval : 60000
112+ healthCheckInterval : 60000 ,
106113 } ;
107114
108115 const manager = new RPCFailoverManager ( customConfig ) ;
@@ -124,7 +131,7 @@ describe("RPC Failover Manager", () => {
124131 it ( "allows initialization with custom config" , ( ) => {
125132 const customConfig = {
126133 ...DEFAULT_RPC_CONFIG ,
127- healthCheckInterval : 120000
134+ healthCheckInterval : 120000 ,
128135 } ;
129136
130137 const manager = initializeRPCManager ( customConfig ) ;
@@ -162,7 +169,9 @@ describe("RPC Failover Manager", () => {
162169 const url = DEFAULT_RPC_CONFIG . horizonUrls [ 0 ] ;
163170 manager . updateEndpointPriority ( url , 10 ) ;
164171
165- const endpoint = manager . getHealthStatus ( ) . horizon . find ( e => e . url === url ) ;
172+ const endpoint = manager
173+ . getHealthStatus ( )
174+ . horizon . find ( ( e ) => e . url === url ) ;
166175 expect ( endpoint ?. priority ) . toBe ( 10 ) ;
167176 } ) ;
168- } ) ;
177+ } ) ;
0 commit comments