Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions xrpl_api/src/api/account_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,40 @@ impl WithResponsePagination for AccountTxResponse {
&self.pagination
}
}

// BASELINE: test that AccountTxResponse fails when any transaction has unknown type — see issue #41
#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_account_tx_response_fails_on_unknown_transaction_type() {
// A response with one known and one unknown transaction type.
// Currently FAILS — the Vec<AccountTransaction> cannot deserialize
// when any element contains an unknown TransactionType.
let json = r#"{
"account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"ledger_index_min": 1,
"ledger_index_max": 100,
"validated": true,
"transactions": [
{
"meta": {
"AffectedNodes": [],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
},
"validated": true,
"tx": {
"TransactionType": "OracleSet",
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"Fee": "12",
"Sequence": 1
}
}
]
}"#;
// After fix: this should succeed — OracleSet deserializes as Transaction::OracleSet(...)
let _: AccountTxResponse = serde_json::from_str(json).unwrap();
}
}
15 changes: 15 additions & 0 deletions xrpl_api/src/api/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,19 @@ mod test {

let _tx_response: TxResponse = serde_json::from_str(json).unwrap();
}

// BASELINE: test that TxResponse fails when transaction has unknown type — see issue #41
#[test]
fn test_tx_response_fails_on_unknown_transaction_type() {
// Currently FAILS — TxResponse cannot deserialize unknown TransactionType
let json = r#"{
"validated": true,
"TransactionType": "AMMCreate",
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"Fee": "12",
"Sequence": 1
}"#;
// After fix: should deserialize as Transaction::AMMCreate(...)
let _: TxResponse = serde_json::from_str(json).unwrap();
}
}
34 changes: 34 additions & 0 deletions xrpl_api/src/events/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,37 @@ pub struct TransactionEvent {
#[serde(flatten)]
pub ledger_spec: ReturnLedgerSpec,
}

// BASELINE: test that TransactionEvent fails when transaction has unknown type — see issue #41
#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_transaction_event_fails_on_unknown_transaction_type() {
// This is the exact path described in issue #41 — subscribing to
// streams="transactions" and receiving an OracleSet event.
// Currently FAILS — TransactionEvent cannot deserialize unknown TransactionType.
let json = r#"{
"engine_result": "tesSUCCESS",
"engine_result_code": 0,
"engine_result_message": "The transaction was applied.",
"meta": {
"AffectedNodes": [],
"TransactionIndex": 0,
"TransactionResult": "tesSUCCESS"
},
"transaction": {
"TransactionType": "OracleSet",
"Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"Fee": "12",
"Sequence": 1
},
"ledger_hash": "abc123",
"ledger_index": 1000,
"validated": true
}"#;
// After fix: should deserialize successfully
let _: TransactionEvent = serde_json::from_str(json).unwrap();
}
}
Loading