Convert SatsPrice to a Skip multiplatform app

This commit is contained in:
2024-08-31 10:24:07 +03:00
parent 29650a3ea4
commit 7f22956557
101 changed files with 1379 additions and 1095 deletions

View File

@@ -0,0 +1,66 @@
// This is free software: you can redistribute and/or modify it
// under the terms of the GNU General Public License 3.0
// as published by the Free Software Foundation https://fsf.org
//
// SatsViewModelTests.swift
// SatsPriceTests
//
// Created by Terry Yiu on 2/19/24.
//
import XCTest
@testable import SatsPrice
final class SatsViewModelTests: XCTestCase {
func testSatsViewModel() {
let satsViewModel = SatsViewModel()
satsViewModel.btcToUsdString = "54321"
// Test BTC updates.
satsViewModel.btcString = "1"
XCTAssertEqual(satsViewModel.btc, Decimal(string: "1"))
XCTAssertEqual(satsViewModel.btcString, "1")
XCTAssertEqual(satsViewModel.sats, Decimal(string: "100000000"))
XCTAssertEqual(satsViewModel.satsString, "100000000")
XCTAssertEqual(satsViewModel.usd, Decimal(string: "54321"))
XCTAssertEqual(satsViewModel.usdString, "54321")
// Test Sats updates.
satsViewModel.satsString = "200000000"
XCTAssertEqual(satsViewModel.btc, Decimal(string: "2"))
XCTAssertEqual(satsViewModel.btcString, "2")
XCTAssertEqual(satsViewModel.sats, Decimal(string: "200000000"))
XCTAssertEqual(satsViewModel.satsString, "200000000")
XCTAssertEqual(satsViewModel.usd, Decimal(string: "108642"))
XCTAssertEqual(satsViewModel.usdString, "108642")
// Test USD updates.
satsViewModel.usdString = "162963"
XCTAssertEqual(satsViewModel.btc, Decimal(string: "3"))
XCTAssertEqual(satsViewModel.btcString, "3")
XCTAssertEqual(satsViewModel.sats, Decimal(string: "300000000"))
XCTAssertEqual(satsViewModel.satsString, "300000000")
XCTAssertEqual(satsViewModel.usd, Decimal(string: "162963"))
XCTAssertEqual(satsViewModel.usdString, "162963")
// Test fractional amounts.
satsViewModel.usdString = "1"
XCTAssertEqual(satsViewModel.btc, Decimal(string: "0.00001840908672520756245282671526665562"))
XCTAssertEqual(satsViewModel.btcString, "0.00001840908672520756245282671526665562")
XCTAssertEqual(satsViewModel.sats, Decimal(string: "1840.908672520756245282671526665562"))
XCTAssertEqual(satsViewModel.satsString, "1840.908672520756245282671526665562")
XCTAssertEqual(satsViewModel.usd, Decimal(string: "1"))
XCTAssertEqual(satsViewModel.usdString, "1")
// Test large amounts that exceed the cap of 21M BTC.
satsViewModel.usdString = "11407419999999"
XCTAssertEqual(satsViewModel.btc, Decimal(string: "210000184.09084884298889932070469983984"))
XCTAssertEqual(satsViewModel.btcString, "210000184.09084884298889932070469983984")
XCTAssertEqual(satsViewModel.sats, Decimal(string: "21000018409084884.298889932070469983984"))
XCTAssertEqual(satsViewModel.satsString, "21000018409084884.298889932070469983984")
XCTAssertEqual(satsViewModel.usd, Decimal(string: "11407419999999"))
XCTAssertEqual(satsViewModel.usdString, "11407419999999")
}
}

View File

@@ -0,0 +1,3 @@
# Configuration file for https://skip.tools project
#build:
# contents:

View File

@@ -0,0 +1,32 @@
// This is free software: you can redistribute and/or modify it
// under the terms of the GNU General Public License 3.0
// as published by the Free Software Foundation https://fsf.org
import Foundation
#if os(macOS) // Skip transpiled tests only run on macOS targets
import SkipTest
/// This test case will run the transpiled tests for the Skip module.
@available(macOS 13, macCatalyst 16, *)
final class XCSkipTests: XCTestCase, XCGradleHarness {
public func testSkipModule() async throws {
// Run the transpiled JUnit tests for the current test module.
// These tests will be executed locally using Robolectric.
// Connected device or emulator tests can be run by setting the
// `ANDROID_SERIAL` environment variable to an `adb devices`
// ID in the scheme's Run settings.
//
// Note that it isn't currently possible to filter the tests to run.
try await runGradleTests()
}
}
#endif
/// True when running in a transpiled Java runtime environment
let isJava = ProcessInfo.processInfo.environment["java.io.tmpdir"] != nil
/// True when running within an Android environment (either an emulator or device)
let isAndroid = isJava && ProcessInfo.processInfo.environment["ANDROID_ROOT"] != nil
/// True is the transpiled code is currently running in the local Robolectric test environment
let isRobolectric = isJava && !isAndroid
/// True if the system's `Int` type is 32-bit.
let is32BitInteger = Int64(Int.max) == Int64(Int32.max)