#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
pub struct DataUpdate {
pub feed_id: [u8; 32],
pub registry_version: u32,
pub value: Vec<u8>,
pub canonical_timestamp: i64,
pub signatures_required: u8,
pub agg_sig_s: [u8; 32],
pub commitment_addr: [u8; 20],
pub signers_bitmap: [u8; 32],
}
#[cfg(all(test, feature = "borsh"))]
mod tests {
use super::*;
use borsh::{BorshDeserialize, BorshSerialize};
const FIXTURE_VALUE: [u8; 32] = [
0x73, 0x6f, 0x6c, 0x61, 0x6e, 0x61, 0x2d, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x2d, 0x76,
0x61, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
];
const FIXTURE_BORSH: [u8; 165] = [
0x73, 0x6f, 0x6c, 0x61, 0x6e, 0x61, 0x2d, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x2d, 0x6a,
0x6f, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x73, 0x6f, 0x6c, 0x61, 0x6e,
0x61, 0x2d, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x2d, 0x76, 0x61, 0x6c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7b, 0xf1, 0x53,
0x65, 0x00, 0x00, 0x00, 0x00, 0x08, 0xc7, 0xe0, 0x99, 0x60, 0x3c, 0xee, 0xd2, 0xa1, 0x13,
0xd7, 0x5a, 0x9d, 0x95, 0xe2, 0x0f, 0x92, 0x00, 0x6b, 0x06, 0xc5, 0x49, 0x7a, 0xdd, 0x09,
0x81, 0x7d, 0xa8, 0x90, 0x8d, 0x39, 0x0d, 0xa5, 0xc6, 0xb9, 0x4f, 0xea, 0x5d, 0xd5, 0xf9,
0x65, 0xd8, 0x67, 0x14, 0xb1, 0xd9, 0x9d, 0xcf, 0xaf, 0x1e, 0x72, 0xee, 0x35, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
];
#[test]
fn fixture_borsh_roundtrip() {
let decoded = DataUpdate::try_from_slice(&FIXTURE_BORSH).expect("decode");
assert_eq!(decoded.value.as_slice(), FIXTURE_VALUE.as_slice());
assert_eq!(decoded.registry_version, 1);
assert_eq!(decoded.signatures_required, 8);
assert_eq!(decoded.canonical_timestamp, 1_700_000_123);
let encoded = decoded.try_to_vec().expect("encode");
assert_eq!(encoded.as_slice(), FIXTURE_BORSH.as_slice());
}
}