Skip to content

Commit

Permalink
test: add test for decoding variable-length inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
grjte committed Nov 7, 2024
1 parent 358c0ce commit 01c4f9a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/decoder.nr
Original file line number Diff line number Diff line change
Expand Up @@ -1069,3 +1069,28 @@ fn test_decode_with_padding() {
];
assert(result == expected);
}

#[test]
fn test_decode_var() {
// base64: SGVsbG8sIFdvcmxkIQ==
let input: BoundedVec<u8, 24> = BoundedVec::from_array([
83, 71, 86, 115, 98, 71, 56, 115, 73, 70, 100, 118, 99, 109, 120, 107, 73, 81, 61, 61,
]);
// base64: SGVsbG8sIFdvcmxkIQ
let input_no_pad: BoundedVec<u8, 24> = BoundedVec::from_array([
83, 71, 86, 115, 98, 71, 56, 115, 73, 70, 100, 118, 99, 109, 120, 107, 73, 81,
]);
// "Hello, World!"
let expected: BoundedVec<u8, 16> =
BoundedVec::from_array([72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]);

// all configurations should decode the same way
let result = STANDARD.decode_var(input);
assert(result == expected);
let result = STANDARD_NO_PAD.decode_var(input_no_pad);
assert(result == expected);
let result = URL_SAFE_WITH_PAD.decode_var(input);
assert(result == expected);
let result = URL_SAFE.decode_var(input_no_pad);
assert(result == expected);
}

0 comments on commit 01c4f9a

Please sign in to comment.