Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Tests/QyvoraWalletTests/UTXOCoinsAddressAuditRegressionTests.swift8// Module : Tests9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0512// Last Modified : 2026-12-0513//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 QyvoraMath44import QyvoraCore45@testable import QyvoraBitcoin46import QyvoraNetworking47@testable import QyvoraWallet4849/// QYV-SVC-065. A Bitcoin Cash recipient written in the legacy Base58 form is also a Bitcoin address (the classic50/// BTC ↔ BCH mis-send). `checkAddress` said so in a note, but the review of the payment did not: the canonical51/// CashAddr form was handed down and the fact was lost. The review now carries a critical warning.52@Suite(.readsMainnetPolicy) struct UTXOCoinsAddressAuditRegressionTests {53 @Test func aLegacyBitcoinCashRecipientIsACriticalWarningOfTheReview() async throws {54 let h = try await CoinFixture.wallet(chain: .bitcoinCash, network: .bitcoinCashTestnet)55 defer { h.cleanup() }56 let receive = try #require(await h.service.snapshot().chain(.bitcoinCashTestnet)?.receive)57 h.backend.fund(receive.address, 400_000)58 try await h.service.synchronize(chain: .bitcoinCashTestnet)59 for script in [try BitcoinScript.p2pkh(publicKeyHash: Bytes(repeating: 0x66, count: 20)), try BitcoinScript.p2sh(scriptHash: Bytes(repeating: 0x67, count: 20))] {60 let address = try BitcoinAddress(scriptPubKey: script, network: .bitcoinCashTestnet)61 let legacy = try #require(address.base58String)62 #expect(address.string.hasPrefix("bchtest:") && !legacy.contains(":"))63 // the legacy form: accepted, converted, and flagged in the check and in the review64 let check = try await h.service.checkAddress(legacy, chain: .bitcoinCashTestnet)65 #expect(check.canonical == address.string && check.notes.contains { $0.contains("legacy form") })66 let review = try await h.service.prepareSend(chain: .bitcoinCashTestnet, asset: .native, to: " " + legacy + "\n", amount: UInt256(50_000))67 let warning = try #require(review.warnings.first { $0.id == "bch.legacy-address" })68 #expect(warning.isCritical && warning.message.contains("Bitcoin address") && review.recipient == address.string)69 // the CashAddr form of the same script: no such warning70 let plain = try await h.service.prepareSend(chain: .bitcoinCashTestnet, asset: .native, to: address.string, amount: UInt256(50_000))71 #expect(!plain.warnings.contains { $0.id == "bch.legacy-address" } && plain.recipient == review.recipient)72 }73 }7475 @Test func theWarningExistsOnlyOnBitcoinCash() async throws {76 let h = try await CoinFixture.wallet(chain: .litecoin, network: .litecoinTestnet)77 defer { h.cleanup() }78 h.backend.fund(CoinFixture.litecoinTestnet0, 500_000)79 try await h.service.synchronize(chain: .litecoinTestnet)80 let legacy = try BitcoinAddress(scriptPubKey: try BitcoinScript.p2pkh(publicKeyHash: Bytes(repeating: 0x66, count: 20)), network: .litecoinTestnet).string81 let review = try await h.service.prepareSend(chain: .litecoinTestnet, asset: .native, to: legacy, amount: UInt256(100_000))82 #expect(!review.warnings.contains { $0.id == "bch.legacy-address" })83 // Litecoin's former P2SH form (Bitcoin's own) is refused, not warned about84 let former = try BitcoinAddress(scriptPubKey: try BitcoinScript.p2sh(scriptHash: Bytes(repeating: 0x67, count: 20)), network: .testnet).string85 guard case .address(.unsupported)? = await walletError({ try await h.service.prepareSend(chain: .litecoinTestnet, asset: .native, to: former, amount: UInt256(100_000)) }) else {86 Issue.record("the former Litecoin P2SH form was not refused")87 return88 }89 }90}91