From 4e8332ddcd9b758973bdecbea9901c4a378e26b7 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 6 Jan 2022 10:43:35 +0000 Subject: [PATCH] Add test for compact wrapper struct --- src/events.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/events.rs b/src/events.rs index 4508ad20fd..aa2b80ea7c 100644 --- a/src/events.rs +++ b/src/events.rs @@ -431,26 +431,40 @@ mod tests { } #[test] - fn compact_event_field() { + fn compact_fields() { #[derive(Clone, Encode, TypeInfo)] enum Event { A(#[codec(compact)] u32), + B(#[codec(compact)] CompactWrapper), } + #[derive(Clone, codec::CompactAs, Encode, TypeInfo)] + struct CompactWrapper(u64); + let pallet_index = 0; let pallet = pallet_metadata::(pallet_index); let decoder = init_decoder(vec![pallet]); - let event = Event::A(u32::MAX); - let encoded_event = event.encode(); - let event_records = vec![event_record(pallet_index, event)]; + let event1 = Event::A(u32::MAX); + let event2 = Event::B(CompactWrapper(0)); + + let encoded_event1 = event1.encode(); + let encoded_event2 = event2.encode(); + + let event_records = vec![ + event_record(pallet_index, event1), + event_record(pallet_index, event2), + ]; let mut input = Vec::new(); event_records.encode_to(&mut input); let events = decoder.decode_events(&mut &input[..]).unwrap(); - assert_eq!(events[0].1.variant_index, encoded_event[0]); - assert_eq!(events[0].1.data.0, encoded_event[1..]); + assert_eq!(events[0].1.variant_index, encoded_event1[0]); + assert_eq!(events[0].1.data.0, encoded_event1[1..]); + + assert_eq!(events[1].1.variant_index, encoded_event2[0]); + assert_eq!(events[1].1.data.0, encoded_event2[1..]); } }