Skip to content
Closed
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
19 changes: 17 additions & 2 deletions backend/tests/test_rpc_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,24 @@ def test_no_feerate_key_does_not_crash(self):
self.assertNotIn('feerate_sat_per_vb', result)

def test_clamps_target_in_rpc_call(self):
with patch.object(self.rpc, '_rpc_call', return_value={"feerate": 0.0001}) as mock:
def mock_rpc(method, params):
if method == "estimatesmartfee":
return {"feerate": 0.0001}
if method == "getblockcount":
return 800000
if method == "getmempoolfeeratediagram":
return [{"fee": 0.001, "weight": 100000}]
if method == "getblockstats":
return {"height": params[0], "total_weight": 1000000}
return None

with patch.object(self.rpc, '_rpc_call', side_effect=mock_rpc) as mock:
self.rpc.estimate_smart_fee(1, "unset", 2)
self.assertEqual(mock.call_args[0][1][0], 2) # params[0] should be 2
# Find the estimatesmartfee call — health stats trigger extra RPC calls
estimatesmartfee_calls = [c for c in mock.call_args_list if c[0][0] == "estimatesmartfee"]
self.assertGreater(len(estimatesmartfee_calls), 0)
params = estimatesmartfee_calls[0][0][1]
self.assertEqual(params[0], 2) # params[0] should be clamped to 2

# --- get_single_block_stats cache safety --------------------------------

Expand Down
9 changes: 6 additions & 3 deletions frontend/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ export interface MempoolDiagramResponse {
}

export class BitcoinCoreAPI {
private baseUrl: string = API_BASE_PATH;
private baseUrl: string;

constructor() {
constructor(baseUrl?: string) {
this.baseUrl = baseUrl ?? API_BASE_PATH;
console.debug(`[API Service] Using relative proxy path: ${this.baseUrl}`);
}

private async fetchJson<T>(path: string, options?: RequestInit): Promise<T> {
const cleanPath = path.replace(/^\/+/, "").replace(/\/+$/, "");
const url = `${this.baseUrl}/${cleanPath}`;
const url = this.baseUrl.startsWith("http")
? `${this.baseUrl.replace(/\/+$/, "")}/${cleanPath}`
: `${this.baseUrl}/${cleanPath}`;
try {
const response = await fetch(url, options);
if (!response.ok) {
Expand Down