Skip to content

Commit

Permalink
Implement Arbitrary for the Status type
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Mar 19, 2023
1 parent bfbb3a5 commit b8f1586
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion soroban-env-common/Cargo.toml
Expand Up @@ -20,12 +20,13 @@ wasmi = { workspace = true, optional = true }
serde = { version = "1.0.0", features = ["derive"], optional = true }
static_assertions = "1.1.0"
ethnum = "1.3.2"
arbitrary = { version = "1.1.3", features = ["derive"], optional = true }

[features]
std = ["stellar-xdr/std", "stellar-xdr/base64"]
serde = ["dep:serde", "stellar-xdr/serde"]
vm = ["wasmi"]
testutils = []
testutils = ["dep:arbitrary", "stellar-xdr/arbitrary"]

[package.metadata.docs.rs]
all-features = true
18 changes: 18 additions & 0 deletions soroban-env-common/src/arbitrary.rs
@@ -0,0 +1,18 @@
//! Implementations of [`Arbitrary`] for contract types.

#![cfg(feature = "testutils")]

extern crate alloc;

use crate::xdr::ScStatus;
use crate::Status;
use arbitrary::{Arbitrary, Unstructured};

impl<'a> Arbitrary<'a> for Status {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
let scstatus = ScStatus::arbitrary(u)?;
let status = Status::from(scstatus);

Ok(status)
}
}
1 change: 1 addition & 0 deletions soroban-env-common/src/lib.rs
Expand Up @@ -36,6 +36,7 @@ pub const VERSION: Version = Version {

mod wrapper_macros;

mod arbitrary;
mod bytes;
mod compare;
mod convert;
Expand Down

0 comments on commit b8f1586

Please sign in to comment.