Skip to content

Commit

Permalink
add finalise unstake as a transaction type
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Jun 19, 2024
1 parent 8ad6dac commit 7342af3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/KukaiCoreSwift/Models/BakingBad/TzKTTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ public struct TzKTTransaction: Codable, CustomStringConvertible, Hashable, Ident
self.subType = .unstake
self.primaryToken = createPrimaryToken()

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

} else {
if self.type == .delegation {
self.subType = .delegate
Expand Down
12 changes: 11 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 == 21, "\(groups.count)")
XCTAssert(groups.count == 22, "\(groups.count)")

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

Expand Down Expand Up @@ -248,6 +248,16 @@ class TzKTClientTests: XCTestCase {
XCTAssert(group.hash == "opPGcuZ459ZGR11RXaL2rRDtKnHFC9o5JQdyBHj3Qua4BMBkAsi", group.hash)
XCTAssert(group.status == .applied, group.status.rawValue)

case 21:
XCTAssert(group.groupType == .finaliseUnstake, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.transactions.first?.amount.description == "400333", group.transactions.first?.amount.description ?? "-")
XCTAssert(group.transactions.first?.primaryToken?.balance.description == "400333", 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 == "onnkAJpSQ8SnLB94saCmtQdPge7gCyEwG6UuEW6KhGkbaQobFBu", group.hash)
XCTAssert(group.status == .applied, group.status.rawValue)

default:
XCTFail("Missing test for transaction")
}
Expand Down
25 changes: 25 additions & 0 deletions Tests/KukaiCoreSwiftTests/Stubs/tzkt_transactions-main.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,5 +1041,30 @@
"stakingUpdatesCount": 2,
"status": "applied",
"kind": "stake"
},
{
"type": "staking",
"id": 309694884216832,
"level": 1672988,
"timestamp": "2024-06-09T15:50:30Z",
"hash": "onnkAJpSQ8SnLB94saCmtQdPge7gCyEwG6UuEW6KhGkbaQobFBu",
"sender": {
"address": "tz1Ue76bLW7boAcJEZf2kSGcamdBKVi4Kpss"
},
"counter": 27926309,
"gasLimit": 1830,
"gasUsed": 1729,
"storageLimit": 0,
"bakerFee": 464,
"action": "finalize",
"requestedAmount": 0,
"amount": 400333000000,
"baker": {
"alias": "Baking Benjamins",
"address": "tz1YgDUQV2eXm8pUWNz3S5aWP86iFzNp4jnD"
},
"stakingUpdatesCount": 2,
"status": "applied",
"kind": "finalize"
}
]

0 comments on commit 7342af3

Please sign in to comment.