You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A simple transaction hex (mainnet coinbase transaction)
1049
+
let tx_hex = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000";
1050
+
1051
+
// Test successful parsing
1052
+
let tx = Transaction::from_string(tx_hex.to_string()).unwrap();
1053
+
1054
+
// Verify the transaction was parsed correctly
1055
+
assert_eq!(tx.version(),1);
1056
+
assert_eq!(tx.input().len(),1);
1057
+
assert_eq!(tx.output().len(),1);
1058
+
assert!(tx.is_coinbase());
1059
+
1060
+
// Test that serializing and re-parsing gives the same result
1061
+
let serialized = tx.serialize();
1062
+
let tx2 = Transaction::new(serialized).unwrap();
1063
+
assert_eq!(
1064
+
tx.compute_txid().to_string(),
1065
+
tx2.compute_txid().to_string()
1066
+
);
1067
+
1068
+
// Test invalid hex string
1069
+
let invalid_hex = "invalid_hex_string";
1070
+
let result = Transaction::from_string(invalid_hex.to_string());
1071
+
assert!(result.is_err());
1072
+
match result.unwrap_err(){
1073
+
TransactionError::InvalidHexString => {}
1074
+
_ => panic!("Expected InvalidHexString error"),
1075
+
}
1076
+
1077
+
// Test hex string with invalid transaction data
1078
+
let invalid_tx_hex = "deadbeef";
1079
+
let result = Transaction::from_string(invalid_tx_hex.to_string());
0 commit comments