From 3b35f291fe01e7aa92f2dc2b97e060415153bae4 Mon Sep 17 00:00:00 2001 From: Philip Liu <12836897+philipliu@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:46:12 -0400 Subject: [PATCH] Fix RequestOnchainFunds incorrect hash memo (#1447) ### Description This sets the `memo` value to the request `memo` value. ### Context `memo.toString()` returns the hex value of the memo but the `memo` in the Payment object is in Base64 format, so the observer will never find the transaction in the database. ### Testing - `./gradlew test` ### Documentation N/A ### Known limitations N/A --- .../rpc/RequestOnchainFundsHandler.java | 4 +- .../rpc/RequestOnchainFundsHandlerTest.kt | 85 +++++++++---------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/platform/src/main/java/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandler.java b/platform/src/main/java/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandler.java index f014279c9..c5568406f 100644 --- a/platform/src/main/java/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandler.java +++ b/platform/src/main/java/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandler.java @@ -252,7 +252,7 @@ protected void updateTransactionWithRpcRequest( if (sep6DepositInfoGenerator instanceof Sep6DepositInfoNoneGenerator) { Memo memo = makeMemo(request.getMemo(), request.getMemoType()); if (memo != null) { - txn6.setMemo(memo.toString()); + txn6.setMemo(request.getMemo()); txn6.setMemoType(memoTypeString(memoType(memo))); } txn6.setWithdrawAnchorAccount(request.getDestinationAccount()); @@ -286,7 +286,7 @@ protected void updateTransactionWithRpcRequest( if (sep24DepositInfoGenerator instanceof Sep24DepositInfoNoneGenerator) { Memo memo = makeMemo(request.getMemo(), request.getMemoType()); if (memo != null) { - txn24.setMemo(memo.toString()); + txn24.setMemo(request.getMemo()); txn24.setMemoType(memoTypeString(memoType(memo))); } txn24.setWithdrawAnchorAccount(request.getDestinationAccount()); diff --git a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandlerTest.kt b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandlerTest.kt index 29afb38d2..68c7d56d5 100644 --- a/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandlerTest.kt +++ b/platform/src/test/kotlin/org/stellar/anchor/platform/rpc/RequestOnchainFundsHandlerTest.kt @@ -65,7 +65,6 @@ class RequestOnchainFundsHandlerTest { private const val STELLAR_USDC_ISSUER = "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN" private const val TEXT_MEMO = "testMemo" - private const val TEXT_MEMO_2 = "testMemo2" private const val HASH_MEMO = "YWYwOTk2M2QtNzU3Mi00NGQ4LWE5MDktMmY2YzMzNTY=" private const val TEXT_MEMO_TYPE = "text" private const val HASH_MEMO_TYPE = "hash" @@ -558,8 +557,8 @@ class RequestOnchainFundsHandlerTest { .amountOut(AmountAssetRequest("0.9", FIAT_USD)) .feeDetails(Amount("0.1", STELLAR_USDC).toRate()) .amountExpected(AmountRequest("1")) - .memo(TEXT_MEMO) - .memoType(TEXT_MEMO_TYPE) + .memo(HASH_MEMO) + .memoType(HASH_MEMO_TYPE) .destinationAccount(DESTINATION_ACCOUNT) .build() val txn24 = JdbcSep24Transaction() @@ -603,8 +602,8 @@ class RequestOnchainFundsHandlerTest { expectedSep24Txn.amountFee = "0.1" expectedSep24Txn.amountFeeAsset = STELLAR_USDC expectedSep24Txn.amountExpected = "1" - expectedSep24Txn.memo = TEXT_MEMO - expectedSep24Txn.memoType = TEXT_MEMO_TYPE + expectedSep24Txn.memo = HASH_MEMO + expectedSep24Txn.memoType = HASH_MEMO_TYPE expectedSep24Txn.toAccount = DESTINATION_ACCOUNT expectedSep24Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT @@ -624,8 +623,8 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep24TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO - expectedResponse.memoType = TEXT_MEMO_TYPE + expectedResponse.memo = HASH_MEMO + expectedResponse.memoType = HASH_MEMO_TYPE expectedResponse.destinationAccount = DESTINATION_ACCOUNT JSONAssert.assertEquals( @@ -685,7 +684,7 @@ class RequestOnchainFundsHandlerTest { txn24.requestAssetIssuer = STELLAR_USDC_ISSUER val sep24TxnCapture = slot() val anchorEventCapture = slot() - val depositInfo = SepDepositInfo(DESTINATION_ACCOUNT_2, TEXT_MEMO_2, TEXT_MEMO_TYPE) + val depositInfo = SepDepositInfo(DESTINATION_ACCOUNT_2, TEXT_MEMO, TEXT_MEMO_TYPE) every { txn6Store.findByTransactionId(any()) } returns null every { txn24Store.findByTransactionId(TX_ID) } returns txn24 @@ -721,7 +720,7 @@ class RequestOnchainFundsHandlerTest { expectedSep24Txn.amountFee = "0.1" expectedSep24Txn.amountFeeAsset = STELLAR_USDC expectedSep24Txn.amountExpected = "1" - expectedSep24Txn.memo = TEXT_MEMO_2 + expectedSep24Txn.memo = TEXT_MEMO expectedSep24Txn.memoType = TEXT_MEMO_TYPE expectedSep24Txn.toAccount = DESTINATION_ACCOUNT_2 expectedSep24Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT_2 @@ -742,7 +741,7 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep24TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO_2 + expectedResponse.memo = TEXT_MEMO expectedResponse.memoType = TEXT_MEMO_TYPE expectedResponse.destinationAccount = DESTINATION_ACCOUNT_2 @@ -888,8 +887,8 @@ class RequestOnchainFundsHandlerTest { .amountIn(AmountAssetRequest("1", STELLAR_USDC)) .amountOut(AmountAssetRequest("0.9", FIAT_USD)) .amountFee(AmountAssetRequest("0.1", STELLAR_USDC)) - .memo(TEXT_MEMO) - .memoType(TEXT_MEMO_TYPE) + .memo(HASH_MEMO) + .memoType(HASH_MEMO_TYPE) .destinationAccount(DESTINATION_ACCOUNT) .userActionRequiredBy(actionRequiredBy) .build() @@ -933,8 +932,8 @@ class RequestOnchainFundsHandlerTest { expectedSep24Txn.amountFee = "0.1" expectedSep24Txn.amountFeeAsset = STELLAR_USDC expectedSep24Txn.amountExpected = "1" - expectedSep24Txn.memo = TEXT_MEMO - expectedSep24Txn.memoType = TEXT_MEMO_TYPE + expectedSep24Txn.memo = HASH_MEMO + expectedSep24Txn.memoType = HASH_MEMO_TYPE expectedSep24Txn.toAccount = DESTINATION_ACCOUNT expectedSep24Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT expectedSep24Txn.userActionRequiredBy = actionRequiredBy @@ -955,8 +954,8 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep24TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO - expectedResponse.memoType = TEXT_MEMO_TYPE + expectedResponse.memo = HASH_MEMO + expectedResponse.memoType = HASH_MEMO_TYPE expectedResponse.destinationAccount = DESTINATION_ACCOUNT expectedResponse.userActionRequiredBy = actionRequiredBy @@ -989,8 +988,8 @@ class RequestOnchainFundsHandlerTest { val request = RequestOnchainFundsRequest.builder() .transactionId(TX_ID) - .memo(TEXT_MEMO) - .memoType(TEXT_MEMO_TYPE) + .memo(HASH_MEMO) + .memoType(HASH_MEMO_TYPE) .destinationAccount(DESTINATION_ACCOUNT) .build() val txn24 = JdbcSep24Transaction() @@ -1040,8 +1039,8 @@ class RequestOnchainFundsHandlerTest { expectedSep24Txn.amountFee = "0.1" expectedSep24Txn.amountFeeAsset = STELLAR_USDC expectedSep24Txn.amountExpected = "1" - expectedSep24Txn.memo = TEXT_MEMO - expectedSep24Txn.memoType = TEXT_MEMO_TYPE + expectedSep24Txn.memo = HASH_MEMO + expectedSep24Txn.memoType = HASH_MEMO_TYPE expectedSep24Txn.toAccount = DESTINATION_ACCOUNT expectedSep24Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT @@ -1061,8 +1060,8 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep24TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO - expectedResponse.memoType = TEXT_MEMO_TYPE + expectedResponse.memo = HASH_MEMO + expectedResponse.memoType = HASH_MEMO_TYPE expectedResponse.destinationAccount = DESTINATION_ACCOUNT JSONAssert.assertEquals( @@ -1223,8 +1222,8 @@ class RequestOnchainFundsHandlerTest { .amountOut(AmountAssetRequest("0.9", FIAT_USD)) .feeDetails(Amount("0.1", STELLAR_USDC).toRate()) .amountExpected(AmountRequest("1")) - .memo(TEXT_MEMO) - .memoType(TEXT_MEMO_TYPE) + .memo(HASH_MEMO) + .memoType(HASH_MEMO_TYPE) .destinationAccount(DESTINATION_ACCOUNT) .build() val txn6 = JdbcSep6Transaction() @@ -1269,8 +1268,8 @@ class RequestOnchainFundsHandlerTest { expectedSep6Txn.amountFee = "0.1" expectedSep6Txn.amountFeeAsset = STELLAR_USDC expectedSep6Txn.amountExpected = "1" - expectedSep6Txn.memo = TEXT_MEMO - expectedSep6Txn.memoType = TEXT_MEMO_TYPE + expectedSep6Txn.memo = HASH_MEMO + expectedSep6Txn.memoType = HASH_MEMO_TYPE expectedSep6Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT JSONAssert.assertEquals( @@ -1295,8 +1294,8 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep6TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO - expectedResponse.memoType = TEXT_MEMO_TYPE + expectedResponse.memo = HASH_MEMO + expectedResponse.memoType = HASH_MEMO_TYPE expectedResponse.customers = Customers(StellarId(null, null, null), StellarId(null, null, null)) JSONAssert.assertEquals( @@ -1357,7 +1356,7 @@ class RequestOnchainFundsHandlerTest { txn6.requestAssetIssuer = STELLAR_USDC_ISSUER val sep6TxnCapture = slot() val anchorEventCapture = slot() - val depositInfo = SepDepositInfo(DESTINATION_ACCOUNT_2, TEXT_MEMO_2, TEXT_MEMO_TYPE) + val depositInfo = SepDepositInfo(DESTINATION_ACCOUNT_2, TEXT_MEMO, TEXT_MEMO_TYPE) every { txn6Store.findByTransactionId(TX_ID) } returns txn6 every { txn24Store.findByTransactionId(any()) } returns null @@ -1392,7 +1391,7 @@ class RequestOnchainFundsHandlerTest { expectedSep6Txn.amountFee = "0.1" expectedSep6Txn.amountFeeAsset = STELLAR_USDC expectedSep6Txn.amountExpected = "1" - expectedSep6Txn.memo = TEXT_MEMO_2 + expectedSep6Txn.memo = TEXT_MEMO expectedSep6Txn.memoType = TEXT_MEMO_TYPE expectedSep6Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT_2 @@ -1412,7 +1411,7 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep6TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO_2 + expectedResponse.memo = TEXT_MEMO expectedResponse.memoType = TEXT_MEMO_TYPE expectedResponse.customers = Customers(StellarId(null, null, null), StellarId(null, null, null)) @@ -1449,8 +1448,8 @@ class RequestOnchainFundsHandlerTest { .amountIn(AmountAssetRequest("1", STELLAR_USDC)) .amountOut(AmountAssetRequest("0.9", FIAT_USD)) .amountFee(AmountAssetRequest("0.1", STELLAR_USDC)) - .memo(TEXT_MEMO) - .memoType(TEXT_MEMO_TYPE) + .memo(HASH_MEMO) + .memoType(HASH_MEMO_TYPE) .destinationAccount(DESTINATION_ACCOUNT) .build() val txn6 = JdbcSep6Transaction() @@ -1490,8 +1489,8 @@ class RequestOnchainFundsHandlerTest { expectedSep6Txn.amountFee = "0.1" expectedSep6Txn.amountFeeAsset = STELLAR_USDC expectedSep6Txn.amountExpected = "1" - expectedSep6Txn.memo = TEXT_MEMO - expectedSep6Txn.memoType = TEXT_MEMO_TYPE + expectedSep6Txn.memo = HASH_MEMO + expectedSep6Txn.memoType = HASH_MEMO_TYPE expectedSep6Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT JSONAssert.assertEquals( @@ -1510,8 +1509,8 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = Amount("0.1", STELLAR_USDC).toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep6TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO - expectedResponse.memoType = TEXT_MEMO_TYPE + expectedResponse.memo = HASH_MEMO + expectedResponse.memoType = HASH_MEMO_TYPE expectedResponse.customers = Customers(StellarId(null, null, null), StellarId(null, null, null)) JSONAssert.assertEquals( @@ -1544,8 +1543,8 @@ class RequestOnchainFundsHandlerTest { val request = RequestOnchainFundsRequest.builder() .transactionId(TX_ID) - .memo(TEXT_MEMO) - .memoType(TEXT_MEMO_TYPE) + .memo(HASH_MEMO) + .memoType(HASH_MEMO_TYPE) .destinationAccount(DESTINATION_ACCOUNT) .build() val txn6 = JdbcSep6Transaction() @@ -1593,8 +1592,8 @@ class RequestOnchainFundsHandlerTest { expectedSep6Txn.amountFee = "0.1" expectedSep6Txn.amountFeeAsset = STELLAR_USDC expectedSep6Txn.amountExpected = "1" - expectedSep6Txn.memo = TEXT_MEMO - expectedSep6Txn.memoType = TEXT_MEMO_TYPE + expectedSep6Txn.memo = HASH_MEMO + expectedSep6Txn.memoType = HASH_MEMO_TYPE expectedSep6Txn.withdrawAnchorAccount = DESTINATION_ACCOUNT JSONAssert.assertEquals( @@ -1613,8 +1612,8 @@ class RequestOnchainFundsHandlerTest { expectedResponse.feeDetails = expectedResponse.amountFee.toRate() expectedResponse.amountExpected = Amount("1", STELLAR_USDC) expectedResponse.updatedAt = sep6TxnCapture.captured.updatedAt - expectedResponse.memo = TEXT_MEMO - expectedResponse.memoType = TEXT_MEMO_TYPE + expectedResponse.memo = HASH_MEMO + expectedResponse.memoType = HASH_MEMO_TYPE expectedResponse.customers = Customers(StellarId(null, null, null), StellarId(null, null, null)) JSONAssert.assertEquals(