Skip to content

Commit 55290a1

Browse files
authored
Merge pull request #2379 from CosmWasm/co/cwa-2024-008-test
Add tests
2 parents 95600bc + 1f40410 commit 55290a1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/vm/src/sections.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ mod tests {
123123
assert_eq!(dec, &[vec![0xAA], vec![0xDE, 0xDE], vec![], vec![0xFF; 19]]);
124124
}
125125

126+
#[test]
127+
fn decode_sections_fails_for_invalid_length() {
128+
// section length too long
129+
assert!(decode_sections(b"\xAA\0\0\0\x02").is_err());
130+
// section length without section
131+
assert!(decode_sections(b"\xAA\0\0\0\x01\xBB\x03\0\0\0\x03").is_err());
132+
}
133+
134+
#[test]
135+
fn decode_sections_fails_for_extra_bytes() {
136+
// extra data after successful section
137+
assert!(decode_sections(b"\x44\xAA\0\0\0\x01").is_err());
138+
assert!(decode_sections(b"\x44\x44\xAA\0\0\0\x01").is_err());
139+
assert!(decode_sections(b"\x44\x44\x44\xAA\0\0\0\x01").is_err());
140+
141+
// Insufficient length for even a first section (or extra data of 0 sections)
142+
assert!(decode_sections(b"\x44").is_err());
143+
assert!(decode_sections(b"\x44\x44").is_err());
144+
assert!(decode_sections(b"\x44\x44\x44").is_err());
145+
}
146+
126147
#[test]
127148
fn encode_sections_works_for_empty_sections() {
128149
let enc = encode_sections(&[]).unwrap();

0 commit comments

Comments
 (0)