Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Tests/QyvoraNetworkingTests/LiveTests.swift8// Module : Tests9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import Testing43import QyvoraCore44@testable import QyvoraNetworking4546/// Opt-in tests against the public test networks: `QYVORA_LIVE=1 swift test --filter LiveTests`.47/// They only read public chain data (no key, no broadcast).48@Suite(.enabled(if: ProcessInfo.processInfo.environment["QYVORA_LIVE"] == "1"), .serialized)49struct LiveTests {50 let transport = URLSessionTransport()5152 @Test func esploraSignetAndTestnet() async throws {53 for network in [BitcoinNetwork.signet, .testnet] {54 let c = EsploraClient(network: network, transport: transport)55 try await c.verifyChain()56 #expect(try await c.tipHeight() > 100_000)57 let fees = try await c.feeEstimates()58 #expect(!fees.isEmpty)59 }60 let signet = EsploraClient(network: .signet, transport: transport)61 // an address taken from the first transaction page of a recent block is not stable; use the BIP-84 vector address on signet62 let a = "tb1q6rz28mcfaxtmd6v789l9rrlrusdprr9pqcpvkl"63 let stats = try await signet.addressStats(a)64 #expect(stats.address == a)65 _ = try await signet.utxos(a)66 _ = try await signet.transactions(a)67 }6869 @Test func ethereumSepolia() async throws {70 let rpc = EthereumRPC(network: .sepolia, transport: transport)71 try await rpc.verifyChain()72 #expect(try await rpc.blockNumber() > 5_000_000)73 let fee = try await rpc.feeData()74 #expect(fee.maxFee >= fee.priorityFee)75 let a = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"76 _ = try await rpc.balance(of: a)77 _ = try await rpc.transactionCount(of: a, tag: "latest")78 let idx = EthereumIndexer(network: .sepolia, transport: transport)79 let txs = try await idx.transactions(of: a)80 #expect(!txs.isEmpty)81 #expect(txs.allSatisfy { $0.hash.hasPrefix("0x") })82 let tokens = try await idx.tokenTransfers(of: a)83 _ = try await idx.tokenHoldings(of: a)84 print("sepolia:", txs.count, "txs,", tokens.count, "token transfers, first:", txs.first.map { "\($0.timestamp as Any) \($0.value) fee \($0.fee as Any)" } ?? "")85 }8687 @Test func prices() async throws {88 let p = PriceClient(transport: transport)89 let q = try await p.quotes(ids: ["bitcoin", "ethereum"])90 #expect(q["bitcoin"]!.price > 1000 && q["ethereum"]!.sparkline7d.count > 50)91 let chart = try await p.chart(id: "bitcoin", days: 7)92 #expect(chart.count > 50)93 }94}9596@Suite struct EndpointConfigurationTests {97 @Test func acceptableURLs() {98 #expect(EndpointConfiguration.isAcceptable("https://mempool.space/api"))99 #expect(EndpointConfiguration.isAcceptable("http://192.168.1.20:3002/api"))100 #expect(EndpointConfiguration.isAcceptable("http://umbrel.local:3006/api"))101 #expect(EndpointConfiguration.isAcceptable("http://172.20.0.3:8545"))102 #expect(!EndpointConfiguration.isAcceptable("http://example.com/api"))103 #expect(!EndpointConfiguration.isAcceptable("http://10.example.com/api"))104 #expect(!EndpointConfiguration.isAcceptable("http://192.168.evil.net"))105 #expect(!EndpointConfiguration.isAcceptable("http://127.0.0.1.evil.net"))106 #expect(EndpointConfiguration.isAcceptable("http://127.0.0.1:8332"))107 #expect(!EndpointConfiguration.isAcceptable("http://172.40.0.3:8545"))108 #expect(!EndpointConfiguration.isAcceptable("https://user:pw@example.com"))109 #expect(!EndpointConfiguration.isAcceptable("ftp://example.com"))110 #expect(!EndpointConfiguration.isAcceptable("not a url"))111 }112}113