|
| 1 | +@testable import Bitkit |
| 2 | +import XCTest |
| 3 | + |
| 4 | +final class Bip21UtilsTests: XCTestCase { |
| 5 | + // MARK: - isDuplicatedBip21 Tests |
| 6 | + |
| 7 | + func testIsDuplicatedBip21_ReturnsFalseForSingleValidBIP21URI() { |
| 8 | + let input = "bitcoin:bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?amount=0.001&message=Bitkit" |
| 9 | + XCTAssertFalse(Bip21Utils.isDuplicatedBip21(input)) |
| 10 | + } |
| 11 | + |
| 12 | + func testIsDuplicatedBip21_ReturnsTrueWhenBIP21URIIsDuplicated() { |
| 13 | + let first = "bitcoin:bcrt1qr289x0fhg62672e8urudfnxnsr8tcax64xk2vk?amount=0.0000002&message=Bitkit" |
| 14 | + let second = "bitcoin:bcrt1qr289x0fhg62672e8urudfnxnsr8tcax64xk2vk?amount=0.0000003&message=Bitkit" |
| 15 | + let input = first + second |
| 16 | + XCTAssertTrue(Bip21Utils.isDuplicatedBip21(input)) |
| 17 | + } |
| 18 | + |
| 19 | + func testIsDuplicatedBip21_HandlesCaseInsensitiveBitcoinPrefix() { |
| 20 | + let first = "BITCOIN:bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?amount=0.001" |
| 21 | + let second = "bitcoin:bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?amount=0.002" |
| 22 | + let input = first + second |
| 23 | + XCTAssertTrue(Bip21Utils.isDuplicatedBip21(input)) |
| 24 | + } |
| 25 | + |
| 26 | + func testIsDuplicatedBip21_ReturnsFalseForNonBitcoinURIs() { |
| 27 | + let input = "lnbc500n1p3k9v3pp5kzmj..." |
| 28 | + XCTAssertFalse(Bip21Utils.isDuplicatedBip21(input)) |
| 29 | + } |
| 30 | + |
| 31 | + func testIsDuplicatedBip21_ReturnsFalseForEmptyString() { |
| 32 | + XCTAssertFalse(Bip21Utils.isDuplicatedBip21("")) |
| 33 | + } |
| 34 | + |
| 35 | + func testIsDuplicatedBip21_HandlesMixedCaseDuplicatedURIs() { |
| 36 | + let first = "Bitcoin:bc1qaddr1?amount=0.001" |
| 37 | + let second = "BITCOIN:bc1qaddr2?amount=0.002" |
| 38 | + let input = first + second |
| 39 | + XCTAssertTrue(Bip21Utils.isDuplicatedBip21(input)) |
| 40 | + } |
| 41 | + |
| 42 | + func testIsDuplicatedBip21_ReturnsFalseForPlainBitcoinAddress() { |
| 43 | + let input = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq" |
| 44 | + XCTAssertFalse(Bip21Utils.isDuplicatedBip21(input)) |
| 45 | + } |
| 46 | + |
| 47 | + func testIsDuplicatedBip21_ReturnsFalseForSingleBIP21WithLightningParam() { |
| 48 | + let input = "bitcoin:bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq?lightning=lnbc500n1p3k9v3pp5kzmj" |
| 49 | + XCTAssertFalse(Bip21Utils.isDuplicatedBip21(input)) |
| 50 | + } |
| 51 | +} |
0 commit comments