2025-11-19 14:28:18 +02:00
|
|
|
use crate::{ProgramDeploymentTransaction, error::NssaError};
|
2025-10-15 18:00:35 -03:00
|
|
|
|
|
|
|
|
impl ProgramDeploymentTransaction {
|
|
|
|
|
pub fn to_bytes(&self) -> Vec<u8> {
|
2025-11-25 09:40:46 +02:00
|
|
|
borsh::to_vec(&self).expect("Autoderived borsh serialization failure")
|
2025-10-15 18:00:35 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn from_bytes(bytes: &[u8]) -> Result<Self, NssaError> {
|
2025-11-19 14:28:18 +02:00
|
|
|
Ok(borsh::from_slice(bytes)?)
|
2025-10-15 18:00:35 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-15 20:14:19 -03:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use crate::{ProgramDeploymentTransaction, program_deployment_transaction::Message};
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_roundtrip() {
|
|
|
|
|
let message = Message::new(vec![0xca, 0xfe, 0xca, 0xfe, 0x01, 0x02, 0x03]);
|
|
|
|
|
let tx = ProgramDeploymentTransaction::new(message);
|
|
|
|
|
let bytes = tx.to_bytes();
|
2025-11-19 14:28:18 +02:00
|
|
|
let tx_from_bytes = ProgramDeploymentTransaction::from_bytes(&bytes).unwrap();
|
|
|
|
|
assert_eq!(tx, tx_from_bytes);
|
2025-10-15 20:14:19 -03:00
|
|
|
}
|
|
|
|
|
}
|