spb/os-vault Public
Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.
Swift 96%
Shell 3.4%
Makefile 0.6%
1//2// WalletCoreTests.swift3// OS Vault4//5// Author: Simon-Pierre Boucher6// Mail: contact@spboucher.ai7//89import XCTest10import WalletCore11import Web3Core12@testable import OSVaultKit1314final class WalletCoreTests: XCTestCase {1516 // Same public test vector as the rest of the suite.17 let vectorMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"1819 func testEthereumAddressMatchesWeb3swift() throws {20 // Cross-check the two independent secp256k1/BIP-32 stacks: wallet-core21 // must derive the exact address web3swift derives (and the BIP-44 vector).22 let hd = HDWallet(mnemonic: vectorMnemonic, passphrase: "")!23 XCTAssertEqual(hd.getAddressForCoin(coin: .ethereum),24 "0x9858EfFD232B4033E47d90003D41EC34EcaEda94")25 }2627 func testTronDerivationConsistentAcrossStacks() throws {28 // Derive the Tron key with web3swift's HD stack at m/44'/195'/0'/0/0,29 // feed the raw private key to wallet-core, and require the same30 // address wallet-core derives internally from the mnemonic.31 let hd = HDWallet(mnemonic: vectorMnemonic, passphrase: "")!32 let fromMnemonic = hd.getAddressForCoin(coin: .tron)3334 let seed = BIP39.seedFromMmemonics(vectorMnemonic, password: "", language: .english)!35 let node = HDNode(seed: seed)!.derive(path: "m/44'/195'/0'/0/0", derivePrivateKey: true)!36 let key = PrivateKey(data: node.privateKey!)!37 let fromRawKey = CoinType.tron.deriveAddress(privateKey: key)3839 XCTAssertEqual(fromMnemonic, fromRawKey)40 XCTAssertTrue(fromMnemonic.hasPrefix("T"))41 XCTAssertEqual(fromMnemonic.count, 34)42 }4344 func testXRPAndTONAddressesDerive() throws {45 let hd = HDWallet(mnemonic: vectorMnemonic, passphrase: "")!46 let xrp = hd.getAddressForCoin(coin: .xrp)47 XCTAssertTrue(xrp.hasPrefix("r"))48 let ton = hd.getAddressForCoin(coin: .ton)49 XCTAssertTrue(ton.hasPrefix("UQ") || ton.hasPrefix("EQ"))50 }5152 func testTronAddressValidation() {53 XCTAssertTrue(AnyAddress.isValid(string: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", coin: .tron))54 XCTAssertFalse(AnyAddress.isValid(string: "0x9858EfFD232B4033E47d90003D41EC34EcaEda94", coin: .tron))55 XCTAssertFalse(AnyAddress.isValid(string: "Tinvalid", coin: .tron))56 }57}5859final class XRPLTONTests: XCTestCase {6061 func testXRPLValidationAndAmounts() {62 XCTAssertTrue(XRPLService.validate(address: "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De"))63 XCTAssertFalse(XRPLService.validate(address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"))64 XCTAssertEqual(XRPLService.parseXRP("1"), 1_000_000)65 XCTAssertEqual(XRPLService.formatXRP(1_500_000), "1.5")66 XCTAssertEqual(XRPLService.validRLUSDAmount("12,5"), "12.5")67 XCTAssertNil(XRPLService.validRLUSDAmount("abc"))68 XCTAssertNil(XRPLService.validRLUSDAmount("0"))69 }7071 func testTONValidationAndAmounts() {72 XCTAssertTrue(TONService.validate(address: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"))73 XCTAssertFalse(TONService.validate(address: "not-a-ton-address"))74 XCTAssertEqual(TONService.parseTON("1"), 1_000_000_000)75 XCTAssertEqual(TONService.parseUSDT("2.5"), 2_500_000)76 XCTAssertEqual(TONService.formatTON(1_500_000_000), "1.5")77 }78}79