diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index fa7e154..a83755b 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -43,6 +43,7 @@ jobs: - name: Check code coverage with cargo-tarpaulin run: cargo-tarpaulin --workspace --all-features --out xml - name: Upload to codecov.io - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 with: fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 7e29c59..f96bebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["ethereum"] categories = ["cryptography::cryptocurrencies"] [dependencies] -tree_hash = { git = "https://github.com/KolbyML/tree_hash.git", rev = "8aaf8bb4184148768d48e2cfbbdd0b95d1da8730" } +tree_hash = { git = "https://github.com/eserilev/tree_hash", branch = "alloy-deps"} ethereum_serde_utils = "0.5" ethereum_ssz = "0.5" serde = "1.0.0" @@ -24,4 +24,4 @@ itertools = "0.10.0" [dev-dependencies] serde_json = "1.0.0" -tree_hash_derive = { git = "https://github.com/KolbyML/tree_hash.git", rev = "8aaf8bb4184148768d48e2cfbbdd0b95d1da8730" } +tree_hash_derive = { git = "https://github.com/eserilev/tree_hash", branch = "alloy-deps"} diff --git a/src/bitfield.rs b/src/bitfield.rs index d090833..dedaf7a 100644 --- a/src/bitfield.rs +++ b/src/bitfield.rs @@ -240,6 +240,24 @@ impl Bitfield> { pub fn is_subset(&self, other: &Self) -> bool { self.difference(other).is_zero() } + + /// Returns a new BitList of length M, with the same bits set as `self`. + pub fn resize(&self) -> Result>, Error> { + if N::to_usize() > M::to_usize() { + return Err(Error::InvalidByteCount { + given: M::to_usize(), + expected: N::to_usize() + 1, + }); + } + + let mut resized = Bitfield::>::with_capacity(M::to_usize())?; + + for (i, bit) in self.iter().enumerate() { + resized.set(i, bit)?; + } + + Ok(resized) + } } impl Bitfield> { @@ -1403,4 +1421,21 @@ mod bitlist { fn size_of() { assert_eq!(std::mem::size_of::(), SMALLVEC_LEN + 24); } + + #[test] + fn resize() { + let mut bit_list = BitList1::with_capacity(1).unwrap(); + bit_list.set(0, true).unwrap(); + assert_eq!(bit_list.len(), 1); + assert_eq!(bit_list.num_set_bits(), 1); + assert_eq!(bit_list.highest_set_bit().unwrap(), 0); + + let resized_bit_list = bit_list.resize::().unwrap(); + assert_eq!(resized_bit_list.len(), 1024); + assert_eq!(resized_bit_list.num_set_bits(), 1); + assert_eq!(resized_bit_list.highest_set_bit().unwrap(), 0); + + // Can't extend a BitList to a smaller BitList + resized_bit_list.resize::().unwrap_err(); + } } diff --git a/src/fixed_vector.rs b/src/fixed_vector.rs index 78dd309..939fbd8 100644 --- a/src/fixed_vector.rs +++ b/src/fixed_vector.rs @@ -46,7 +46,7 @@ pub use typenum; /// assert_eq!(&long[..], &[1, 2, 3, 4, 0]); /// ``` #[derive(Debug, Clone, Serialize, Deserialize, Derivative)] -#[derivative(PartialEq, Hash(bound = "T: std::hash::Hash"))] +#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))] #[serde(transparent)] pub struct FixedVector { vec: Vec,