Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update xdrgen #312

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=aedb93da
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());
}