diff --git a/Sources/KukaiCoreSwift/Factories/OperationFactory.swift b/Sources/KukaiCoreSwift/Factories/OperationFactory.swift index 825a9b45..1a3d75d4 100644 --- a/Sources/KukaiCoreSwift/Factories/OperationFactory.swift +++ b/Sources/KukaiCoreSwift/Factories/OperationFactory.swift @@ -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 { diff --git a/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift b/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift index 7ba5e619..8a0cacac 100644 --- a/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift +++ b/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift @@ -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() { diff --git a/Tests/KukaiCoreSwiftTests/Stubs/3route-fa1-for-fa2.json b/Tests/KukaiCoreSwiftTests/Stubs/3route-fa1-for-fa2.json new file mode 100644 index 00000000..a35ec929 --- /dev/null +++ b/Tests/KukaiCoreSwiftTests/Stubs/3route-fa1-for-fa2.json @@ -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" + } +] \ No newline at end of file