Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions sway-core/src/semantic_analysis/cei_pattern_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,16 +515,14 @@ fn effects_of_expression(engines: &Engines, expr: &ty::TyExpression) -> HashSet<
let type_engine = engines.te();
let decl_engine = engines.de();
match &expr.expression {
ConstGenericExpression { .. } => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
}
Literal(_)
| ConstantExpression { .. }
| ConfigurableExpression { .. }
| VariableExpression { .. }
| FunctionParameter
| Break
| Continue
| ConstGenericExpression { .. }
| AbiName(_) => HashSet::new(),
// this type of assignment only mutates local variables and not storage
Reassignment(reassgn) => effects_of_expression(engines, &reassgn.rhs),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# TODO Enable this test once https://github.com/FuelLabs/sway/issues/6899 is fixed.
# Compilation fails with error: No method "contains4(Data2<u64, u64>, Data2<numeric, numeric>) -> bool" found for type "Data2<T, K>".
category = "disabled"
category = "run"
expected_result = { action = "return", value = 10 }
expected_result_new_encoding = { action = "return_data", value = "000000000000000A" }
validate_abi = true
4 changes: 1 addition & 3 deletions test/src/in_language_tests/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ members = [
"test_programs/result_inline_tests",
"test_programs/revert_inline_tests",
"test_programs/storage_key_inline_tests",
# TODO: Enable this test once https://github.com/FuelLabs/sway/issues/6899 is fixed.
# Compilation fails with error: No method "eq(Self, Self) -> ()" found for type "Self".
# "test_programs/storage_vec_iter_tests",
"test_programs/storage_vec_iter_tests",
"test_programs/string_inline_tests",
"test_programs/time_inline_tests",
"test_programs/tx_inline_tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl TestInstance for str {
}
}

#[cfg(experimental_const_generics = false)]
impl PartialEq for str[6] {
fn eq(self, other: Self) -> bool {
let mut i = 0;
Expand All @@ -134,6 +135,7 @@ impl PartialEq for str[6] {
true
}
}
#[cfg(experimental_const_generics = false)]
impl Eq for str[6] {}

impl TestInstance for str[6] {
Expand All @@ -154,11 +156,13 @@ impl TestInstance for str[6] {
}
}

#[cfg(experimental_const_generics = false)]
impl PartialEq for [u64; 2] {
fn eq(self, other: Self) -> bool {
self[0] == other[0] && self[1] == other[1]
}
}
#[cfg(experimental_const_generics = false)]
impl Eq for [u64; 2] {}

impl TestInstance for [u64; 2] {
Expand Down Expand Up @@ -251,13 +255,6 @@ impl TestInstance for Enum {
}
}

impl PartialEq for (u8, u32) {
fn eq(self, other: Self) -> bool {
self.0 == other.0 && self.1 == other.1
}
}
impl Eq for (u8, u32) {}

impl TestInstance for (u8, u32) {
fn elements(len: u64) -> Vec<Self> {
let u8_values = u8::elements(len);
Expand Down Expand Up @@ -288,16 +285,11 @@ impl TestInstance for b256 {
}
}

impl AbiEncode for raw_ptr {
fn abi_encode(self, buffer: Buffer) -> Buffer {
let ptr_as_u64 = asm(p: self) {
p: u64
};
ptr_as_u64.abi_encode(buffer)
}
pub struct RawPtrNewtype {
ptr: raw_ptr,
}

impl TestInstance for raw_ptr {
impl TestInstance for RawPtrNewtype {
fn elements(len: u64) -> Vec<Self> {
let values = u8::elements(len);
let mut res = Vec::new();
Expand All @@ -306,16 +298,39 @@ impl TestInstance for raw_ptr {
let null_ptr = asm() {
zero: raw_ptr
};
res.push(null_ptr.add::<u64>(values.get(i).unwrap().as_u64()));
res.push(RawPtrNewtype {
ptr: null_ptr.add::<u64>(values.get(i).unwrap().as_u64())
});
i += 1;
}
res
}
}

impl AbiEncode for RawPtrNewtype {
fn abi_encode(self, buffer: Buffer) -> Buffer {
let ptr_as_u64 = asm(p: self.ptr) {
p: u64
};
ptr_as_u64.abi_encode(buffer)
}
}

impl PartialEq for RawPtrNewtype {
fn eq(self, other: Self) -> bool {
self.ptr == other.ptr
}
}
impl Eq for RawPtrNewtype {}

impl TestInstance for raw_slice {
fn elements(len: u64) -> Vec<Self> {
let ptr_values = raw_ptr::elements(len);
let raw_ptr_values = RawPtrNewtype::elements(len);
let mut ptr_values = Vec::<raw_ptr>::new();
for raw_ptr in raw_ptr_values.iter() {
ptr_values.push(raw_ptr.ptr);
}

let len_values = u8::elements(len);
let mut res = Vec::new();
let mut i = 0;
Expand All @@ -335,13 +350,6 @@ impl TestInstance for raw_slice {
}
}

impl PartialEq for raw_slice {
fn eq(self, other: Self) -> bool {
self.ptr() == other.ptr() && self.number_of_bytes() == other.number_of_bytes()
}
}
impl Eq for raw_slice {}

impl TestInstance for () {
fn elements(len: u64) -> Vec<Self> {
let mut res = Vec::new();
Expand All @@ -354,13 +362,6 @@ impl TestInstance for () {
}
}

impl PartialEq for () {
fn eq(self, other: Self) -> bool {
true
}
}
impl Eq for () {}

impl TestInstance for [u64; 0] {
fn elements(len: u64) -> Vec<Self> {
let mut res = Vec::new();
Expand All @@ -373,9 +374,11 @@ impl TestInstance for [u64; 0] {
}
}

#[cfg(experimental_const_generics = false)]
impl PartialEq for [u64; 0] {
fn eq(self, other: Self) -> bool {
true
}
}
#[cfg(experimental_const_generics = false)]
impl Eq for [u64; 0] {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@ use impls::Enum;
use std::hash::{Hash, sha256};
use std::storage::storage_vec::*;

abi StorageVecIterTest {
#[storage(read)]
fn assert_empty_vec_next_returns_none();

#[storage(read, write)]
fn assert_vec_with_elements_next_returns_element();

#[storage(read, write)]
fn assert_vec_with_elements_for_loop_iteration();

#[storage(read, write)]
fn storage_vec_field_for_loop_iteration();

#[storage(read, write)]
fn storage_vec_field_nested_for_loop_iteration();
}

storage {
vec: StorageVec<u64> = StorageVec {},
vec_of_vec: StorageVec<StorageVec<u64>> = StorageVec {},
Expand All @@ -33,8 +16,7 @@ storage {
#[storage(read)]
fn assert_empty_vec_next_returns_none_impl<T>(slot_id_preimage: u64) {
let vec: StorageKey<StorageVec<T>> = StorageKey::new(sha256(slot_id_preimage), 0, sha256(slot_id_preimage + 100));
// TODO: Replace with `.is_none()` method call once https://github.com/FuelLabs/sway/issues/6825 is fixed.
assert(Option::is_none(vec.iter().next()));
assert(vec.iter().next().is_none());
}

#[storage(read, write)]
Expand All @@ -58,20 +40,18 @@ where
let mut iter = vec.iter();
while i < NUM_OF_ELEMENTS {
let element = iter.next();
// TODO: Replace with `.is_some()` method call once https://github.com/FuelLabs/sway/issues/6825 is fixed.
assert(Option::is_some(element));
assert(element.is_some());

let value = element.unwrap().read();
assert_eq(value, vec.get(i).unwrap().read());

i += 1;
}

// TODO: Replace with `.is_none()` method call once https://github.com/FuelLabs/sway/issues/6825 is fixed.
let element_after_last = iter.next();
assert(Option::is_none(element_after_last));
assert(element_after_last.is_none());
let element_after_last = iter.next();
assert(Option::is_none(element_after_last));
assert(element_after_last.is_none());
}

#[storage(read, write)]
Expand All @@ -91,21 +71,18 @@ where
i += 1;
}

// TODO: This code fails to compile with the error given below.
// Uncomment this test once https://github.com/FuelLabs/sway/issues/6825 is fixed.
// let mut i = 0;
// for element in vec.iter() {
// // ERROR: ^^^^^^^^^^ No method "unwrap(Option<StorageKey<T>>)" found for type "Option<StorageKey<T>>".
// let value = element.read();
// assert_eq(value, vec.get(i).unwrap().read());
let mut i = 0;
for element in vec.iter() {
let value = element.read();
assert_eq(value, vec.get(i).unwrap().read());

// i += 1;
// }
i += 1;
}

// assert_eq(vec.len(), i);
assert_eq(vec.len(), i);
}

impl StorageVecIterTest for Contract {
impl Contract {
#[storage(read)]
fn assert_empty_vec_next_returns_none() {
assert_empty_vec_next_returns_none_impl::<()>(1);
Expand All @@ -124,7 +101,7 @@ impl StorageVecIterTest for Contract {
assert_empty_vec_next_returns_none_impl::<Enum>(14);
assert_empty_vec_next_returns_none_impl::<(u8, u32)>(15);
assert_empty_vec_next_returns_none_impl::<b256>(16);
assert_empty_vec_next_returns_none_impl::<raw_ptr>(17);
assert_empty_vec_next_returns_none_impl::<RawPtrNewtype>(17);
assert_empty_vec_next_returns_none_impl::<raw_slice>(18);
}

Expand All @@ -147,7 +124,7 @@ impl StorageVecIterTest for Contract {
assert_vec_with_elements_next_returns_element_impl::<Enum>(14);
assert_vec_with_elements_next_returns_element_impl::<(u8, u32)>(15);
assert_vec_with_elements_next_returns_element_impl::<b256>(16);
assert_vec_with_elements_next_returns_element_impl::<raw_ptr>(17);
assert_vec_with_elements_next_returns_element_impl::<RawPtrNewtype>(17);
assert_vec_with_elements_next_returns_element_impl::<raw_slice>(18);
}

Expand All @@ -170,7 +147,7 @@ impl StorageVecIterTest for Contract {
assert_vec_with_elements_for_loop_iteration_impl::<Enum>(14);
assert_vec_with_elements_for_loop_iteration_impl::<(u8, u32)>(15);
assert_vec_with_elements_for_loop_iteration_impl::<b256>(16);
assert_vec_with_elements_for_loop_iteration_impl::<raw_ptr>(17);
assert_vec_with_elements_for_loop_iteration_impl::<RawPtrNewtype>(17);
assert_vec_with_elements_for_loop_iteration_impl::<raw_slice>(18);
}

Expand Down Expand Up @@ -239,30 +216,30 @@ impl StorageVecIterTest for Contract {

#[test]
fn empty_vec_next_returns_none() {
let contract_abi = abi(StorageVecIterTest, CONTRACT_ID);
let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID);
contract_abi.assert_empty_vec_next_returns_none();
}

#[test]
fn vec_with_elements_next_returns_element() {
let contract_abi = abi(StorageVecIterTest, CONTRACT_ID);
let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID);
contract_abi.assert_vec_with_elements_next_returns_element();
}

#[test]
fn vec_with_elements_for_loop_iteration() {
let contract_abi = abi(StorageVecIterTest, CONTRACT_ID);
let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID);
contract_abi.assert_vec_with_elements_for_loop_iteration();
}

#[test]
fn storage_vec_field_for_loop_iteration() {
let contract_abi = abi(StorageVecIterTest, CONTRACT_ID);
let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID);
contract_abi.storage_vec_field_for_loop_iteration();
}

#[test]
fn storage_vec_field_nested_for_loop_iteration() {
let contract_abi = abi(StorageVecIterTest, CONTRACT_ID);
let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID);
contract_abi.storage_vec_field_nested_for_loop_iteration();
}
Loading