Skip to content

Commit

Permalink
fix delegation detection, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Jul 21, 2023
1 parent 78ee40b commit e7e3ade
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
14 changes: 7 additions & 7 deletions Sources/KukaiCoreSwift/Models/BakingBad/TzKTTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,20 @@ public struct TzKTTransaction: Codable, CustomStringConvertible, Hashable, Ident
self.entrypointCalled = entrypoint

} else {
if self.target?.address == currentWalletAddress {
if self.type == .delegation {
self.subType = .delegate

} else if self.type == .reveal {
self.subType = .reveal

} else if self.target?.address == currentWalletAddress {
self.subType = .receive
self.primaryToken = createPrimaryToken()

} else if self.target?.address != currentWalletAddress {
self.subType = .send
self.primaryToken = createPrimaryToken()

} else if self.type == .delegation {
self.subType = .delegate

} else if self.type == .reveal {
self.subType = .reveal

} else {
self.subType = .unknown
}
Expand Down
9 changes: 8 additions & 1 deletion Tests/KukaiCoreSwiftTests/Clients/TzKTClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TzKTClientTests: XCTestCase {
MockConstants.shared.tzktClient.fetchTransactions(forAddress: MockConstants.defaultHdWallet.address) { transactions in
let groups = MockConstants.shared.tzktClient.groupTransactions(transactions: transactions, currentWalletAddress: MockConstants.defaultHdWallet.address)

XCTAssert(groups.count == 16, "\(groups.count)")
XCTAssert(groups.count == 17, "\(groups.count)")

for (index, group) in groups.enumerated() {

Expand Down Expand Up @@ -207,6 +207,13 @@ class TzKTClientTests: XCTestCase {
XCTAssert(group.hash == "ooyKEQLPDHHD2K8ZJSt92braYAPcRjxxfEmXVcdAQ5X4AoRuREA", group.hash)
XCTAssert(group.entrypointCalled == "wrap", group.entrypointCalled ?? "-")

case 16:
XCTAssert(group.groupType == .delegate, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "onpirLfDfojh84pihNKmrNFZ14Uf8z2SHYBVikcaKfSRBFFFb25", group.hash)
XCTAssert(group.transactions.first?.prevDelegate?.alias == " Baking Benjamins", group.transactions.first?.prevDelegate?.alias ?? "-")
XCTAssert(group.transactions.first?.newDelegate?.alias == "ECAD Labs Baker", group.transactions.first?.newDelegate?.alias ?? "-")

default:
XCTFail("Missing test for transaction")
}
Expand Down
28 changes: 27 additions & 1 deletion Tests/KukaiCoreSwiftTests/Stubs/tzkt_transactions-main.json
Original file line number Diff line number Diff line change
Expand Up @@ -929,5 +929,31 @@
},
"status": "applied",
"hasInternals": true
}
},
{
"type": "delegation",
"id": 162385896669184,
"level": 2932791,
"timestamp": "2023-07-21T15:08:19Z",
"block": "BLGRuCdw6czoRQK9V3JJApDsCY9uctsQycgWx99jfKFV17wucB8",
"hash": "onpirLfDfojh84pihNKmrNFZ14Uf8z2SHYBVikcaKfSRBFFFb25",
"counter": 16355997,
"sender": {
"address": "tz1Ue76bLW7boAcJEZf2kSGcamdBKVi4Kpss"
},
"gasLimit": 194,
"gasUsed": 169,
"storageLimit": 0,
"bakerFee": 281,
"amount": 4144650,
"prevDelegate": {
"alias": " Baking Benjamins",
"address": "tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD"
},
"newDelegate": {
"alias": "ECAD Labs Baker",
"address": "tz1RuHDSj9P7mNNhfKxsyLGRDahTX5QD1DdP"
},
"status": "applied"
},
]

0 comments on commit e7e3ade

Please sign in to comment.