Skip to content

Commit c4c0240

Browse files
committed
test: add regression tests for transaction_context_from_ffi validation
Addresses CodeRabbit review comment on PR #582 #582 (comment)
1 parent 5114330 commit c4c0240

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

key-wallet-ffi/src/types.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ impl FFIAccountType {
436436
mod tests {
437437
use super::*;
438438

439+
fn valid_block_info() -> FFIBlockInfo {
440+
FFIBlockInfo {
441+
height: 1000,
442+
block_hash: [0xab; 32],
443+
timestamp: 1700000000,
444+
}
445+
}
446+
439447
#[test]
440448
#[should_panic(expected = "DashpayReceivingFunds cannot be converted to AccountType")]
441449
fn test_dashpay_receiving_funds_to_account_type_panics() {
@@ -506,6 +514,57 @@ mod tests {
506514
assert_eq!(ffi_type, FFIAccountType::StandardBIP44);
507515
assert_eq!(index, 5);
508516
}
517+
518+
#[test]
519+
fn transaction_context_from_ffi_mempool_with_empty_block_info() {
520+
let result =
521+
transaction_context_from_ffi(FFITransactionContext::Mempool, &FFIBlockInfo::empty());
522+
assert!(matches!(result, Some(TransactionContext::Mempool)));
523+
}
524+
525+
#[test]
526+
fn transaction_context_from_ffi_instant_send_with_empty_block_info() {
527+
let result = transaction_context_from_ffi(
528+
FFITransactionContext::InstantSend,
529+
&FFIBlockInfo::empty(),
530+
);
531+
assert!(matches!(result, Some(TransactionContext::InstantSend)));
532+
}
533+
534+
#[test]
535+
fn transaction_context_from_ffi_in_block_with_empty_block_info() {
536+
let result =
537+
transaction_context_from_ffi(FFITransactionContext::InBlock, &FFIBlockInfo::empty());
538+
assert!(result.is_none());
539+
}
540+
541+
#[test]
542+
fn transaction_context_from_ffi_in_chain_locked_block_with_empty_block_info() {
543+
let result = transaction_context_from_ffi(
544+
FFITransactionContext::InChainLockedBlock,
545+
&FFIBlockInfo::empty(),
546+
);
547+
assert!(result.is_none());
548+
}
549+
550+
#[test]
551+
fn transaction_context_from_ffi_in_block_with_valid_block_info() {
552+
let block_info = valid_block_info();
553+
let result = transaction_context_from_ffi(FFITransactionContext::InBlock, &block_info);
554+
let ctx = result.expect("should return Some for InBlock with valid block info");
555+
assert!(matches!(ctx, TransactionContext::InBlock(info) if info.height() == 1000));
556+
}
557+
558+
#[test]
559+
fn transaction_context_from_ffi_in_chain_locked_block_with_valid_block_info() {
560+
let block_info = valid_block_info();
561+
let result =
562+
transaction_context_from_ffi(FFITransactionContext::InChainLockedBlock, &block_info);
563+
let ctx = result.expect("should return Some for InChainLockedBlock with valid block info");
564+
assert!(
565+
matches!(ctx, TransactionContext::InChainLockedBlock(info) if info.height() == 1000)
566+
);
567+
}
509568
}
510569

511570
/// Address type enumeration

0 commit comments

Comments
 (0)