Skip to content

Commit

Permalink
Add test for compact wrapper struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones committed Jan 6, 2022
1 parent 10c3d51 commit 4e8332d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Event>(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..]);
}
}

0 comments on commit 4e8332d

Please sign in to comment.