Skip to content

Commit

Permalink
- bug fix: encode transaction data as rpc decimals, as decoder is not…
Browse files Browse the repository at this point in the history
… expecting strings

- bug fix: populate transaction primary token, just in case
- update tests
  • Loading branch information
simonmcl committed Jun 18, 2024
1 parent d98a73a commit 8ad6dac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Sources/KukaiCoreSwift/Models/BakingBad/TzKTTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ public struct TzKTTransaction: Codable, CustomStringConvertible, Hashable, Ident
try container.encode(newDelegate, forKey: .newDelegate)
try container.encodeIfPresent(baker, forKey: .baker)
try container.encode(parameter, forKey: .parameter)
try container.encode(bakerFee.rpcRepresentation, forKey: .bakerFee)
try container.encode(storageFee.rpcRepresentation, forKey: .storageFee)
try container.encode(allocationFee.rpcRepresentation, forKey: .allocationFee)
try container.encode(amount.rpcRepresentation, forKey: .amount)
try container.encode(bakerFee.toRpcDecimal(), forKey: .bakerFee)
try container.encode(storageFee.toRpcDecimal(), forKey: .storageFee)
try container.encode(allocationFee.toRpcDecimal(), forKey: .allocationFee)
try container.encode(amount.toRpcDecimal(), forKey: .amount)
try container.encode(status.rawValue, forKey: .status)
try container.encode(hasInternals, forKey: .hasInternals)
try container.encode(tokenTransfersCount, forKey: .tokenTransfersCount)
Expand Down Expand Up @@ -343,9 +343,11 @@ public struct TzKTTransaction: Codable, CustomStringConvertible, Hashable, Ident

} else if self.kind == "stake" {
self.subType = .stake
self.primaryToken = createPrimaryToken()

} else if self.kind == "unstake" {
self.subType = .unstake
self.primaryToken = createPrimaryToken()

} else {
if self.type == .delegation {
Expand Down
2 changes: 2 additions & 0 deletions Tests/KukaiCoreSwiftTests/Clients/TzKTClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class TzKTClientTests: XCTestCase {
XCTAssert(group.groupType == .unstake, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.transactions.first?.amount.description == "1", group.transactions.first?.amount.description ?? "-")
XCTAssert(group.transactions.first?.primaryToken?.balance.description == "1", group.transactions.first?.primaryToken?.balance.description ?? "-")
XCTAssert(group.transactions.first?.baker?.address == "tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD", group.transactions.first?.baker?.address ?? "-")
XCTAssert(group.transactions.first?.baker?.alias == "Baking Benjamins", group.transactions.first?.baker?.alias ?? "-")
XCTAssert(group.hash == "ooyVR1r5vt3K4JGoVnH2XLQjwAVpoZaAkfdG1PssCPPovi7m1FL", group.hash)
Expand All @@ -241,6 +242,7 @@ class TzKTClientTests: XCTestCase {
XCTAssert(group.groupType == .stake, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.transactions.first?.amount.description == "10", group.transactions.first?.amount.description ?? "-")
XCTAssert(group.transactions.first?.primaryToken?.balance.description == "10", group.transactions.first?.primaryToken?.balance.description ?? "-")
XCTAssert(group.transactions.first?.baker?.address == "tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD", group.transactions.first?.baker?.address ?? "-")
XCTAssert(group.transactions.first?.baker?.alias == "Baking Benjamins", group.transactions.first?.baker?.alias ?? "-")
XCTAssert(group.hash == "opPGcuZ459ZGR11RXaL2rRDtKnHFC9o5JQdyBHj3Qua4BMBkAsi", group.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class TzKTTransactionTests: XCTestCase {
transaction.processAdditionalData(withCurrentWalletAddress: "tz1abc")

if let json = try? JSONEncoder().encode(transaction), let jsonString = String(data: json, encoding: .utf8) {
XCTAssert(jsonString.count == 952, jsonString.count.description)
XCTAssert(jsonString.count == 944, jsonString.count.description)
} else {
XCTFail()
}
Expand Down

0 comments on commit 8ad6dac

Please sign in to comment.