This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add balance struct and get balance client method - wip * update balanceData shape * mute tests * add getBalance test * bump tbdex spec * comment parse_offering test * add more tests
- Loading branch information
1 parent
3a8cd58
commit 6476eb1
Showing
10 changed files
with
233 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
public typealias Balance = Resource<BalanceData> | ||
|
||
/// Data that makes up a Balance Resource | ||
/// | ||
/// [Specification Reference](https://github.com/TBD54566975/tbdex/tree/main/specs/protocol#balance) | ||
public struct BalanceData: ResourceData { | ||
|
||
/// ISO 3166 currency code string | ||
public let currencyCode: String | ||
|
||
/// The amount available to be transacted with | ||
public let available: String | ||
|
||
/// Returns the ResourceKind of balance | ||
public func kind() -> ResourceKind { | ||
return .balance | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule tbdex-spec
updated
13 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Tests/tbDEXTests/Protocol/Models/Resources/BalanceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Web5 | ||
import XCTest | ||
|
||
@testable import tbDEX | ||
|
||
final class BalanceTests: XCTestCase { | ||
|
||
func _test_parseBalanceFromStringified() throws { | ||
if let balance = try parsedBalance(balance: balanceStringJSON) { | ||
XCTAssertEqual(balance.metadata.kind, ResourceKind.balance) | ||
} else { | ||
XCTFail("Balance is not a parsed balance") | ||
} | ||
} | ||
|
||
func _test_parseBalanceFromPrettified() throws { | ||
if let balance = try parsedBalance(balance: balancePrettyJSON) { | ||
XCTAssertEqual(balance.metadata.kind, ResourceKind.balance) | ||
} else { | ||
XCTFail("Balance is not a parsed balance") | ||
} | ||
} | ||
|
||
func _test_verifyBalanceIsValid() async throws { | ||
if let balance = try parsedBalance(balance: balancePrettyJSON) { | ||
XCTAssertNotNil(balance.signature) | ||
XCTAssertNotNil(balance.data) | ||
XCTAssertNotNil(balance.metadata) | ||
} else { | ||
XCTFail("Balance is not a parsed balance") | ||
} | ||
} | ||
|
||
private func parsedBalance(balance: String) throws -> Balance? { | ||
let parsedResource = try AnyResource.parse(balance) | ||
guard case let .balance(parsedBalance) = parsedResource else { | ||
return nil | ||
} | ||
return parsedBalance | ||
} | ||
|
||
let balancePrettyJSON = """ | ||
""" | ||
|
||
let balanceStringJSON = | ||
"" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters