Skip to content

Commit

Permalink
[ANCHOR-843] Allow PENDING_EXTERNAL state even if funds are not recei…
Browse files Browse the repository at this point in the history
…ved in `notify_offchain_funds_received` method (#1535)

### Description

- Allow PENDING_EXTERNAL state even if funds are not received in
`notify_offchain_funds_received` method
  • Loading branch information
lijamie98 authored Oct 2, 2024
1 parent 2b077f0 commit a1b0edc
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ class PlatformApiTests : AbstractIntegrationTests(TestConfig()) {
)
}

/**
* 1. incomplete -> request_offchain_funds
* 2. pending_user_transfer_start -> notify_offchain_funds_sent
* 3. pending_user_transfer_start -> notify_offchain_funds_received
* 4. pending_anchor -> notify_onchain_funds_sent
* 5. completed
*/
@Test
fun `SEP-6 deposit with pending-external status`() {
`test sep6 deposit flow`(
SEP_6_DEPOSIT_WITH_PENDING_EXTERNAL_FLOW_ACTION_REQUESTS,
SEP_6_DEPOSIT_WITH_PENDING_EXTERNAL_FLOW_ACTION_RESPONSES
)
}

/**
* 1. incomplete -> request_offchain_funds
* 2. pending_user_transfer_start -> notify_offchain_funds_received
Expand Down Expand Up @@ -579,6 +594,73 @@ private val SEP_6_DEPOSIT_COMPLETE_SHORT_FLOW_ACTION_REQUESTS =
]
"""

private val SEP_6_DEPOSIT_WITH_PENDING_EXTERNAL_FLOW_ACTION_REQUESTS =
"""
[
{
"id": "1",
"method": "request_offchain_funds",
"jsonrpc": "2.0",
"params": {
"transaction_id": "%TX_ID%",
"message": "test message 1",
"amount_in": {
"amount": "100",
"asset": "iso4217:USD"
},
"amount_out": {
"amount": "95",
"asset": "stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
},
"amount_fee": {
"amount": "5",
"asset": "iso4217:USD"
},
"amount_expected": {
"amount": "100"
}
}
},
{
"id": "2",
"method": "notify_offchain_funds_sent",
"jsonrpc": "2.0",
"params": {
"transaction_id": "%TX_ID%",
"message": "test message 2",
"funds_sent_at": "2023-07-04T12:34:56Z",
"external_transaction_id": "ext-123456"
}
},
{
"id": "3",
"method": "notify_offchain_funds_received",
"jsonrpc": "2.0",
"params": {
"transaction_id": "%TX_ID%",
"message": "test message 2",
"funds_received_at": "2023-07-04T12:34:56Z",
"external_transaction_id": "ext-123456",
"amount_in": {
"amount": "100"
}
}
},
{
"id": "4",
"method": "notify_onchain_funds_sent",
"jsonrpc": "2.0",
"params": {
"transaction_id": "%TX_ID%",
"message": "test message 3",
"stellar_transaction_id": "%TESTPAYMENT_TXN_HASH%"
}
}
]
"""
.trimIndent()

private val SEP_6_DEPOSIT_COMPLETE_SHORT_FLOW_ACTION_RESPONSES =
"""
[
Expand Down Expand Up @@ -712,6 +794,151 @@ private val SEP_6_DEPOSIT_COMPLETE_SHORT_FLOW_ACTION_RESPONSES =
]
"""

private val SEP_6_DEPOSIT_WITH_PENDING_EXTERNAL_FLOW_ACTION_RESPONSES =
"""
[
{
"jsonrpc": "2.0",
"result": {
"id": "%TX_ID%",
"sep": "6",
"kind": "deposit",
"status": "pending_user_transfer_start",
"type": "SWIFT",
"amount_expected": {
"amount": "100",
"asset": "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP"
},
"amount_in": { "amount": "100", "asset": "iso4217:USD" },
"amount_out": {
"amount": "95",
"asset": "stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
},
"amount_fee": { "amount": "5", "asset": "iso4217:USD" },
"fee_details": { "total": "5", "asset": "iso4217:USD" },
"started_at": "2024-06-25T20:02:31.003419Z",
"updated_at": "2024-06-25T20:02:32.055853Z",
"message": "test message 1",
"destination_account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG",
"client_name": "referenceCustodial",
"customers": {
"sender": {
"account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
},
"receiver": {
"account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
}
}
},
"id": "1"
},
{
"jsonrpc": "2.0",
"result": {
"id": "%TX_ID%",
"sep": "6",
"kind": "deposit",
"status": "pending_external",
"type": "SWIFT"
},
"id": "2"
},
{
"jsonrpc": "2.0",
"result": {
"id": "%TX_ID%",
"sep": "6",
"kind": "deposit",
"status": "pending_anchor",
"type": "SWIFT",
"amount_expected": {
"amount": "100",
"asset": "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP"
},
"amount_in": { "amount": "100", "asset": "iso4217:USD" },
"amount_out": {
"amount": "95",
"asset": "stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
},
"amount_fee": { "amount": "5", "asset": "iso4217:USD" },
"fee_details": { "total": "5", "asset": "iso4217:USD" },
"started_at": "2024-06-25T20:02:31.003419Z",
"updated_at": "2024-06-25T20:02:33.085143Z",
"transfer_received_at": "2023-07-04T12:34:56Z",
"message": "test message 2",
"destination_account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG",
"external_transaction_id": "ext-123456",
"client_name": "referenceCustodial",
"customers": {
"sender": {
"account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
},
"receiver": {
"account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
}
}
},
"id": "3"
},
{
"jsonrpc": "2.0",
"result": {
"id": "%TX_ID%",
"sep": "6",
"kind": "deposit",
"status": "completed",
"type": "SWIFT",
"amount_expected": {
"amount": "100",
"asset": "stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP"
},
"amount_in": { "amount": "100", "asset": "iso4217:USD" },
"amount_out": {
"amount": "95",
"asset": "stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
},
"amount_fee": { "amount": "5", "asset": "iso4217:USD" },
"fee_details": { "total": "5", "asset": "iso4217:USD" },
"started_at": "2024-06-25T20:02:31.003419Z",
"updated_at": "2024-06-25T20:02:34.180861Z",
"completed_at": "2024-06-25T20:02:34.180858Z",
"transfer_received_at": "2023-07-04T12:34:56Z",
"message": "test message 3",
"stellar_transactions": [
{
"id": "%TESTPAYMENT_TXN_HASH%",
"payments": [
{
"id": "%TESTPAYMENT_ID%",
"amount": {
"amount": "%TESTPAYMENT_AMOUNT%",
"asset": "%TESTPAYMENT_ASSET_CIRCLE_USDC%"
},
"payment_type": "payment",
"source_account": "%TESTPAYMENT_SRC_ACCOUNT%",
"destination_account": "%TESTPAYMENT_DEST_ACCOUNT%"
}
]
}
],
"destination_account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG",
"external_transaction_id": "ext-123456",
"client_name": "referenceCustodial",
"customers": {
"sender": {
"account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
},
"receiver": {
"account": "GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"
}
}
},
"id": "4"
}
]
"""
.trimIndent()

private val SEP_6_DEPOSIT_EXCHANGE_COMPLETE_SHORT_FLOW_ACTION_RESPONSES =
"""
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,15 @@ protected Set<SepTransactionStatus> getSupportedStatuses(JdbcSepTransaction txn)
if (ImmutableSet.of(DEPOSIT, DEPOSIT_EXCHANGE).contains(Kind.from(txn6.getKind()))) {
supportedStatuses.add(PENDING_USR_TRANSFER_START);
supportedStatuses.add(ON_HOLD);
if (areFundsReceived(txn6)) {
supportedStatuses.add(PENDING_EXTERNAL);
}
supportedStatuses.add(PENDING_EXTERNAL);
}
break;
case SEP_24:
JdbcSep24Transaction txn24 = (JdbcSep24Transaction) txn;
if (DEPOSIT == Kind.from(txn24.getKind())) {
supportedStatuses.add(PENDING_USR_TRANSFER_START);
supportedStatuses.add(ON_HOLD);
if (areFundsReceived(txn24)) {
supportedStatuses.add(PENDING_EXTERNAL);
}
supportedStatuses.add(PENDING_EXTERNAL);
}
break;
default:
Expand Down

0 comments on commit a1b0edc

Please sign in to comment.