mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 21:58:06 +00:00
fix option decoding and add basic sanity test (#161)
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
This commit is contained in:
+33
-2
@@ -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(),
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user