mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 13:41:08 +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) => {
|
EventArg::Option(arg) => {
|
||||||
match input.read_byte()? {
|
match input.read_byte()? {
|
||||||
0 => (),
|
0 => output.push_byte(0),
|
||||||
1 => self.decode_raw_bytes(&[*arg.clone()], input, output)?,
|
1 => {
|
||||||
|
output.push_byte(1);
|
||||||
|
self.decode_raw_bytes(&[*arg.clone()], input, output)?
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Error::Other(
|
return Err(Error::Other(
|
||||||
"unexpected first byte decoding Option".into(),
|
"unexpected first byte decoding Option".into(),
|
||||||
@@ -247,3 +250,31 @@ pub enum Raw {
|
|||||||
Event(RawEvent),
|
Event(RawEvent),
|
||||||
Error(RuntimeError),
|
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.
|
/// Runtime metadata.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
modules: HashMap<String, ModuleMetadata>,
|
modules: HashMap<String, ModuleMetadata>,
|
||||||
modules_with_calls: HashMap<String, ModuleWithCalls>,
|
modules_with_calls: HashMap<String, ModuleWithCalls>,
|
||||||
|
|||||||
Reference in New Issue
Block a user