Skip to content

Commit

Permalink
Make account services static
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Nov 18, 2024
1 parent f0daf83 commit 9742f80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Sources/XyoClient/Address/AccountServices.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public class AccountServices {
func getNamedAccount(name: String = "default") -> AccountInstance {
public static func getNamedAccount(name: String = "default") -> AccountInstance {
// let _ = removeFromKeychain(key: name)
if let existingAccount = getStoredAccount(name: name) {
return existingAccount
Expand All @@ -18,7 +18,7 @@ public class AccountServices {
}
}

private func getStoredAccount(name: String) -> AccountInstance? {
private static func getStoredAccount(name: String) -> AccountInstance? {
// Lookup previously saved private key if it exists
if let storedPrivateKeyString = getFromKeychain(key: name) {
if let parsedPrivateKeyData = Data.dataFrom(hexString: storedPrivateKeyString) {
Expand Down
11 changes: 3 additions & 8 deletions Tests/XyoClientTests/AccountServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,20 @@ class AccountServicesTests: XCTestCase {
]

func testGetNamedAccount_CreatesAndReturnsNewAccount_WhenNoExistingAccount() {

let accountServices = AccountServices()

// Act
let account = accountServices.getNamedAccount(name: "testAccount")
let account = AccountServices.getNamedAccount(name: "testAccount")

// Assert
XCTAssertNotNil(account)
XCTAssertNotNil(account.address)
}

func testGetNamedAccount_ReturnsExistingAccount_WhenAccountExists() {
let accountServices = AccountServices()

// Act
// Initial attempt create account
let accountA = accountServices.getNamedAccount(name: "testAccount")
let accountA = AccountServices.getNamedAccount(name: "testAccount")
// Subsequent ones retrieve account
let accountB = accountServices.getNamedAccount(name: "testAccount")
let accountB = AccountServices.getNamedAccount(name: "testAccount")

// Asserts
let addressA = accountA.address
Expand Down

0 comments on commit 9742f80

Please sign in to comment.