Skip to content

Commit

Permalink
bug fix: allow TzKTClient to parse token transfers that contain no tr…
Browse files Browse the repository at this point in the history
…ansactionId
  • Loading branch information
simonmcl committed Apr 2, 2024
1 parent fd99521 commit c47576c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public struct TzKTTokenTransfer: Codable {
public let to: TzKTAddress?
public let from: TzKTAddress?
public let amount: String
public let transactionId: Decimal
public let transactionId: Decimal?
public let originationId: Decimal?
public let mintingTool: String?

public func tokenAmount() -> TokenAmount {
Expand Down
44 changes: 26 additions & 18 deletions Tests/KukaiCoreSwiftTests/Clients/TzKTClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,72 +59,80 @@ 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 == 18, "\(groups.count)")
XCTAssert(groups.count == 19, "\(groups.count)")

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

switch index {
case 0:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "1030074601046021", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1PegvRtG4LTWGjNx8bswVEvqKNC1FBZBjL", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "40", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "TestFirstMCDao", group.primaryToken?.name ?? "-")

case 1:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "op3K5QH2Tho6sUJy54hyRDXaRa7p11AvoVfZDmT4gLojFFDGG6Y", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1CzVSa18hndYupV9NcXy3Qj7p8YFDZKVQv", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "1", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Wood Mooncake", group.primaryToken?.name ?? "-")

case 1:
case 2:
XCTAssert(group.groupType == .contractCall, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "op3K5QH2Tho6sUJy54hyRDXaRa7p11AvoVfZDmT4gLojFFDGG6Y", group.hash)
XCTAssert(group.entrypointCalled == "claim", group.entrypointCalled ?? "-")

case 2:
case 3:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "opRQnyqN4fogpRSBCuxFpCm9SGooy1QY3r5Xc4FXre33tNFWh97", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1CzVSa18hndYupV9NcXy3Qj7p8YFDZKVQv", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "1", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Wood Mooncake", group.primaryToken?.name ?? "-")

case 3:
case 4:
XCTAssert(group.groupType == .contractCall, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "opRQnyqN4fogpRSBCuxFpCm9SGooy1QY3r5Xc4FXre33tNFWh97", group.hash)
XCTAssert(group.entrypointCalled == "claim", group.entrypointCalled ?? "-")

case 4:
case 5:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "oopQFnCyS9fPYeBftynXH6coUUAy4UPBuA3Hcp8nsApYNKxVuRx", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == nil, group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "0.5", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Tezos", group.primaryToken?.name ?? "-")

case 5:
case 6:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "onjmwjKLUPVpguDVYSZp2yh1tqGPp5oEgAjSbiFvxv74XsmMarg", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1914CUZ7EegAFPbfgQMRkw8Uz5mYkEz2ui", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "228.9299288", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Crunchy.Network CRNCHY", group.primaryToken?.name ?? "-")

case 6:
case 7:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "onjmwjKLUPVpguDVYSZp2yh1tqGPp5oEgAjSbiFvxv74XsmMarg", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == nil, group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "0.102422", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Tezos", group.primaryToken?.name ?? "-")

case 7:
case 8:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "onjmwjKLUPVpguDVYSZp2yh1tqGPp5oEgAjSbiFvxv74XsmMarg", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1KPoyzkj82Sbnafm6pfesZKEhyCpXwQfMc", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "3.160106", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "fDAO", group.primaryToken?.name ?? "-")

case 8:
case 9:
XCTAssert(group.groupType == .contractCall, group.groupType.rawValue)
XCTAssert(group.transactions.count == 7, group.transactions.count.description)
XCTAssert(group.hash == "onjmwjKLUPVpguDVYSZp2yh1tqGPp5oEgAjSbiFvxv74XsmMarg", group.hash)
Expand Down Expand Up @@ -155,66 +163,66 @@ class TzKTClientTests: XCTestCase {
XCTAssert(group.transactions[6].subType == .contractCall, group.transactions[6].subType?.rawValue ?? "-")
XCTAssert(group.transactions[6].entrypointCalled == "tezToTokenPayment", group.transactions[6].entrypointCalled ?? "-")

case 9:
case 10:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "onqrPbMuVZy6dDELwhXfdF8BbANXy5mLj47gjAf7CE5cAUvSVoQ", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1U6EHmNxJTkvaWJ4ThczG4FSDaHC21ssvi", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "1", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Unknown Token", group.primaryToken?.name ?? "-")

case 10:
case 11:
XCTAssert(group.groupType == .contractCall, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "onqrPbMuVZy6dDELwhXfdF8BbANXy5mLj47gjAf7CE5cAUvSVoQ", group.hash)
XCTAssert(group.entrypointCalled == "mint", group.entrypointCalled ?? "-")

case 11:
case 12:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "589699422879746", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1BRADdqGk2eLmMqvyWzqVmPQ1RCBCbW5dY", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "1", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "7/23 McLaren F1 Collectible", group.primaryToken?.name ?? "-")

case 12:
case 13:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "579854610202626", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1BRADdqGk2eLmMqvyWzqVmPQ1RCBCbW5dY", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "1", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "6/23 McLaren F1 Collectible", group.primaryToken?.name ?? "-")

case 13:
case 14:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "566013445799938", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1JBNFcB5tiycHNdYGYCtR3kk6JaJysUCi8", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "0", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "Lugh Euro pegged stablecoin", group.primaryToken?.name ?? "-")

case 14:
case 15:
XCTAssert(group.groupType == .receive, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "ooyKEQLPDHHD2K8ZJSt92braYAPcRjxxfEmXVcdAQ5X4AoRuREA", group.hash)
XCTAssert(group.primaryToken?.tokenContractAddress == "KT1JFjwQ25n58NZr5Bwy9chAxHCaPsjvh5xt", group.primaryToken?.tokenContractAddress ?? "-")
XCTAssert(group.primaryToken?.balance.normalisedRepresentation == "0.975223", group.primaryToken?.balance.normalisedRepresentation ?? "-")
XCTAssert(group.primaryToken?.name == "WTZ", group.primaryToken?.name ?? "-")

case 15:
case 16:
XCTAssert(group.groupType == .contractCall, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "ooyKEQLPDHHD2K8ZJSt92braYAPcRjxxfEmXVcdAQ5X4AoRuREA", group.hash)
XCTAssert(group.entrypointCalled == "wrap", group.entrypointCalled ?? "-")

case 16:
case 17:
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 ?? "-")

case 17:
case 18:
XCTAssert(group.groupType == .contractCall, group.groupType.rawValue)
XCTAssert(group.transactions.count == 1, group.transactions.count.description)
XCTAssert(group.hash == "opC815T6zqTUtzQktPBBeLAB1eRnvuR5ETZDoLPGgAb3698wwFK", group.hash)
Expand Down
27 changes: 27 additions & 0 deletions Tests/KukaiCoreSwiftTests/Stubs/tzkt_transactions-transfers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
[
{
"id": 1030074601046021,
"level": 5335465,
"timestamp": "2024-03-28T12:22:02Z",
"token": {
"id": 1030074601046017,
"contract": {
"address": "KT1PegvRtG4LTWGjNx8bswVEvqKNC1FBZBjL"
},
"tokenId": "0",
"standard": "fa2",
"totalSupply": "1000000000000",
"metadata": {
"name": "TestFirstMCDao",
"symbol": "KAI",
"decimals": "10",
"description": "Testing onchain voting",
"thumbnailUri": "https://kukai-embed-docs.pages.dev/img/logo.svg",
"shouldPreferSymbol": "true"
}
},
"to": {
"address": "tz1Ue76bLW7boAcJEZf2kSGcamdBKVi4Kpss"
},
"amount": "400000000000",
"originationId": 1030074601046016
},
{
"id": 619221159510017,
"level": 3717283,
"timestamp": "2023-06-16T11:28:11Z",
Expand Down

0 comments on commit c47576c

Please sign in to comment.