Skip to content

Commit

Permalink
chore: bump cairo 2.4.0-rc2 (keep-starknet-strange#218)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->
Bumped alexandria_data_structures version number as there are breaking
changes in ByteArray serde
## Pull Request type

<!-- Please try to limit your pull request to one type; submit multiple
pull requests if needed. -->

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?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Issue Number: N/A

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

## Does this introduce a breaking change?

- [ ] Yes
- [ ] No

<!-- If this does introduce a breaking change, please describe the
impact and migration path for existing applications below. -->

## Other information

<!-- Any other information that is important to this PR, such as
screenshots of how the component looks before and after the change. -->
Bumped alexandria_data_structures version number as there are breaking
changes in ByteArray serde
  • Loading branch information
enitrat authored Nov 20, 2023
1 parent e3af7ed commit 01a7690
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.3.1
scarb 2.4.0-rc2
2 changes: 1 addition & 1 deletion Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [

[[package]]
name = "alexandria_data_structures"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"alexandria_encoding",
]
Expand Down
24 changes: 12 additions & 12 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[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"
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
Expand Down
4 changes: 2 additions & 2 deletions src/data_structures/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[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"

[tool]
fmt.workspace = true

[dependencies]
alexandria_encoding = { path = "../encoding" }
alexandria_encoding = { path = "../encoding" }
36 changes: 0 additions & 36 deletions src/data_structures/src/byte_array_ext.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -444,39 +444,3 @@ impl ByteArrayImpl of ByteArrayTraitExt {
ByteArrayReaderTrait::new(self)
}
}

impl ByteArraySerde of Serde<ByteArray> {
fn serialize(self: @ByteArray, ref output: Array<felt252>) {
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<felt252>) -> Option<ByteArray> {
let length = *serialized.pop_front()?;
let length: usize = length.try_into().unwrap();
let denominator: NonZero<usize> = BYTES_IN_BYTES31.try_into().unwrap();
let (felt_length, pending_word_len) = DivRem::div_rem(length, denominator);
let mut arr: Array<bytes31> = 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()
}
)
}
}
28 changes: 1 addition & 27 deletions src/data_structures/src/tests/byte_array_ext_test.cairo
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -489,12 +472,3 @@ fn test_byte_array_64() -> ByteArray {
ba1.append_word(0x3f40, 2);
ba1
}

fn serialized_byte_array_64() -> Array<felt252> {
array![
0x40,
0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f,
0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e,
0x3f40
]
}

0 comments on commit 01a7690

Please sign in to comment.