Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : security/tests/Tests/ConformanceAuditTests/UTXOCoinsVectors.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 AuditSupport42import Foundation43import QyvoraMath44import QyvoraSymmetric45import Testing4647@testable import QyvoraBitcoin48@testable import QyvoraCore49@testable import QyvoraSecp256k15051// Litecoin, Dogecoin and Bitcoin Cash conformance from files fetched at pinned revisions (security/vectors,52// MANIFEST.json):53// cashaddr/ the two tables of the CashAddr specification and the checksum strings of Bitcoin Cash Node;54// bchn/ the 1000 signature-hash vectors of Bitcoin Cash Node (original and fork-id algorithms);55// utxo-mainnet/ public main-network transactions with the transactions their inputs spend.5657@Suite struct UTXOCoinsConformance {58 static func object(_ path: String) throws -> [String: Any] {59 try #require(try AuditVectors.json(AuditPaths.vectors.appendingPathComponent(path)) as? [String: Any])60 }6162 // MARK: CashAddr6364 /// The specification's tables: 6 legacy / CashAddr pairs, 32 addresses of every hash size.65 @Test func cashAddrSpecificationTables() throws {66 let spec = try Self.object("cashaddr/cashaddr-spec-vectors.json")67 var board = Board(source: "CashAddr specification (bitcoincashorg/bitcoincash.org spec/cashaddr.md, pinned commit)")68 let translation = try #require(spec["translation"] as? [[String: Any]])69 #expect(translation.count == 6)70 for row in translation {71 let legacy = row.str("legacy"), cash = row.str("cashaddr")72 let fromLegacy = try? BitcoinAddress(legacy, network: .bitcoinCash)73 board.add("CashAddr", "translation", "legacy-to-cashaddr", ok: fromLegacy?.string == cash && fromLegacy?.isLegacyFormat == true, id: legacy)74 let fromCash = try? BitcoinAddress(cash, network: .bitcoinCash)75 board.add("CashAddr", "translation", "cashaddr-to-legacy", ok: fromCash?.base58String == legacy && fromCash?.isLegacyFormat == false, id: cash)76 board.add("CashAddr", "translation", "same-script", ok: fromCash != nil && fromCash?.scriptPubKey == fromLegacy?.scriptPubKey, id: cash)77 // the upper-case form (QR codes) and the form without prefix decode to the same address78 let upper = try? BitcoinAddress(cash.uppercased(), network: .bitcoinCash)79 let bare = try? BitcoinAddress(String(cash.split(separator: ":")[1]), network: .bitcoinCash)80 board.add("CashAddr", "translation", "upper-case-and-bare", ok: upper?.string == cash && bare?.string == cash, id: cash)81 // on the test network the same text is another network's82 let wrong: BitcoinAddress.Error? = { do { _ = try BitcoinAddress(cash, network: .bitcoinCashTestnet); return nil } catch { return error as? BitcoinAddress.Error } }()83 board.add("CashAddr", "translation", "wrong-network", ok: wrong == .wrongNetwork, id: cash)84 }85 let larger = try #require(spec["larger"] as? [[String: Any]])86 #expect(larger.count == 32)87 var payable = 088 for row in larger {89 let text = row.str("cashaddr")90 let payload = try #require(row.hex("payload")), type = try #require(row.integer("type")), size = try #require(row.integer("size"))91 #expect(payload.count == size)92 let prefix = String(text.split(separator: ":")[0])93 let decoded = CashAddr.decode(text)94 board.add("CashAddr", "larger", "decode", ok: decoded == CashAddr.Decoded(prefix: prefix, type: UInt8(type), hash: payload), id: text)95 board.add("CashAddr", "larger", "encode", ok: CashAddr.encode(prefix: prefix, type: UInt8(type), hash: payload) == text, id: text)96 board.add("CashAddr", "larger", "decode-upper-case", ok: CashAddr.decode(text.uppercased()) == decoded && decoded != nil, id: text)97 let body = String(text.split(separator: ":")[1])98 board.add("CashAddr", "larger", "decode-without-prefix", ok: CashAddr.decode(body, defaultPrefix: prefix) == decoded && CashAddr.decode(body) == nil, id: text)99 // the checksum covers the prefix: the body under another prefix is refused100 board.add("CashAddr", "larger", "prefix-is-checksummed", ok: CashAddr.decode(body, defaultPrefix: prefix + "x") == nil, id: text)101 // what the wallet pays to: 20-byte P2PKH / P2SH of the network's own prefix, nothing else102 for network in [BitcoinNetwork.bitcoinCash, .bitcoinCashTestnet] {103 let parsed = try? BitcoinAddress(text, network: network)104 let expected = size == 20 && type <= 1 && prefix == network.cashAddrPrefix105 if expected { payable += 1 }106 board.add("CashAddr", "larger", "wallet-acceptance", ok: (parsed != nil) == expected && (parsed == nil || parsed?.string == text), id: text + " on " + network.rawValue)107 }108 // never an address of a coin without CashAddr109 for network in [BitcoinNetwork.mainnet, .litecoin, .dogecoin] {110 board.add("CashAddr", "larger", "other-coins-refuse", ok: (try? BitcoinAddress(text, network: network)) == nil, id: text)111 }112 }113 #expect(payable == 2)114 #expect(board.cases == 6 * 5 + 32 * 10)115 board.finish(minimum: 350)116 }117118 /// Bitcoin Cash Node's checksum strings: 6 valid, 24 invalid, 7 without prefix.119 @Test func cashAddrChecksumStringsOfBitcoinCashNode() throws {120 let file = try Self.object("cashaddr/bchn-cashaddr-tests.json")121 var board = Board(source: "Bitcoin Cash Node src/test/cashaddr_tests.cpp (pinned commit)")122 let valid = try #require(file["valid"] as? [String]), invalid = try #require(file["invalid"] as? [String])123 let noprefix = try #require(file["noprefix"] as? [[String: Any]])124 #expect(valid.count == 6 && invalid.count == 24 && noprefix.count == 7)125 for s in valid { board.add("CashAddr", "checksum", "valid", ok: CashAddr.hasValidChecksum(s), id: s) }126 for s in invalid {127 board.add("CashAddr", "checksum", "invalid", ok: !CashAddr.hasValidChecksum(s), id: s)128 board.add("CashAddr", "checksum", "invalid-not-decoded", ok: CashAddr.decode(s) == nil && CashAddr.decode(s, defaultPrefix: "bitcoincash") == nil, id: s)129 for network in BitcoinNetwork.allCases {130 board.add("CashAddr", "checksum", "invalid-not-an-address", ok: (try? BitcoinAddress(s, network: network)) == nil, id: s)131 }132 }133 for c in noprefix { board.add("CashAddr", "checksum", "valid-with-given-prefix", ok: CashAddr.hasValidChecksum(c.str("prefix") + ":" + c.str("payload")), id: c.str("payload")) }134 #expect(board.cases == 6 + 24 * (2 + BitcoinNetwork.allCases.count) + 7)135 board.finish(minimum: 37)136 }137138 // MARK: Signature hashes139140 /// The 1000 vectors of Bitcoin Cash Node. The file carries no amounts: the fork-id digests were produced with141 /// amount 0. The hash types are random 32-bit values, so almost none is a type the wallet signs with; the142 /// record says how many rows the public functions can express and how many only the preimage function can.143 @Test func bitcoinCashNodeSignatureHashes() throws {144 let url = AuditPaths.vectors.appendingPathComponent("bchn/sighash.json.gz")145 let rows = try #require(try JSONSerialization.jsonObject(with: try AuditVectors.gunzip(try Data(contentsOf: url))) as? [[Any]])146 #expect(rows.count == 1001)147 var board = Board(source: "Bitcoin Cash Node src/test/data/sighash.json (tag v29.2.0, pinned commit)")148 var forkRows = 0, plainRows = 0, publicForkID = 0, publicScheme = 0, unparsed = 0149 for (n, row) in rows.dropFirst().enumerated() {150 guard row.count == 6, let raw = row[0] as? String, let scriptHex = row[1] as? String, let index = row[2] as? Int, let signedType = row[3] as? Int,151 let regular = row[4] as? String, let noFork = row[5] as? String, let script = Hex.decode(scriptHex) else {152 Issue.record("row \(n) has another shape")153 continue154 }155 guard let tx = try? BitcoinTransaction(hex: raw, allowWitness: false) else {156 unparsed += 1157 board.add("Bitcoin Cash sighash", "", "transaction-parses", ok: false, id: n)158 continue159 }160 board.add("Bitcoin Cash sighash", "", "transaction-round-trip", ok: tx.hex == raw, id: n)161 let type = BitcoinSighashType(rawValue: UInt32(truncatingIfNeeded: signedType))162 // original algorithm: every row163 let original = try? BitcoinSighash.legacy(transaction: tx, inputIndex: index, scriptCode: script, type: type)164 board.add("Bitcoin Cash sighash", "original algorithm", "digest", ok: original.map { Hex.encode($0.reversed()) } == noFork, id: n)165 if type.hasForkID {166 forkRows += 1167 // BIP-143-style preimage with amount 0 and the full 32-bit hash type168 let preimage = try? BitcoinSighash.segwitV0Preimage(transaction: tx, inputIndex: index, scriptCode: script, value: 0, type: type)169 board.add("Bitcoin Cash sighash", "fork-id algorithm, amount 0", "digest", ok: preimage.map { Hex.encode(SHA256.double($0).reversed()) } == regular, id: n)170 // the public function refuses a fork id other than 0 (upper 24 bits): count the rows it expresses171 if let viaPublic = try? BitcoinSighash.forkID(transaction: tx, inputIndex: index, scriptCode: script, value: 0, type: type) {172 publicForkID += 1173 board.add("Bitcoin Cash sighash", "fork-id algorithm, amount 0", "public-function", ok: Hex.encode(viaPublic.reversed()) == regular, id: n)174 }175 } else {176 plainRows += 1177 board.add("Bitcoin Cash sighash", "original algorithm", "regular-equals-no-fork-flag", ok: regular == noFork, id: n)178 }179 if type.isStandard(for: .bip143ForkID) || type.isStandard(for: .legacy) { publicScheme += 1 }180 }181 #expect(unparsed == 0)182 #expect(forkRows + plainRows == 1000)183 board.finish(minimum: 2500, note: "1000 rows: \(forkRows) with SIGHASH_FORKID (fork-id digest, amount 0, through the preimage function; \(publicForkID) of them also expressible by the public forkID function, which requires fork id 0), \(plainRows) without (original algorithm); the original algorithm is replayed on all 1000. \(publicScheme) rows carry one of the hash types the wallet signs with. The vectors hold no amount: the commitment of the fork-id digest to a non-zero amount is covered by the main-network transactions and by the differential tests.")184 }185186 // MARK: Main-network transactions187188 struct Counts {189 var transactions = 0, inputs = 0, ecdsaVerified = 0, schnorr = 0, previous = 0, mwebSkipped = 0190 }191192 /// Public transactions: strict parsing, byte-identical serialization, identifier, authenticated previous outputs,193 /// then the signature hash of every input under the coin's scheme and the ECDSA signature found on chain.194 @Test func mainNetworkTransactionsVerify() throws {195 let file = try Self.object("utxo-mainnet/transactions.json")196 let coins = try #require(file["coins"] as? [String: Any])197 var board = Board(source: "public main-network transactions (security/vectors/utxo-mainnet, fetched 2026-12-05)")198 var counts = [String: Counts]()199 for (name, value) in coins.sorted(by: { $0.key < $1.key }) {200 let network = try #require(BitcoinNetwork(rawValue: name))201 let scheme = network.sighashScheme202 let list = try #require((value as? [String: Any])?["transactions"] as? [[String: Any]])203 var c = Counts()204 for t in list {205 let txid = t.str("txid"), raw = t.str("raw")206 guard let tx = try? BitcoinTransaction(hex: raw, allowWitness: network.supportsSegWit) else {207 board.add(network.displayName, "", "parse", ok: false, id: txid)208 continue209 }210 c.transactions += 1211 board.add(network.displayName, "", "parse", ok: true, id: txid)212 board.add(network.displayName, "", "serialize-byte-identical", ok: tx.hex == raw, id: txid)213 board.add(network.displayName, "", "txid", ok: tx.txid == txid, id: txid)214 board.add(network.displayName, "", "sanity", ok: (try? tx.checkSanity(maximumMoney: network.maximumMoney)) != nil, id: txid)215 if !network.supportsSegWit { board.add(network.displayName, "", "no-witness", ok: !tx.hasWitness && tx.vsize == tx.serialized().count, id: txid) }216 let previous = try #require(t["previous"] as? [String: String])217 var spent = [BitcoinTransaction.Output]()218 var total: UInt64 = 0219 for input in tx.inputs {220 // Litecoin MWEB: an integrating transaction is serialized with flag 0x08 (marker 00, flag bit 3) and221 // carries extension data the engine does not parse. The wallet never needs such a transaction (its222 // Litecoin inputs are P2WPKH, whose signature commits to the amount), so the row is skipped, and said.223 if let hex = previous[input.previousOutput.txid], let head = Hex.decode(String(hex.prefix(12))), head.count == 6, head[4] == 0x00, head[5] & 0x08 != 0 {224 c.mwebSkipped += 1225 board.skip(network.displayName, "", "previous-transaction-with-mweb-flag")226 #expect((try? BitcoinTransaction(hex: hex, allowWitness: true)) == nil, "an MWEB serialization parsed: the limitation no longer holds, replay this row")227 continue228 }229 guard let hex = previous[input.previousOutput.txid], let p = try? BitcoinTransaction(hex: hex, allowWitness: network.supportsSegWit) else {230 board.add(network.displayName, "", "previous-transaction", ok: false, id: txid)231 continue232 }233 c.previous += 1234 // authenticated by its own hash; the amount and the script come from it235 let ok = p.txid == input.previousOutput.txid && Int(input.previousOutput.index) < p.outputs.count236 board.add(network.displayName, "", "previous-transaction", ok: ok, id: txid)237 guard ok else { continue }238 let output = p.outputs[Int(input.previousOutput.index)]239 let utxo = BitcoinUTXO(outPoint: input.previousOutput, value: output.value, scriptPubKey: output.scriptPubKey, confirmations: 1)240 board.add(network.displayName, "", "utxo-authenticated", ok: utxo.isAuthenticated(by: p) && !utxo.isAuthenticated(by: tx), id: txid)241 let lying = BitcoinUTXO(outPoint: input.previousOutput, value: output.value &- 1, scriptPubKey: output.scriptPubKey, confirmations: 1)242 board.add(network.displayName, "", "understated-utxo-refused", ok: !lying.isAuthenticated(by: p), id: txid)243 spent.append(output)244 total += output.value245 }246 guard spent.count == tx.inputs.count, let out = tx.outputValue(maximumMoney: network.maximumMoney) else { continue }247 board.add(network.displayName, "", "fee-not-negative", ok: total >= out, id: txid)248 for i in tx.inputs.indices {249 c.inputs += 1250 do {251 try BitcoinVerifier.verifyInput(transaction: tx, inputIndex: i, spentOutput: spent[i], requireLowS: true, scheme: scheme)252 c.ecdsaVerified += 1253 board.add(network.displayName, t.str("inputKind"), "signature-verifies", ok: true, id: txid)254 // explicitly, for P2PKH: the digest is recomputed here and the signature checked against it255 if case .p2pkh = BitcoinScript.classify(spent[i].scriptPubKey), let elements = try? BitcoinScript.decode(tx.inputs[i].scriptSig), elements.count == 2,256 case .push(let signature, _) = elements[0], case .push(let key, _) = elements[1], let last = signature.last {257 let type = BitcoinSighashType(rawValue: UInt32(last))258 let digest = try? BitcoinSighash.digest(scheme: scheme, isWitness: false, transaction: tx, inputIndex: i, scriptCode: spent[i].scriptPubKey,259 value: spent[i].value, type: type)260 let compact = try? Secp256k1.parseDER(Bytes(signature.dropLast()))261 let valid = digest != nil && compact != nil && Secp256k1.verify(compactSignature: compact!, digest: digest!, publicKey: key, requireLowS: true)262 board.add(network.displayName, "p2pkh", "digest-recomputed-and-ecdsa-verified", ok: valid, id: txid)263 board.add(network.displayName, "p2pkh", "sighash-byte-of-the-coin", ok: scheme == .bip143ForkID ? type.hasForkID : !type.hasForkID, id: txid)264 // a digest over another amount: valid on Dogecoin and Litecoin (the original digest ignores it), invalid on Bitcoin Cash265 let other = try? BitcoinSighash.digest(scheme: scheme, isWitness: false, transaction: tx, inputIndex: i, scriptCode: spent[i].scriptPubKey,266 value: spent[i].value &+ 1, type: type)267 board.add(network.displayName, "p2pkh", "amount-commitment", ok: (other == digest) == (scheme != .bip143ForkID), id: txid)268 }269 // the same signature under a wrong amount, and under the other coins' rules270 var wrongAmount = spent[i]271 wrongAmount.value &+= 1272 let stillValid = (try? BitcoinVerifier.verifyInput(transaction: tx, inputIndex: i, spentOutput: wrongAmount, scheme: scheme)) != nil273 let commits = scheme == .bip143ForkID || BitcoinScript.witnessProgram(of: spent[i].scriptPubKey) != nil274 board.add(network.displayName, t.str("inputKind"), "wrong-amount", ok: stillValid == !commits, id: txid)275 for otherScheme in UTXOSighashScheme.allCases where otherScheme != scheme {276 let segwit = BitcoinScript.witnessProgram(of: spent[i].scriptPubKey) != nil277 if !segwit, Set([otherScheme, scheme]) == [.bip143, .legacy] { continue }278 let valid = (try? BitcoinVerifier.verifyInput(transaction: tx, inputIndex: i, spentOutput: spent[i], scheme: otherScheme)) != nil279 board.add(network.displayName, t.str("inputKind"), "invalid-under-another-scheme", ok: !valid, id: txid + " under " + otherScheme.rawValue)280 }281 var tampered = tx282 tampered.outputs[0].value ^= 1283 let tamperedValid = (try? BitcoinVerifier.verifyInput(transaction: tampered, inputIndex: i, spentOutput: spent[i], scheme: scheme)) != nil284 board.add(network.displayName, t.str("inputKind"), "changed-output-invalid", ok: !tamperedValid, id: txid)285 } catch BitcoinVerifier.Error.unsupportedSignature {286 // Schnorr on Bitcoin Cash: never reported as valid, never signed by the wallet287 c.schnorr += 1288 board.add(network.displayName, "p2pkh", "schnorr-reported-unsupported", ok: scheme == .bip143ForkID, id: txid)289 } catch {290 board.add(network.displayName, t.str("inputKind"), "signature-verifies", ok: false, id: txid + " input \(i): \(error)")291 }292 }293 }294 counts[name] = c295 }296 let all = counts.values297 #expect(all.reduce(0) { $0 + $1.transactions } == 28)298 #expect(counts["litecoin"]?.transactions == 12 && counts["dogecoin"]?.transactions == 8 && counts["bitcoinCash"]?.transactions == 8)299 #expect(all.reduce(0) { $0 + $1.ecdsaVerified + $1.schnorr } == all.reduce(0) { $0 + $1.inputs })300 #expect((counts["dogecoin"]?.ecdsaVerified ?? 0) >= 8 && (counts["litecoin"]?.ecdsaVerified ?? 0) >= 12)301 let summary = counts.sorted { $0.key < $1.key }.map { "\($0.key): \($0.value.transactions) transactions, \($0.value.previous) previous transactions, \($0.value.inputs) inputs, \($0.value.ecdsaVerified) ECDSA signatures verified, \($0.value.schnorr) Schnorr (not verified by the engine), \($0.value.mwebSkipped) transactions not verified because an input spends an MWEB integrating transaction (flag 0x08, not parsed)" }302 print("UTXO-MAINNET-COUNTS " + summary.joined(separator: " | "))303 board.finish(minimum: 300, note: summary.joined(separator: "; "))304 }305306 // MARK: Chain constants307308 /// Address versions, key versions, coin types, identity blocks and policy constants, each against the value read309 /// in the reference client (source file and line in the comment; reference clients read on 2026-12-05).310 @Test func chainConstantsAgainstReferenceClients() {311 var board = Board(source: "reference clients: Litecoin Core v0.21.4 chainparams.cpp / policy.h / amount.h, Dogecoin Core v1.14.9 chainparams.cpp / policy.h / amount.h, Bitcoin Cash Node v29.2.0 chainparams.cpp, SLIP-0044")312 func check(_ name: String, _ ok: Bool) { board.add("chain constants", "", name, ok: ok, id: name) }313 // Litecoin Core chainparams.cpp: PUBKEY_ADDRESS 48, SCRIPT_ADDRESS 5 (former), SCRIPT_ADDRESS2 50, SECRET_KEY 176, bech32 "ltc"314 check("litecoin.p2pkh", BitcoinNetwork.litecoin.p2pkhVersion == 48)315 check("litecoin.p2sh", BitcoinNetwork.litecoin.p2shVersion == 50)316 check("litecoin.p2sh-former", BitcoinNetwork.litecoin.deprecatedP2SHVersion == 5)317 check("litecoin.wif", BitcoinNetwork.litecoin.wifVersion == 176)318 check("litecoin.hrp", BitcoinNetwork.litecoin.bech32HRP == "ltc")319 check("litecoin.genesis", BitcoinNetwork.litecoin.genesisHash == "12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2")320 // testnet: 111, 196 (former), 58, 239, "tltc"321 check("litecoin-testnet.p2pkh", BitcoinNetwork.litecoinTestnet.p2pkhVersion == 111)322 check("litecoin-testnet.p2sh", BitcoinNetwork.litecoinTestnet.p2shVersion == 58)323 check("litecoin-testnet.p2sh-former", BitcoinNetwork.litecoinTestnet.deprecatedP2SHVersion == 196)324 check("litecoin-testnet.wif", BitcoinNetwork.litecoinTestnet.wifVersion == 239)325 check("litecoin-testnet.hrp", BitcoinNetwork.litecoinTestnet.bech32HRP == "tltc")326 check("litecoin-testnet.genesis", BitcoinNetwork.litecoinTestnet.genesisHash == "4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0")327 // Litecoin Core: MAX_MONEY 84 000 000 COIN, DEFAULT_MIN_RELAY_TX_FEE 1000, DUST_RELAY_TX_FEE 30 000328 check("litecoin.max-money", BitcoinNetwork.litecoin.maximumMoney == 84_000_000 * 100_000_000)329 check("litecoin.fee-floor", BitcoinNetwork.litecoin.feePolicy.minimumFeeRatePerKiloVByte == 1_000)330 check("litecoin.dust", BitcoinNetwork.litecoin.feePolicy.dust == .relayFee(perKiloVByte: 30_000))331 // Dogecoin Core chainparams.cpp: 30, 22, 158; testnet 113, 196, 241332 check("dogecoin.p2pkh", BitcoinNetwork.dogecoin.p2pkhVersion == 30)333 check("dogecoin.p2sh", BitcoinNetwork.dogecoin.p2shVersion == 22)334 check("dogecoin.wif", BitcoinNetwork.dogecoin.wifVersion == 158)335 check("dogecoin.no-segwit", BitcoinNetwork.dogecoin.bech32HRP == nil && BitcoinNetwork.dogecoin.cashAddrPrefix == nil)336 check("dogecoin.genesis", BitcoinNetwork.dogecoin.genesisHash == "1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691")337 check("dogecoin-testnet.p2pkh", BitcoinNetwork.dogecoinTestnet.p2pkhVersion == 113)338 check("dogecoin-testnet.p2sh", BitcoinNetwork.dogecoinTestnet.p2shVersion == 196)339 check("dogecoin-testnet.wif", BitcoinNetwork.dogecoinTestnet.wifVersion == 241)340 check("dogecoin-testnet.genesis", BitcoinNetwork.dogecoinTestnet.genesisHash == "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e")341 // Dogecoin Core: MAX_MONEY 10 000 000 000 COIN; RECOMMENDED_MIN_TX_FEE = COIN / 100 per kB (wallet default and342 // DEFAULT_DUST_LIMIT, the soft dust limit); DEFAULT_MIN_RELAY_TX_FEE and DEFAULT_HARD_DUST_LIMIT one tenth of it343 check("dogecoin.max-money", BitcoinNetwork.dogecoin.maximumMoney == 10_000_000_000 * 100_000_000)344 check("dogecoin.fee-floor-is-the-recommended-fee", BitcoinNetwork.dogecoin.feePolicy.minimumFeeRatePerKiloVByte == 100_000_000 / 100)345 check("dogecoin.dust-is-the-soft-limit", BitcoinNetwork.dogecoin.feePolicy.dust == .fixed(100_000_000 / 100))346 // Bitcoin Cash Node chainparams.cpp: 0, 5, 128, "bitcoincash"; testnet4 111, 196, 239, "bchtest"; checkpoints347 check("bitcoin-cash.p2pkh", BitcoinNetwork.bitcoinCash.p2pkhVersion == 0)348 check("bitcoin-cash.p2sh", BitcoinNetwork.bitcoinCash.p2shVersion == 5)349 check("bitcoin-cash.wif", BitcoinNetwork.bitcoinCash.wifVersion == 128)350 check("bitcoin-cash.prefix", BitcoinNetwork.bitcoinCash.cashAddrPrefix == "bitcoincash" && BitcoinNetwork.bitcoinCash.bech32HRP == nil)351 check("bitcoin-cash-testnet.p2pkh", BitcoinNetwork.bitcoinCashTestnet.p2pkhVersion == 111)352 check("bitcoin-cash-testnet.p2sh", BitcoinNetwork.bitcoinCashTestnet.p2shVersion == 196)353 check("bitcoin-cash-testnet.wif", BitcoinNetwork.bitcoinCashTestnet.wifVersion == 239)354 check("bitcoin-cash-testnet.prefix", BitcoinNetwork.bitcoinCashTestnet.cashAddrPrefix == "bchtest")355 // identity blocks: checkpoint 661648 of Bitcoin Cash Node (first block after the split of 2020-11-15); the356 // same hash on blockbook.bch.zelcore.io, api.bitcore.io and api.haskoin.com, and another one on Bitcoin357 // (mempool.space) at that height; testnet4 block 200000 on api.bitcore.io and api.haskoin.com358 check("bitcoin-cash.identity", BitcoinNetwork.bitcoinCash.identityBlock == UTXOChainIdentity(height: 661_648, hash: "0000000000000000029e471c41818d24b8b74c911071c4ef0b4a0509f9b5a8ce"))359 check("bitcoin-cash.identity-is-not-the-genesis", BitcoinNetwork.bitcoinCash.genesisHash == BitcoinNetwork.mainnet.genesisHash && BitcoinNetwork.bitcoinCash.identityBlock.height > 556_766)360 check("bitcoin-cash-testnet.identity", BitcoinNetwork.bitcoinCashTestnet.identityBlock == UTXOChainIdentity(height: 200_000, hash: "00000000071ca109d9e44e26c1510922d2913ead12e8d2bd86d7bc7577806d7b"))361 check("bitcoin-cash-testnet.genesis", BitcoinNetwork.bitcoinCashTestnet.genesisHash == "000000001dd410c49a788668ce26751718cc797474d3152a5fc073dd44fd9f7b")362 check("bitcoin-cash.max-money", BitcoinNetwork.bitcoinCash.maximumMoney == 21_000_000 * 100_000_000)363 check("bitcoin-cash.dust", BitcoinNetwork.bitcoinCash.feePolicy.dust == .fixed(546))364 for n in [BitcoinNetwork.litecoin, .litecoinTestnet, .dogecoin, .dogecoinTestnet] { check("\(n.rawValue).identity-is-genesis", n.identityBlock == UTXOChainIdentity(height: 0, hash: n.genesisHash)) }365 // SLIP-0044 coin types: 2 Litecoin, 3 Dogecoin, 145 Bitcoin Cash, 1 every test network366 check("coin-types", BitcoinNetwork.litecoin.coinType == 2 && BitcoinNetwork.dogecoin.coinType == 3 && BitcoinNetwork.bitcoinCash.coinType == 145)367 check("coin-types-testnets", [BitcoinNetwork.litecoinTestnet, .dogecoinTestnet, .bitcoinCashTestnet].allSatisfy { $0.coinType == 1 })368 // signature schemes and what follows from them369 check("schemes", BitcoinNetwork.litecoin.sighashScheme == .bip143 && BitcoinNetwork.dogecoin.sighashScheme == .legacy && BitcoinNetwork.bitcoinCash.sighashScheme == .bip143ForkID)370 check("amount-commitment-flags", !BitcoinNetwork.dogecoin.signatureCommitsToAmounts && BitcoinNetwork.bitcoinCash.signatureCommitsToAmounts)371 check("fork-id-byte", BitcoinSighashType.allForkID.rawValue == 0x41 && BitcoinSighashType.forkIDFlag == 0x40)372 check("no-replace-by-fee-on-bitcoin-cash", !BitcoinNetwork.bitcoinCash.supportsRBF && BitcoinNetwork.dogecoin.supportsRBF && BitcoinNetwork.litecoin.supportsRBF)373 board.finish(minimum: 45)374 }375}376