Ensure to digest non-empty snapshot_storages and add asserts (#11021)

* Add asserts to detect not-digestable example data

* Ensure to digest non-empty snapshot_storages
This commit is contained in:
Ryo Onodera
2020-07-14 00:58:34 +09:00
committed by GitHub
parent e95e7a96da
commit de379a8cd6
3 changed files with 40 additions and 20 deletions

View File

@ -340,7 +340,12 @@ impl Serializer for AbiDigester {
}
fn serialize_seq(mut self, len: Option<usize>) -> DigestResult {
self.update_with_string(format!("seq (elements = {})", len.unwrap()));
let len = len.unwrap();
assert_eq!(
len, 1,
"Exactly 1 seq element is needed to generate the ABI digest precisely"
);
self.update_with_string(format!("seq (elements = {})", len));
Ok(self.create_child())
}
@ -367,7 +372,12 @@ impl Serializer for AbiDigester {
}
fn serialize_map(mut self, len: Option<usize>) -> DigestResult {
self.update_with_string(format!("map (entries = {})", len.unwrap()));
let len = len.unwrap();
assert_eq!(
len, 1,
"Exactly 1 map entry is needed to generate the ABI digest precisely"
);
self.update_with_string(format!("map (entries = {})", len));
Ok(self.create_child())
}