Skip to content

Commit f764fc8

Browse files
authored
Bugfix for magic value check and additional serde test (#860)
1 parent b5cfc0c commit f764fc8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pythnet/pythnet_sdk/src/wire.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub mod v1 {
7272

7373
pub fn try_from_slice(bytes: &[u8]) -> Result<Self, Error> {
7474
let message = from_slice::<byteorder::BE, Self>(bytes).unwrap();
75-
require!(&message.magic[..] != b"PNAU", Error::InvalidMagic);
75+
require!(&message.magic[..] == b"PNAU", Error::InvalidMagic);
7676
require!(message.major_version == 1, Error::InvalidVersion);
7777
require!(message.minor_version == 0, Error::InvalidVersion);
7878
Ok(message)
@@ -130,6 +130,8 @@ mod tests {
130130
Deserializer,
131131
PrefixedVec,
132132
Serializer,
133+
v1::AccumulatorUpdateData,
134+
v1::Proof,
133135
};
134136

135137
// Test the arbitrary fixed sized array serialization implementation.
@@ -341,4 +343,26 @@ mod tests {
341343
crate::wire::from_slice::<byteorder::LE, _>(&buffer).unwrap()
342344
);
343345
}
346+
347+
// Test if the AccumulatorUpdateData type can be serialized and deserialized
348+
// and still be the same as the original.
349+
#[test]
350+
fn test_accumulator_update_data_serde() {
351+
use serde::Serialize;
352+
// Serialize an empty update into a buffer.
353+
let empty_update = AccumulatorUpdateData::new(Proof::WormholeMerkle {
354+
vaa: PrefixedVec::from(vec![]),
355+
updates: vec![],
356+
});
357+
let mut buffer = Vec::new();
358+
let mut cursor = std::io::Cursor::new(&mut buffer);
359+
let mut serializer: Serializer<_, byteorder::LE> = Serializer::new(&mut cursor);
360+
empty_update.serialize(&mut serializer).unwrap();
361+
362+
// Test if it can be deserialized back into the original type.
363+
let deserialized_update = AccumulatorUpdateData::try_from_slice(&buffer).unwrap();
364+
365+
// The deserialized value should be the same as the original.
366+
assert_eq!(deserialized_update, empty_update);
367+
}
344368
}

0 commit comments

Comments
 (0)