From 39d20fb71ea4f64b9fe4d749eee475eb0b77a8c5 Mon Sep 17 00:00:00 2001 From: delaaxe <1091900+delaaxe@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:15:40 +0000 Subject: [PATCH] Fix warnings when compiling with `>=2.5.0` (#269) ## 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) - [ ] 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 --- src/bytes/src/tests/test_bytes.cairo | 12 ++++++------ .../src/tests/array_ext_test.cairo | 9 +-------- .../src/tests/bit_array_test.cairo | 2 +- .../src/tests/byte_reader_test.cairo | 2 -- src/data_structures/src/tests/stack_test.cairo | 2 +- src/data_structures/src/tests/vec_test.cairo | 3 +-- src/encoding/src/tests/rlp_test.cairo | 12 ++++++------ src/math/src/tests/i257_test.cairo | 1 - src/numeric/src/tests/cumprod_test.cairo | 2 +- src/numeric/src/tests/cumsum_test.cairo | 2 +- src/numeric/src/tests/diff_test.cairo | 4 ++-- src/searching/src/tests/dijkstra_test.cairo | 3 --- src/storage/src/tests/list_test.cairo | 15 ++++++--------- 13 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/bytes/src/tests/test_bytes.cairo b/src/bytes/src/tests/test_bytes.cairo index 84296f3b..5674a9f1 100644 --- a/src/bytes/src/tests/test_bytes.cairo +++ b/src/bytes/src/tests/test_bytes.cairo @@ -119,7 +119,7 @@ fn test_bytes_read_u128_packed_out_of_bound() { let bytes = BytesTrait::new(42, array); - let (new_offset, value) = bytes.read_u128_packed(0, 43); + bytes.read_u128_packed(0, 43); } #[test] @@ -134,7 +134,7 @@ fn test_bytes_read_u128_packed_too_large() { let bytes = BytesTrait::new(42, array); - let (new_offset, value) = bytes.read_u128_packed(0, 17); + bytes.read_u128_packed(0, 17); } #[test] @@ -174,7 +174,7 @@ fn test_bytes_read_u128_array_packed_out_of_bound() { let bytes = BytesTrait::new(42, array); - let (new_offset, new_array) = bytes.read_u128_array_packed(0, 11, 4); + bytes.read_u128_array_packed(0, 11, 4); } #[test] @@ -189,7 +189,7 @@ fn test_bytes_read_u128_array_packed_too_large() { let bytes = BytesTrait::new(42, array); - let (new_offset, new_array) = bytes.read_u128_array_packed(0, 2, 17); + bytes.read_u128_array_packed(0, 2, 17); } #[test] @@ -220,7 +220,7 @@ fn test_bytes_read_felt252_packed_out_of_bound() { let bytes = BytesTrait::new(42, array); - let (new_offset, new_array) = bytes.read_felt252_packed(0, 43); + bytes.read_felt252_packed(0, 43); } #[test] @@ -235,7 +235,7 @@ fn test_bytes_read_felt252_packed_too_large() { let bytes = BytesTrait::new(42, array); - let (new_offset, new_array) = bytes.read_felt252_packed(0, 32); + bytes.read_felt252_packed(0, 32); } #[test] diff --git a/src/data_structures/src/tests/array_ext_test.cairo b/src/data_structures/src/tests/array_ext_test.cairo index b00e4925..1daf8242 100644 --- a/src/data_structures/src/tests/array_ext_test.cairo +++ b/src/data_structures/src/tests/array_ext_test.cairo @@ -7,7 +7,6 @@ use alexandria_data_structures::array_ext::{ArrayTraitExt, SpanTraitExt}; fn dedup_all_different() { let mut destination = array![1, 2, 3, 4]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(*new_arr[0] == 1, 'Should be 1'); assert(*new_arr[1] == 2, 'Should be 2'); @@ -21,7 +20,6 @@ fn dedup_all_different() { fn dedup_one_match() { let mut destination = array![1, 2, 2, 3, 4]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(*new_arr[0] == 1, 'Should be 1'); assert(*new_arr[1] == 2, 'Should be 2'); @@ -35,7 +33,6 @@ fn dedup_one_match() { fn dedup_two_matches() { let mut destination = array![1, 2, 2, 3, 4, 4]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(*new_arr[0] == 1, 'Should be 1'); assert(*new_arr[1] == 2, 'Should be 2'); @@ -49,7 +46,6 @@ fn dedup_two_matches() { fn dedup_one_match_more() { let mut destination = array![1, 2, 2, 2, 3, 4, 4]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(*new_arr[0] == 1, 'Should be 1'); assert(*new_arr[1] == 2, 'Should be 2'); @@ -63,7 +59,6 @@ fn dedup_one_match_more() { fn dedup_all_same() { let mut destination = array![2, 2, 2, 2]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(*new_arr[0] == 2, 'Should be 2'); assert(new_arr.len() == 1, 'Len should be 1'); @@ -74,7 +69,6 @@ fn dedup_all_same() { fn dedup_one_elem() { let mut destination = array![2]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(*new_arr[0] == 2, 'Should be 2'); assert(new_arr.len() == 1, 'Len should be 1'); @@ -85,7 +79,7 @@ fn dedup_one_elem() { fn dedup_no_elem() { let mut destination = ArrayTrait::::new(); let new_arr = destination.dedup(); - let len = new_arr.len(); + assert(new_arr.len() == 0, 'Len should be 0'); } @@ -94,7 +88,6 @@ fn dedup_no_elem() { fn dedup_multiple_duplicates_same() { let mut destination = array![1, 1, 3, 4, 3, 3, 3, 4, 2, 2]; let new_arr = destination.dedup(); - let len = new_arr.len(); assert(new_arr.len() == 6, 'Len should be 6'); assert(*new_arr[0] == 1, 'Should be 1'); diff --git a/src/data_structures/src/tests/bit_array_test.cairo b/src/data_structures/src/tests/bit_array_test.cairo index 58914ca1..c96feac5 100644 --- a/src/data_structures/src/tests/bit_array_test.cairo +++ b/src/data_structures/src/tests/bit_array_test.cairo @@ -332,7 +332,7 @@ fn test_serde_ser_deser() { // helpers fn sample_bit_array() -> BitArray { let sample: felt252 = BoundedInt::::max().into() - 1; - let u256{low, high } = sample.into(); + let u256{low, high: _ } = sample.into(); let ba = BitArray { data: array![], current: low.into() * one_shift_left_bytes_felt252(15), diff --git a/src/data_structures/src/tests/byte_reader_test.cairo b/src/data_structures/src/tests/byte_reader_test.cairo index 6ebcdc46..68cceabc 100644 --- a/src/data_structures/src/tests/byte_reader_test.cairo +++ b/src/data_structures/src/tests/byte_reader_test.cairo @@ -466,7 +466,6 @@ fn test_read_sequence_le_arr() { fn test_clone_byte_array_reader() { let ba = test_byte_array_64(); let mut rd1 = ba.reader(); - let temp = rd1.read_u256().unwrap(); let mut rd2 = rd1.clone(); let a = rd1.read_u128().unwrap(); assert(rd1.index != rd2.index, 'indicies equal'); @@ -480,7 +479,6 @@ fn test_clone_byte_array_reader() { fn test_clone_array_of_bytes_reader() { let ba = test_array_64(); let mut rd1 = ba.reader(); - let temp = rd1.read_u256().unwrap(); let mut rd2 = rd1.clone(); let a = rd1.read_u128().unwrap(); assert(rd1.index != rd2.index, 'indicies equal'); diff --git a/src/data_structures/src/tests/stack_test.cairo b/src/data_structures/src/tests/stack_test.cairo index 6447ee50..a9a7bcd8 100644 --- a/src/data_structures/src/tests/stack_test.cairo +++ b/src/data_structures/src/tests/stack_test.cairo @@ -77,7 +77,7 @@ fn stack_push_pop_push_test< ) { stack.push(val_1); stack.push(val_2); - stack.pop(); + let _ = stack.pop(); stack.push(val_3); assert(stack.peek().unwrap() == val_3, 'wrong result'); diff --git a/src/data_structures/src/tests/vec_test.cairo b/src/data_structures/src/tests/vec_test.cairo index caa8a7ce..4bb2b22c 100644 --- a/src/data_structures/src/tests/vec_test.cairo +++ b/src/data_structures/src/tests/vec_test.cairo @@ -30,7 +30,6 @@ fn vec_at_test< ref vec: V, val_1: T ) { vec.push(val_1); - let result = vec.at(0); assert(vec.at(0) == val_1, 'vec at should return val_1'); } @@ -39,7 +38,7 @@ fn vec_at_out_of_bounds_test< >( ref vec: V ) { - let result = vec.at(0); + vec.at(0); } fn vec_push_test< diff --git a/src/encoding/src/tests/rlp_test.cairo b/src/encoding/src/tests/rlp_test.cairo index c1e3b446..3202324a 100644 --- a/src/encoding/src/tests/rlp_test.cairo +++ b/src/encoding/src/tests/rlp_test.cairo @@ -174,7 +174,7 @@ fn test_rlp_decode_short_string() { let res = RLPTrait::decode(arr.span()).unwrap(); // Remove the byte representing the data type - arr.pop_front(); + let _ = arr.pop_front(); let expected_item = array![RLPItem::String(arr.span())].span(); assert(res == expected_item, 'Wrong value'); @@ -291,8 +291,8 @@ fn test_rlp_decode_long_string_with_payload_len_on_1_byte() { let res = RLPTrait::decode(arr.span()).unwrap(); // Remove the bytes representing the data type and their length - arr.pop_front(); - arr.pop_front(); + let _ = arr.pop_front(); + let _ = arr.pop_front(); let expected_item = array![RLPItem::String(arr.span())].span(); assert(res == expected_item, 'Wrong value'); @@ -641,9 +641,9 @@ fn test_rlp_decode_long_string_with_payload_len_on_2_bytes() { let res = RLPTrait::decode(arr.span()).unwrap(); // Remove the bytes representing the data type and their length - arr.pop_front(); - arr.pop_front(); - arr.pop_front(); + let _ = arr.pop_front(); + let _ = arr.pop_front(); + let _ = arr.pop_front(); let expected_item = array![RLPItem::String(arr.span())].span(); assert(res == expected_item, 'Wrong value'); diff --git a/src/math/src/tests/i257_test.cairo b/src/math/src/tests/i257_test.cairo index e79986f7..454c58d9 100644 --- a/src/math/src/tests/i257_test.cairo +++ b/src/math/src/tests/i257_test.cairo @@ -131,7 +131,6 @@ fn i257_test_mul() { // Test multiplication by zero let a = i257 { abs: 10, is_negative: false }; let b = i257 { abs: 0, is_negative: false }; - let expected = i257 { abs: 0, is_negative: false }; let result = a * b; assert(result.abs == 0, '10 * 0 = 0'); assert(!result.is_negative, '10 * 0 -> positive'); diff --git a/src/numeric/src/tests/cumprod_test.cairo b/src/numeric/src/tests/cumprod_test.cairo index fa729c5e..903bbb6e 100644 --- a/src/numeric/src/tests/cumprod_test.cairo +++ b/src/numeric/src/tests/cumprod_test.cairo @@ -15,5 +15,5 @@ fn cumprod_test() { #[available_gas(2000000)] fn cumprod_test_revert_empty() { let xs: Array = array![]; - let ys = cumprod(xs.span()); + cumprod(xs.span()); } diff --git a/src/numeric/src/tests/cumsum_test.cairo b/src/numeric/src/tests/cumsum_test.cairo index 2f0315a0..dacb65f0 100644 --- a/src/numeric/src/tests/cumsum_test.cairo +++ b/src/numeric/src/tests/cumsum_test.cairo @@ -15,5 +15,5 @@ fn cumsum_test() { #[available_gas(2000000)] fn cumsum_test_revert_empty() { let xs: Array = array![]; - let ys = cumsum(xs.span()); + cumsum(xs.span()); } diff --git a/src/numeric/src/tests/diff_test.cairo b/src/numeric/src/tests/diff_test.cairo index 9e8a86de..1a571668 100644 --- a/src/numeric/src/tests/diff_test.cairo +++ b/src/numeric/src/tests/diff_test.cairo @@ -15,7 +15,7 @@ fn diff_test() { #[available_gas(2000000)] fn diff_test_revert_not_sorted() { let xs: Array = array![3, 2]; - let ys = diff(xs.span()); + diff(xs.span()); } #[test] @@ -23,5 +23,5 @@ fn diff_test_revert_not_sorted() { #[available_gas(2000000)] fn diff_test_revert_empty() { let xs: Array = array![]; - let ys = diff(xs.span()); + diff(xs.span()); } diff --git a/src/searching/src/tests/dijkstra_test.cairo b/src/searching/src/tests/dijkstra_test.cairo index 12fe2264..e16d89d6 100644 --- a/src/searching/src/tests/dijkstra_test.cairo +++ b/src/searching/src/tests/dijkstra_test.cairo @@ -70,9 +70,6 @@ fn calculate_shortest_path() { #[test] #[available_gas(2000000)] fn calculate_shortest_path_random() { - let source = 0_u32; - let dest = 2_u32; - let weight = 4_u128; let mut graph = GraphTrait::new(); GraphTrait::add_edge(ref graph, 0, 2, 4); GraphTrait::add_edge(ref graph, 0, 3, 5); diff --git a/src/storage/src/tests/list_test.cairo b/src/storage/src/tests/list_test.cairo index 291a98b5..21b58360 100644 --- a/src/storage/src/tests/list_test.cairo +++ b/src/storage/src/tests/list_test.cairo @@ -34,7 +34,7 @@ mod AListHolder { numbers: List } - #[external(v0)] + #[abi(embed_v0)] impl Holder of super::IAListHolder { fn do_get_len(self: @ContractState) -> (u32, u32) { (self.addresses.read().len(), self.numbers.read().len()) @@ -71,8 +71,8 @@ mod AListHolder { ) { let mut a = self.addresses.read(); let mut n = self.numbers.read(); - a.set(index, addrs_value); - n.set(index, numbers_value); + let _ = a.set(index, addrs_value); + let _ = n.set(index, numbers_value); } fn do_clean(ref self: ContractState) { @@ -189,9 +189,9 @@ mod tests { let numbers_address = contract_state.numbers.address(); let mut numbers_list = ListTrait::::new(0, numbers_address); - addresses_list.append(mock_addr()); - numbers_list.append(1); - numbers_list.append(2); + let _ = addresses_list.append(mock_addr()); + let _ = numbers_list.append(1); + let _ = numbers_list.append(2); assert(addresses_list.len() == 1, 'Addresses length should be 1'); assert(numbers_list.len() == 2, 'Numbers length should be 2'); @@ -205,9 +205,7 @@ mod tests { fn test_fetch_empty_list() { let contract = deploy_mock(); set_contract_address(contract.contract_address); - let mut contract_state = AListHolder::unsafe_new_contract_state(); let storage_address = storage_base_address_from_felt252('empty_address'); - let contract = deploy_mock(); let empty_list = ListTrait::::fetch(0, storage_address).expect('List fetch failed'); @@ -512,7 +510,6 @@ mod tests { #[available_gas(100000000)] fn test_array_clean_with_empty_array() { let contract = deploy_mock(); - let mock_addr = mock_addr(); assert(contract.do_get_len() == (0, 0), 'is empty');