Skip to content

Commit

Permalink
fix: patch circ dep in bounded-vec (#858)
Browse files Browse the repository at this point in the history
* up

* fix circ dependency in bounded-vec

* fi

* done

* fmt

---------

Co-authored-by: Swen <[email protected]>
  • Loading branch information
SwenSchaeferjohann and Swen authored Jun 23, 2024
1 parent f904d0c commit 21aadca
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion merkle-tree/bounded-vec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ solana-program = { version = "1.18.11", optional = true }
thiserror = "1.0"

[dev-dependencies]
light-utils = { version = "0.2.0", path = "../../utils" }
rand = "0.8"
38 changes: 37 additions & 1 deletion merkle-tree/bounded-vec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,14 +783,50 @@ where
mod test {
use std::array;

use light_utils::rand::gen_range_exclude;
use rand::{
distributions::{Distribution, Standard},
thread_rng, Rng,
};

use super::*;

use rand::distributions::uniform::{SampleRange, SampleUniform};

/// Generates a random value in the given range, excluding the values provided
/// in `exclude`.
fn gen_range_exclude<N, R, T>(rng: &mut N, range: R, exclude: &[T]) -> T
where
N: Rng,
R: Clone + SampleRange<T>,
T: PartialEq + SampleUniform,
{
loop {
// This utility is supposed to be used only in unit tests. This `clone`
// is harmless and necessary (can't pass a reference to range, it has
// to be moved).
let sample = rng.gen_range(range.clone());
if !exclude.contains(&sample) {
return sample;
}
}
}

#[test]
fn test_gen_range_exclude() {
let mut rng = thread_rng();

for n_excluded in 1..100 {
let excluded: Vec<u64> = (0..n_excluded).map(|_| rng.gen_range(0..100)).collect();

for _ in 0..10_000 {
let sample = gen_range_exclude(&mut rng, 0..100, excluded.as_slice());
for excluded in excluded.iter() {
assert_ne!(&sample, excluded);
}
}
}
}

fn rand_bounded_vec<T>() -> BoundedVec<T>
where
T: Clone,
Expand Down
2 changes: 1 addition & 1 deletion scripts/release-all-rust-crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo "Tagging and releasing all Rust projects..."
echo "Logging in to crates.io..."
cargo login "${CRATES_IO_TOKEN}"
# TODO: allow dynamic releases, and add gh release workflow
PACKAGES=("aligned-sized" "light-heap" "light-utils" "light-bounded-vec" "light-hasher" "light-macros" "light-hash-set" "light-merkle-tree-reference" "light-concurrent-merkle-tree" "light-indexed-merkle-tree" "light-prover-client" "light-verifier" "account-compression" "light-registry" "light-system-program" "light-compressed-token" "light-test-utils")
PACKAGES=("aligned-sized" "light-heap" "light-bounded-vec" "light-utils" "light-hasher" "light-macros" "light-hash-set" "light-merkle-tree-reference" "light-concurrent-merkle-tree" "light-indexed-merkle-tree" "light-prover-client" "light-verifier" "account-compression" "light-registry" "light-system-program" "light-compressed-token" "light-test-utils")
for PACKAGE in "${PACKAGES[@]}"; do
PKG_VERSION=$(cargo pkgid -p "$PACKAGE" | cut -d "#" -f2)
VERSION=${PKG_VERSION#*@}
Expand Down

0 comments on commit 21aadca

Please sign in to comment.