// // WalletCoreTests.swift // OS Vault // // Author: Simon-Pierre Boucher // Mail: contact@spboucher.ai // import XCTest import WalletCore import Web3Core @testable import OSVaultKit final class WalletCoreTests: XCTestCase { // Same public test vector as the rest of the suite. let vectorMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" func testEthereumAddressMatchesWeb3swift() throws { // Cross-check the two independent secp256k1/BIP-32 stacks: wallet-core // must derive the exact address web3swift derives (and the BIP-44 vector). let hd = HDWallet(mnemonic: vectorMnemonic, passphrase: "")! XCTAssertEqual(hd.getAddressForCoin(coin: .ethereum), "0x9858EfFD232B4033E47d90003D41EC34EcaEda94") } func testTronDerivationConsistentAcrossStacks() throws { // Derive the Tron key with web3swift's HD stack at m/44'/195'/0'/0/0, // feed the raw private key to wallet-core, and require the same // address wallet-core derives internally from the mnemonic. let hd = HDWallet(mnemonic: vectorMnemonic, passphrase: "")! let fromMnemonic = hd.getAddressForCoin(coin: .tron) let seed = BIP39.seedFromMmemonics(vectorMnemonic, password: "", language: .english)! let node = HDNode(seed: seed)!.derive(path: "m/44'/195'/0'/0/0", derivePrivateKey: true)! let key = PrivateKey(data: node.privateKey!)! let fromRawKey = CoinType.tron.deriveAddress(privateKey: key) XCTAssertEqual(fromMnemonic, fromRawKey) XCTAssertTrue(fromMnemonic.hasPrefix("T")) XCTAssertEqual(fromMnemonic.count, 34) } func testXRPAndTONAddressesDerive() throws { let hd = HDWallet(mnemonic: vectorMnemonic, passphrase: "")! let xrp = hd.getAddressForCoin(coin: .xrp) XCTAssertTrue(xrp.hasPrefix("r")) let ton = hd.getAddressForCoin(coin: .ton) XCTAssertTrue(ton.hasPrefix("UQ") || ton.hasPrefix("EQ")) } func testTronAddressValidation() { XCTAssertTrue(AnyAddress.isValid(string: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", coin: .tron)) XCTAssertFalse(AnyAddress.isValid(string: "0x9858EfFD232B4033E47d90003D41EC34EcaEda94", coin: .tron)) XCTAssertFalse(AnyAddress.isValid(string: "Tinvalid", coin: .tron)) } } final class XRPLTONTests: XCTestCase { func testXRPLValidationAndAmounts() { XCTAssertTrue(XRPLService.validate(address: "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De")) XCTAssertFalse(XRPLService.validate(address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t")) XCTAssertEqual(XRPLService.parseXRP("1"), 1_000_000) XCTAssertEqual(XRPLService.formatXRP(1_500_000), "1.5") XCTAssertEqual(XRPLService.validRLUSDAmount("12,5"), "12.5") XCTAssertNil(XRPLService.validRLUSDAmount("abc")) XCTAssertNil(XRPLService.validRLUSDAmount("0")) } func testTONValidationAndAmounts() { XCTAssertTrue(TONService.validate(address: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs")) XCTAssertFalse(TONService.validate(address: "not-a-ton-address")) XCTAssertEqual(TONService.parseTON("1"), 1_000_000_000) XCTAssertEqual(TONService.parseUSDT("2.5"), 2_500_000) XCTAssertEqual(TONService.formatTON(1_500_000_000), "1.5") } }