Skip to content

Commit f2508df

Browse files
committed
Add Paybis webhook test and minor cleanups
Add a unit test for mapping a completed Paybis webhook that includes a payout transaction_hash (crates/fiat/src/providers/paybis/mapper.rs). Remove the #[serde(rename_all = "camelCase")] attribute from PaybisPayout (crates/fiat/src/providers/paybis/models/webhook.rs). Tidy keccak test assertions formatting (crates/gem_hash/src/keccak.rs) and adjust import ordering in Sui preload tests to avoid warnings (crates/gem_sui/src/provider/preload.rs). These changes increase test coverage and perform small formatting/import cleanups.
1 parent 26cfbd8 commit f2508df

5 files changed

Lines changed: 50 additions & 10 deletions

File tree

crates/fiat/src/providers/paybis/mapper.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,28 @@ mod tests {
373373
assert_eq!(transaction.fiat_currency, Some("EUR".to_string()));
374374
}
375375

376+
#[test]
377+
fn test_map_process_webhook_completed_with_transaction_hash() {
378+
let data: serde_json::Value = serde_json::from_str(include_str!("../../../testdata/paybis/webhook_transaction_completed.json")).unwrap();
379+
380+
let result = map_process_webhook(data).unwrap();
381+
let FiatWebhook::Transaction(transaction) = result else {
382+
panic!("Expected FiatWebhook::Transaction variant");
383+
};
384+
385+
assert_eq!(
386+
transaction,
387+
FiatTransactionUpdate {
388+
transaction_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".to_string(),
389+
provider_transaction_id: Some("PBXXXXXXXXXXTXX".to_string()),
390+
status: FiatTransactionStatus::Complete,
391+
transaction_hash: Some("x".to_string()),
392+
fiat_amount: Some(50.0),
393+
fiat_currency: Some("USD".to_string()),
394+
}
395+
);
396+
}
397+
376398
#[test]
377399
fn test_verification_webhook_maps_to_none() {
378400
let data: serde_json::Value = serde_json::from_str(include_str!("../../../testdata/paybis/webhook_transaction_no_changes.json")).unwrap();

crates/fiat/src/providers/paybis/models/webhook.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub struct PaybisWebhookData {
1818
}
1919

2020
#[derive(Debug, Clone, Deserialize)]
21-
#[serde(rename_all = "camelCase")]
2221
pub struct PaybisPayout {
2322
pub transaction_hash: Option<String>,
2423
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"event": "TRANSACTION_STATUS_CHANGED",
3+
"data": {
4+
"partnerTransactionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
5+
"quote": {
6+
"quoteId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
7+
},
8+
"transaction": {
9+
"invoice": "PBXXXXXXXXXXTXX",
10+
"status": "completed",
11+
"flow": "buyCrypto"
12+
},
13+
"amountFrom": {
14+
"amount": "50.00",
15+
"currency": "USD"
16+
},
17+
"amountTo": {
18+
"amount": "0.1",
19+
"currency": "BTC"
20+
},
21+
"payout": {
22+
"transaction_hash": "x"
23+
}
24+
}
25+
}

crates/gem_hash/src/keccak.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ mod tests {
1010

1111
#[test]
1212
fn test_keccak256() {
13-
assert_eq!(
14-
hex::encode(keccak256(b"hello")),
15-
"1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"
16-
);
17-
assert_eq!(
18-
hex::encode(keccak256(b"")),
19-
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
20-
);
13+
assert_eq!(hex::encode(keccak256(b"hello")), "1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8");
14+
assert_eq!(hex::encode(keccak256(b"")), "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
2115
}
2216
}

crates/gem_sui/src/provider/preload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ impl<C: Client + Clone> SuiClient<C> {
109109
#[cfg(all(test, feature = "chain_integration_tests"))]
110110
mod chain_integration_tests {
111111
use super::*;
112+
use crate::models::SuiStakeStatus;
112113
use crate::provider::testkit::*;
113114
use base64::{Engine, engine::general_purpose};
114115
use chain_traits::ChainTransactionLoad;
115-
use crate::models::SuiStakeStatus;
116116
use primitives::{Asset, Chain, Delegation, FeePriority, StakeType, TransactionLoadInput};
117117

118118
#[tokio::test]

0 commit comments

Comments
 (0)