Skip to content

Commit

Permalink
Add PrimitivesTestKit, StoreTestKit
Browse files Browse the repository at this point in the history
  • Loading branch information
gemcoder21 committed Jun 6, 2024
1 parent 9f21980 commit 8685a3d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Packages/Keystore/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ let package = Package(
),
.testTarget(
name: "KeystoreTests",
dependencies: ["Keystore"]),
dependencies: [
"Keystore",
.product(name: "PrimitivesTestKit", package: "Primitives"),
]),
]
)
11 changes: 7 additions & 4 deletions Packages/Keystore/Tests/KeystoreTests/Chain+KeystoreTests.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright (c). Gem Wallet. All rights reserved.

import XCTest
import Primitives
import PrimitivesTestKit

final class Chain_KeystoreTests: XCTestCase {

func testIsValidAddress() {
XCTAssertTrue(Chain.ethereum.isValidAddress("0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5"))
XCTAssertTrue(Chain.ethereum.isValidAddress("0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5"))
XCTAssertTrue(Chain.mock(.ethereum).isValidAddress("0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5"))
XCTAssertTrue(Chain.mock(.ethereum).isValidAddress("0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5"))

XCTAssertFalse(Chain.ethereum.isValidAddress("0x123"))
XCTAssertFalse(Chain.ethereum.isValidAddress("0x123"))
XCTAssertFalse(Chain.mock(.ethereum).isValidAddress("0x123"))
XCTAssertFalse(Chain.mock(.ethereum).isValidAddress("0x123"))
}
}
17 changes: 13 additions & 4 deletions Packages/Primitives/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ let package = Package(
name: "Primitives",
platforms: [.iOS(.v17), .macOS(.v12)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Primitives",
targets: ["Primitives"]),
.library(
name: "PrimitivesTestKit",
targets: ["PrimitivesTestKit"]),
],
dependencies: [
.package(url: "https://github.com/gemwalletcom/BigInt.git", exact: Version(5, 3, 0)),
.package(name: "Gemstone", path: "../Gemstone"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Primitives",
dependencies: [
Expand All @@ -27,8 +27,17 @@ let package = Package(
],
path: "Sources"
),
.target(
name: "PrimitivesTestKit",
dependencies: [
"Primitives",
],
path: "TestKit"
),
.testTarget(
name: "PrimitivesTests",
dependencies: ["Primitives"]),
dependencies: [
"Primitives",
]),
]
)
12 changes: 12 additions & 0 deletions Packages/Primitives/TestKit/Chain+Primitives.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import Primitives

public extension Chain {
static func mock(
_ chain: Chain = Chain.bitcoin
) -> Chain {
chain
}
}
16 changes: 16 additions & 0 deletions Packages/Primitives/TestKit/Wallet+Primitives.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import Primitives

//public extension Wallet {
// static func mock() -> Wallet {
// Wallet(
// id: <#T##String#>,
// name: <#T##String#>,
// index: <#T##Int32#>,
// type: <#T##WalletType#>,
// accounts: <#T##[Account]#>
// )
// }
//}
16 changes: 15 additions & 1 deletion Packages/Store/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ let package = Package(
name: "Store",
targets: ["Store"]
),
.library(
name: "StoreTestKit",
targets: ["StoreTestKit"]),
],
dependencies: [
.package(name: "Primitives", path: "../Primitives"),
Expand All @@ -32,9 +35,20 @@ let package = Package(
],
path: "Sources"
),
.target(
name: "StoreTestKit",
dependencies: [
"Store",
],
path: "TestKit"
),
.testTarget(
name: "StoreTests",
dependencies: ["Store"]
dependencies: [
"Store",
"StoreTestKit",
//.product(name: "StoreKit", package: "Store"),
]
),
]
)
12 changes: 12 additions & 0 deletions Packages/Store/TestKit/PreferencesStore+Store.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import Store

public extension PreferencesStore {
static func mock(
defaults: UserDefaults = .mock()
) -> PreferencesStore {
PreferencesStore(defaults: defaults)
}
}
12 changes: 12 additions & 0 deletions Packages/Store/TestKit/UserDefaults+Store.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import Store

public extension UserDefaults {
static func mock(
suiteName: String = UUID().uuidString
) -> UserDefaults {
UserDefaults(suiteName: suiteName)!
}
}
8 changes: 4 additions & 4 deletions Packages/Store/Tests/StoreTests/StoreTests.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c). Gem Wallet. All rights reserved.

import XCTest
@testable import Store
import StoreTestKit

final class StoreTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
//XCTAssertEqual(Store().text, "Hello, World!")
XCTAssertNotNil(PreferencesStore.mock())
}
}

0 comments on commit 8685a3d

Please sign in to comment.