Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ impl<T: System> EventsDecoder<T> {
}
EventArg::Option(arg) => {
match input.read_byte()? {
0 => (),
1 => self.decode_raw_bytes(&[*arg.clone()], input, output)?,
0 => output.push_byte(0),
1 => {
output.push_byte(1);
self.decode_raw_bytes(&[*arg.clone()], input, output)?
}
_ => {
return Err(Error::Other(
"unexpected first byte decoding Option".into(),
Expand Down Expand Up @@ -247,3 +250,31 @@ pub enum Raw {
Event(RawEvent),
Error(RuntimeError),
}

#[cfg(test)]
mod tests {
use super::*;

type TestRuntime = crate::NodeTemplateRuntime;

#[test]
fn test_decode_option() {
let decoder = EventsDecoder::<TestRuntime>::new(Metadata::default());

let value = Some(0u8);
let input = value.encode();
let mut output = Vec::<u8>::new();

decoder
.decode_raw_bytes(
&[EventArg::Option(Box::new(EventArg::Primitive(
"u8".to_string(),
)))],
&mut &input[..],
&mut output,
)
.unwrap();

assert_eq!(output, vec![1, 0]);
}
}
2 changes: 1 addition & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub enum MetadataError {
}

/// Runtime metadata.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Metadata {
modules: HashMap<String, ModuleMetadata>,
modules_with_calls: HashMap<String, ModuleWithCalls>,
Expand Down