lssa/nssa/src/encoding/program_deployment_transaction.rs

26 lines
802 B
Rust
Raw Normal View History

use crate::{ProgramDeploymentTransaction, error::NssaError};
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")
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self, NssaError> {
Ok(borsh::from_slice(bytes)?)
}
}
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();
let tx_from_bytes = ProgramDeploymentTransaction::from_bytes(&bytes).unwrap();
assert_eq!(tx, tx_from_bytes);
2025-10-15 20:14:19 -03:00
}
}