Skip to content

Commit

Permalink
- bug fix: 3route extractor for fa1.2 tokens
Browse files Browse the repository at this point in the history
- add new testcase + sample
  • Loading branch information
simonmcl committed Feb 16, 2024
1 parent da94dc7 commit 4e775b2
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/KukaiCoreSwift/Factories/OperationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public class OperationFactory {
*/
public static func tokenIdAndAmountFromApproveMichelson(michelson: Any) -> (rpcAmount: String, tokenId: Decimal?, destination: String)? {
if let michelsonDict = michelson as? [String: Any] {
let rpcAmountString = michelsonDict.michelsonArgsArray()?.michelsonInt(atIndex: 0)
let rpcAmountString = michelsonDict.michelsonArgsArray()?.michelsonInt(atIndex: 1)
let rpcDestinationString = michelsonDict.michelsonArgsArray()?.michelsonString(atIndex: 0) ?? ""

if let str = rpcAmountString {
Expand Down
11 changes: 11 additions & 0 deletions Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,17 @@ class OperationFactoryTests: XCTestCase {
XCTAssert(details2?.rpcAmount == "65639920011", details2?.rpcAmount ?? "-")
XCTAssert(details2?.tokenId == 0, details2?.tokenId?.description ?? "-")
XCTAssert(details2?.destination == "KT1V5XKmeypanMS9pR65REpqmVejWBZURuuT", details2?.destination ?? "-")


let fa1ForFa2Data = MockConstants.jsonStub(fromFilename: "3route-fa1-for-fa2")
let fa1ForFa2Json = (try? decoder.decode([OperationTransaction].self, from: fa1ForFa2Data)) ?? []
XCTAssert(fa1ForFa2Json.count > 0)

let details3 = OperationFactory.Extractor.firstNonZeroTokenTransferAmount(operations: fa1ForFa2Json)
XCTAssert(details3?.tokenContract == "KT1Ha4yFVeyzw6KRAdkzq6TxDHB97KG4pZe8", details3?.tokenContract ?? "-")
XCTAssert(details3?.rpcAmount == "400000", details3?.rpcAmount ?? "-")
XCTAssert(details3?.tokenId == nil, details3?.tokenId?.description ?? "-")
XCTAssert(details3?.destination == "KT1V5XKmeypanMS9pR65REpqmVejWBZURuuT", details3?.destination ?? "-")
}

func testExtractorsCrunchyStake() {
Expand Down
363 changes: 363 additions & 0 deletions Tests/KukaiCoreSwiftTests/Stubs/3route-fa1-for-fa2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,363 @@
[
{
"amount": "0",
"counter": "24122684",
"destination": "KT1Ha4yFVeyzw6KRAdkzq6TxDHB97KG4pZe8",
"fee": "0",
"gas_limit": "650000",
"kind": "transaction",
"parameters": {
"entrypoint": "approve",
"value": {
"args": [
{
"string": "KT1V5XKmeypanMS9pR65REpqmVejWBZURuuT"
},
{
"int": "0"
}
],
"prim": "Pair"
}
},
"source": "tz1Nzj8BKu3F6KhyaJYZXEfXkyN51HBNJixi",
"storage_limit": "60000"
},
{
"amount": "0",
"counter": "24122685",
"destination": "KT1Ha4yFVeyzw6KRAdkzq6TxDHB97KG4pZe8",
"fee": "0",
"gas_limit": "650000",
"kind": "transaction",
"parameters": {
"entrypoint": "approve",
"value": {
"args": [
{
"string": "KT1V5XKmeypanMS9pR65REpqmVejWBZURuuT"
},
{
"int": "400000"
}
],
"prim": "Pair"
}
},
"source": "tz1Nzj8BKu3F6KhyaJYZXEfXkyN51HBNJixi",
"storage_limit": "60000"
},
{
"amount": "0",
"counter": "24122686",
"destination": "KT1V5XKmeypanMS9pR65REpqmVejWBZURuuT",
"fee": "0",
"gas_limit": "650000",
"kind": "transaction",
"parameters": {
"entrypoint": "execute",
"value": {
"args": [
{
"int": "9"
},
{
"args": [
{
"int": "16"
},
{
"args": [
{
"int": "1228276"
},
{
"args": [
{
"string": "tz1Nzj8BKu3F6KhyaJYZXEfXkyN51HBNJixi"
},
{
"args": [
[
{
"args": [
{
"int": "0"
},
{
"args": [
{
"int": "246"
},
{
"args": [
{
"int": "0"
},
{
"args": [
{
"int": "196000"
},
{
"args": [
{
"int": "0"
},
{
"bytes": ""
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Elt"
},
{
"args": [
{
"int": "1"
},
{
"args": [
{
"int": "250"
},
{
"args": [
{
"int": "7"
},
{
"args": [
{
"int": "0"
},
{
"args": [
{
"int": "0"
},
{
"bytes": ""
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Elt"
},
{
"args": [
{
"int": "2"
},
{
"args": [
{
"int": "65"
},
{
"args": [
{
"int": "3"
},
{
"args": [
{
"int": "64000"
},
{
"args": [
{
"int": "0"
},
{
"bytes": ""
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Elt"
},
{
"args": [
{
"int": "3"
},
{
"args": [
{
"int": "18"
},
{
"args": [
{
"int": "7"
},
{
"args": [
{
"int": "0"
},
{
"args": [
{
"int": "0"
},
{
"bytes": ""
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Elt"
},
{
"args": [
{
"int": "4"
},
{
"args": [
{
"int": "308"
},
{
"args": [
{
"int": "2"
},
{
"args": [
{
"int": "140000"
},
{
"args": [
{
"int": "0"
},
{
"bytes": ""
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Elt"
},
{
"args": [
{
"int": "5"
},
{
"args": [
{
"int": "282"
},
{
"args": [
{
"int": "7"
},
{
"args": [
{
"int": "0"
},
{
"args": [
{
"int": "0"
},
{
"bytes": ""
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Elt"
}
],
{
"int": "0"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
],
"prim": "Pair"
}
},
"source": "tz1Nzj8BKu3F6KhyaJYZXEfXkyN51HBNJixi",
"storage_limit": "60000"
}
]

0 comments on commit 4e775b2

Please sign in to comment.