Skip to content

Commit

Permalink
Update xdrgen (#312)
Browse files Browse the repository at this point in the history
* add test

* ff

* upd xdrgen

* new

* upd
  • Loading branch information
leighmcculloch authored Oct 21, 2023
1 parent b96ca71 commit 313b59d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic

CARGO_HACK_ARGS=--feature-powerset --exclude-features default --group-features base64,serde,arbitrary,hex

XDRGEN_VERSION=92e5c651
XDRGEN_VERSION=b405294c
CARGO_DOC_ARGS?=--open

all: build test
Expand Down
2 changes: 1 addition & 1 deletion src/curr/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ impl<T: ReadXdr, const MAX: u32> ReadXdr for VecM<T, MAX> {
return Err(Error::LengthExceedsMax);
}

let mut vec = Vec::with_capacity(len as usize);
let mut vec = Vec::new();
for _ in 0..len {
let t = T::read_xdr(r)?;
vec.push(t);
Expand Down
2 changes: 1 addition & 1 deletion src/next/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ impl<T: ReadXdr, const MAX: u32> ReadXdr for VecM<T, MAX> {
return Err(Error::LengthExceedsMax);
}

let mut vec = Vec::with_capacity(len as usize);
let mut vec = Vec::new();
for _ in 0..len {
let t = T::read_xdr(r)?;
vec.push(t);
Expand Down
44 changes: 44 additions & 0 deletions tests/vecm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#![cfg(all(
any(feature = "curr", feature = "next"),
not(all(feature = "curr", feature = "next"))
))]
#![cfg(feature = "std")]

#[cfg(feature = "curr")]
use stellar_xdr::curr as stellar_xdr;
#[cfg(feature = "next")]
use stellar_xdr::next as stellar_xdr;

use stellar_xdr::{ReadXdr, ScVal};

#[test]
fn valid_len() {
let data = [
0x00, 0x00, 0x00, 0x11, // SCV_MAP
0x00, 0x00, 0x00, 0x01, // Some
0x00, 0x00, 0x00, 0x01, // map length
0x00, 0x00, 0x00, 0x0f, // SCV_SYMBOL
0x00, 0x00, 0x00, 0x03, // symbol length: 3
0x63, 0x6e, 0x74, 0x00, // symbol value : "cnt"
0x00, 0x00, 0x00, 0x03, // SCV_U32
0x00, 0x00, 0x00, 0x2a, // 42
];
let result = ScVal::from_xdr(data);
assert!(result.is_ok());
}

#[test]
fn invalid_len() {
let data = [
0x00, 0x00, 0x00, 0x11, // SCV_MAP
0x00, 0x00, 0x00, 0x01, // Some
0xff, 0xff, 0xff, 0xff, // map length (first byte invalid)
0x00, 0x00, 0x00, 0x0f, // SCV_SYMBOL
0x00, 0x00, 0x00, 0x03, // symbol length: 3
0x63, 0x6e, 0x74, 0x00, // symbol value : "cnt"
0x00, 0x00, 0x00, 0x03, // SCV_U32
0x00, 0x00, 0x00, 0x2a, // 42
];
let result = ScVal::from_xdr(data);
assert!(result.is_err());
}

0 comments on commit 313b59d

Please sign in to comment.