SPB Git

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.8 KB · 43 lines swift
Raw Blame History
1//2//  SolanaTests.swift3//  OS Vault4//5//  Author: Simon-Pierre Boucher6//  Mail: contact@spboucher.ai7//89import XCTest10import SolanaSwift11@testable import OSVaultKit1213final class SolanaTests: XCTestCase {1415    // Public BIP-44 test vector: the all-"abandon" mnemonic at16    // m/44'/501'/0'/0' (bip44Change) — the Phantom/Solflare default.17    let vectorMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"1819    func testDerivationIsDeterministicAndPhantomPath() async throws {20        let first = try await SolanaService.deriveKeyPair(mnemonic: vectorMnemonic, network: .mainnet)21        let second = try await SolanaService.deriveKeyPair(mnemonic: vectorMnemonic, network: .devnet)22        // Cluster must not change the derivation; the keypair is path-only.23        XCTAssertEqual(first.publicKey.base58EncodedString, second.publicKey.base58EncodedString)24        XCTAssertEqual(first.secretKey.count, 64)25        XCTAssertTrue(SolanaService.validate(address: first.publicKey.base58EncodedString))26    }2728    func testAddressValidation() {29        XCTAssertTrue(SolanaService.validate(address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"))30        XCTAssertFalse(SolanaService.validate(address: "0x9858EfFD232B4033E47d90003D41EC34EcaEda94"))31        XCTAssertFalse(SolanaService.validate(address: "not-an-address"))32        XCTAssertFalse(SolanaService.validate(address: ""))33    }3435    func testAmountParsing() {36        XCTAssertEqual(SolanaService.parseSOL("1"), 1_000_000_000)37        XCTAssertEqual(SolanaService.parseSOL("0.000000001"), 1)38        XCTAssertNil(SolanaService.parseSOL("0.0000000001"))     // sub-lamport39        XCTAssertEqual(SolanaService.parseUSDC("12.5"), 12_500_000)40        XCTAssertEqual(SolanaService.formatSOL(1_500_000_000), "1.5")41    }42}43