Skip to content

Commit

Permalink
Merge branch 'master' into kayagokalp/fuel-core-0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel authored Apr 12, 2024
2 parents e640ed4 + 2d73d09 commit 35d290e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions sway-lib-std/src/vec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,10 @@ where
T: AbiDecode,
{
fn abi_decode(ref mut buffer: BufferReader) -> Vec<T> {
let mut v = Vec::new();

let len = u64::abi_decode(buffer);

let mut v = Vec::with_capacity(len);

let mut i = 0;
while i < len {
let item = T::abi_decode(buffer);
Expand Down Expand Up @@ -710,3 +710,19 @@ fn test_vec_with_len_1() {
let _ = ve.remove(0);
assert(ve.len == 0);
}

#[test()]
fn encode_and_decode_vec() {
let mut v1: Vec<u64> = Vec::new();
v1.push(1);
v1.push(2);
v1.push(3);

let v2 = abi_decode::<Vec<u64>>(encode(v1));

assert(v2.len() == 3);
assert(v2.capacity() == 3);
assert(v2.get(0) == Some(1));
assert(v2.get(1) == Some(2));
assert(v2.get(2) == Some(3));
}

0 comments on commit 35d290e

Please sign in to comment.