From 01a7690dc25d19a086f525b8ce66aa505c8e7527 Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Mon, 20 Nov 2023 12:34:17 +0300 Subject: [PATCH] chore: bump cairo 2.4.0-rc2 (#218) Bumped alexandria_data_structures version number as there are breaking changes in ByteArray serde ## Pull Request type Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [x] Build-related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? Issue Number: N/A ## What is the new behavior? - - - ## Does this introduce a breaking change? - [ ] Yes - [ ] No ## Other information Bumped alexandria_data_structures version number as there are breaking changes in ByteArray serde --- .github/workflows/test.yml | 6 ++-- .tool-versions | 2 +- Scarb.lock | 2 +- Scarb.toml | 24 ++++++------- src/data_structures/Scarb.toml | 4 +-- src/data_structures/src/byte_array_ext.cairo | 36 ------------------- .../src/tests/byte_array_ext_test.cairo | 28 +-------------- 7 files changed, 20 insertions(+), 82 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3eac1e7..5cd9dd2c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: - name: Step 2 - Getting scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: 2.3.1 + scarb-version: 2.4.0-rc2 - name: Step 3 - Trying to build run: scarb build @@ -26,7 +26,7 @@ jobs: - name: Step 2 - Getting scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: 2.3.1 + scarb-version: 2.4.0-rc2 - name: Step 3 - Running tests run: scarb test @@ -40,6 +40,6 @@ jobs: - name: Step 2 - Getting scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: 2.3.1 + scarb-version: 2.4.0-rc2 - name: Step 3 - Checking formatting run: scarb fmt --check diff --git a/.tool-versions b/.tool-versions index 963d7a0c..cff9618e 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.3.1 \ No newline at end of file +scarb 2.4.0-rc2 diff --git a/Scarb.lock b/Scarb.lock index 4df19368..b8771674 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -18,7 +18,7 @@ dependencies = [ [[package]] name = "alexandria_data_structures" -version = "0.1.0" +version = "0.2.0" dependencies = [ "alexandria_encoding", ] diff --git a/Scarb.toml b/Scarb.toml index ce9fa1ba..1f582197 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,16 +1,16 @@ [workspace] members = [ - "src/data_structures", - "src/encoding", - "src/linalg", - "src/math", - "src/merkle_tree", - "src/numeric", - "src/searching", - "src/sorting", - "src/storage", - "src/ascii", - "src/bytes", + "src/data_structures", + "src/encoding", + "src/linalg", + "src/math", + "src/merkle_tree", + "src/numeric", + "src/searching", + "src/sorting", + "src/storage", + "src/ascii", + "src/bytes", ] name = "alexandria" version = "0.1.0" @@ -18,7 +18,7 @@ description = "Community maintained Cairo and Starknet libraries" homepage = "https://github.com/keep-starknet-strange/alexandria/" [workspace.dependencies] -starknet = "=2.3.1" +starknet = ">=2.4.0-rc2" [workspace.tool.fmt] sort-module-level-items = true diff --git a/src/data_structures/Scarb.toml b/src/data_structures/Scarb.toml index 99d0ae57..36ee1b1b 100644 --- a/src/data_structures/Scarb.toml +++ b/src/data_structures/Scarb.toml @@ -1,6 +1,6 @@ [package] name = "alexandria_data_structures" -version = "0.1.0" +version = "0.2.0" description = "A set of Cairo data structure libraries and algorithms" homepage = "https://github.com/keep-starknet-strange/alexandria/tree/main/src/data_structures" @@ -8,4 +8,4 @@ homepage = "https://github.com/keep-starknet-strange/alexandria/tree/main/src/da fmt.workspace = true [dependencies] -alexandria_encoding = { path = "../encoding" } \ No newline at end of file +alexandria_encoding = { path = "../encoding" } diff --git a/src/data_structures/src/byte_array_ext.cairo b/src/data_structures/src/byte_array_ext.cairo index e361a6d2..7dcae968 100644 --- a/src/data_structures/src/byte_array_ext.cairo +++ b/src/data_structures/src/byte_array_ext.cairo @@ -444,39 +444,3 @@ impl ByteArrayImpl of ByteArrayTraitExt { ByteArrayReaderTrait::new(self) } } - -impl ByteArraySerde of Serde { - fn serialize(self: @ByteArray, ref output: Array) { - let len = self.len(); - len.serialize(ref output); - let bytes31_arr = self.data.span(); - serialize_array_helper(bytes31_arr, ref output); - - if (*self.pending_word_len > 0) { - output.append(*self.pending_word); - } - } - - fn deserialize(ref serialized: Span) -> Option { - let length = *serialized.pop_front()?; - let length: usize = length.try_into().unwrap(); - let denominator: NonZero = BYTES_IN_BYTES31.try_into().unwrap(); - let (felt_length, pending_word_len) = DivRem::div_rem(length, denominator); - let mut arr: Array = array![]; - let bytes31_arr = deserialize_array_helper(ref serialized, arr, felt_length.into())?; - - let pending_word = if pending_word_len > 0 { - *serialized.pop_front()? - } else { - 0 - }; - - Option::Some( - ByteArray { - data: bytes31_arr, - pending_word: pending_word, - pending_word_len: pending_word_len.try_into().unwrap() - } - ) - } -} diff --git a/src/data_structures/src/tests/byte_array_ext_test.cairo b/src/data_structures/src/tests/byte_array_ext_test.cairo index fc932229..14b0b36a 100644 --- a/src/data_structures/src/tests/byte_array_ext_test.cairo +++ b/src/data_structures/src/tests/byte_array_ext_test.cairo @@ -1,4 +1,4 @@ -use alexandria_data_structures::byte_array_ext::{ByteArraySerde, ByteArrayTraitExt}; +use alexandria_data_structures::byte_array_ext::{ByteArrayTraitExt}; use integer::u512; #[test] @@ -431,23 +431,6 @@ fn test_reader_helper() { assert(reader.data == @ba, 'reader failed'); } -#[test] -#[available_gas(1000000)] -fn test_serialize() { - let mut out = array![]; - let ba = test_byte_array_64(); - ba.serialize(ref out); - let expected = serialized_byte_array_64(); - assert(out == expected, 'serialization differs'); -} - -#[test] -#[available_gas(1000000)] -fn test_deserialize() { - let mut in = serialized_byte_array_64().span(); - let ba: ByteArray = Serde::deserialize(ref in).unwrap(); - assert(ba == test_byte_array_64(), 'deserialized ByteArray differs'); -} // helpers fn test_byte_array_8() -> ByteArray { @@ -489,12 +472,3 @@ fn test_byte_array_64() -> ByteArray { ba1.append_word(0x3f40, 2); ba1 } - -fn serialized_byte_array_64() -> Array { - array![ - 0x40, - 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f, - 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e, - 0x3f40 - ] -}