From 38f1f10aa4aef7afa5fe6df0d9d0bf3100ec2fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Fri, 2 Aug 2024 01:00:48 +0200 Subject: [PATCH] Additionally test associated constants (#6349) ## Description This PR strengthens existing and adds new tests for associated constants. This extended test coverage revealed the following existing issues: #6310, #6348, #6345, #6346, #6343, #6344. It also pointed out that we are missing rules for a contract implementing several ABIs with overlapping interface surfaces, where constants can also be overlapping: #6306. All the issues are linked to tests via TODOs in code that is commented out. We will address the issues in separate PRs. With this PR, we want to first have tests in place. Additionally, the PR: - cleans up dead code that become obsolete when `TyConfigurableDecl` was introduced in #6058. - deletes some redundant tests for constants. - groups some tests to reduce test compilation and execution time and provides guidelines for such groupings in the testing README.md. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --- .../language/parsed/declaration/constant.rs | 2 - .../ast_node/declaration/constant.rs | 65 ++++------ .../ast_node/expression/intrinsic_function.rs | 3 - .../typed_expression/if_expression.rs | 1 - .../to_parsed_lang/convert_parse_tree.rs | 1 - sway-core/src/type_system/engine.rs | 5 - sway-core/src/type_system/unify/unifier.rs | 6 - sway-error/src/type_error.rs | 1 - test/src/e2e_vm_tests/README.md | 3 + .../Forc.lock | 3 + .../Forc.toml | 5 +- .../src/main.sw | 17 +++ .../test.toml | 7 ++ .../src/main.sw | 11 +- .../src/main.sw | 6 +- .../src/main.sw | 6 +- .../array_oob/json_abi_oracle.json | 1 - .../array_oob_global_const_index/Forc.lock | 15 +-- .../array_oob_global_const_index/Forc.toml | 3 +- .../json_abi_oracle.json | 1 - .../array_oob_global_const_index/src/main.sw | 4 +- .../const-instead-of-let/Forc.lock | 16 --- .../const-instead-of-let/json_abi_oracle.json | 25 ---- .../Forc.lock | 5 - .../Forc.toml | 3 - .../src/main.sw | 6 +- .../const_instead_of_let}/Forc.lock | 4 +- .../Forc.toml | 4 +- .../src/main.sw | 3 +- .../test.toml | 1 - .../const_top_level_no_expr/src/main.sw | 6 +- .../src/main.sw | 11 +- .../src/main.sw | 6 +- .../src/main.sw | 6 +- .../language/associated_const_abi/Forc.lock | 7 +- .../language/associated_const_abi/Forc.toml | 2 +- .../language/associated_const_abi/src/main.sw | 118 ++++++++++++++++-- .../language/associated_const_abi/test.toml | 5 +- .../associated_const_abi_default/Forc.lock | 8 -- .../associated_const_abi_default/src/main.sw | 18 --- .../associated_const_abi_default/test.toml | 4 - .../associated_const_abi_multiple/Forc.lock | 7 +- .../associated_const_abi_multiple/Forc.toml | 2 +- .../associated_const_abi_multiple/src/main.sw | 30 +++-- .../associated_const_abi_multiple/test.toml | 5 +- .../associated_const_impl_multiple/Forc.lock | 7 +- .../associated_const_impl_multiple/Forc.toml | 2 +- .../src/main.sw | 8 +- .../associated_const_impl_multiple/test.toml | 5 +- .../associated_const_impl_self/src/main.sw | 17 ++- .../associated_const_impl_self/test.toml | 4 +- .../Forc.lock | 8 -- .../src/main.sw | 16 --- .../test.toml | 4 - .../language/associated_const_trait/Forc.lock | 7 +- .../language/associated_const_trait/Forc.toml | 2 +- .../associated_const_trait/src/main.sw | 107 ++++++++++++++-- .../associated_const_trait/src/traits.sw | 29 +++++ .../language/associated_const_trait/test.toml | 5 +- .../associated_const_trait_const/Forc.lock | 8 -- .../associated_const_trait_const/Forc.toml | 9 -- .../associated_const_trait_const/src/main.sw | 15 --- .../associated_const_trait_const/test.toml | 4 - .../associated_const_trait_default/Forc.lock | 7 +- .../associated_const_trait_default/Forc.toml | 2 +- .../src/main.sw | 10 +- .../associated_const_trait_default/test.toml | 5 +- .../const_decl_in_library/src/main.sw | 9 +- .../const_decl_in_library/src/moon.sw | 3 + .../language/const_decl_literal/Forc.toml | 8 -- .../const_decl_literal/json_abi_oracle.json | 25 ---- .../json_abi_oracle_new_encoding.json | 26 ---- .../language/const_decl_literal/src/main.sw | 8 -- .../language/const_decl_literal/test.toml | 4 - .../const_decl_with_call_path/Forc.lock | 13 -- .../const_decl_with_call_path/Forc.toml | 8 -- .../json_abi_oracle.json | 25 ---- .../json_abi_oracle_new_encoding.json | 26 ---- .../const_decl_with_call_path/src/main.sw | 13 -- .../const_decl_with_call_path/src/test_lib.sw | 3 - .../const_decl_with_call_path/test.toml | 4 - .../Forc.lock | 13 ++ .../Forc.toml | 4 +- .../src/main.sw | 31 +++++ .../test.toml | 1 + .../numeric_constants/json_abi_oracle.json | 59 ++++++++- .../json_abi_oracle_new_encoding.json | 59 ++++++++- .../language/numeric_constants/src/main.sw | 24 ++-- 88 files changed, 588 insertions(+), 527 deletions(-) create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.lock rename test/src/e2e_vm_tests/test_programs/{should_pass/language/associated_const_abi_default => should_fail/abi_associated_const_access_with_impl_in_contract}/Forc.toml (51%) create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/test.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/array_oob/json_abi_oracle.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/json_abi_oracle.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/json_abi_oracle.json rename test/src/e2e_vm_tests/test_programs/{should_pass/language/const_decl_literal => should_fail/const_instead_of_let}/Forc.lock (52%) rename test/src/e2e_vm_tests/test_programs/should_fail/{const-instead-of-let => const_instead_of_let}/Forc.toml (62%) rename test/src/e2e_vm_tests/test_programs/should_fail/{const-instead-of-let => const_instead_of_let}/src/main.sw (81%) rename test/src/e2e_vm_tests/test_programs/should_fail/{const-instead-of-let => const_instead_of_let}/test.toml (81%) delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/test.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/test.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/traits.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/test.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/moon.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle_new_encoding.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/test.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.lock delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.toml delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle_new_encoding.json delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw delete mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/test.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.lock rename test/src/e2e_vm_tests/test_programs/should_pass/language/{associated_const_impl_self_order => contract_implements_multiple_abis_with_same_methods}/Forc.toml (50%) create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/test.toml diff --git a/sway-core/src/language/parsed/declaration/constant.rs b/sway-core/src/language/parsed/declaration/constant.rs index 174c20a4121..c76a044fc15 100644 --- a/sway-core/src/language/parsed/declaration/constant.rs +++ b/sway-core/src/language/parsed/declaration/constant.rs @@ -14,7 +14,6 @@ pub struct ConstantDeclaration { pub type_ascription: TypeArgument, pub value: Option, pub visibility: Visibility, - pub is_configurable: bool, pub span: Span, } @@ -26,7 +25,6 @@ impl PartialEqWithEngines for ConstantDeclaration { && self.type_ascription.eq(&other.type_ascription, ctx) && self.value.eq(&other.value, ctx) && self.visibility == other.visibility - && self.is_configurable == other.is_configurable && self.span == other.span } } diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/constant.rs b/sway-core/src/semantic_analysis/ast_node/declaration/constant.rs index b574753b6d7..da95a2a2dad 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/constant.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/constant.rs @@ -28,7 +28,6 @@ impl ty::TyConstantDecl { span, mut type_ascription, value, - is_configurable, attributes, visibility, } = decl; @@ -53,48 +52,28 @@ impl ty::TyConstantDecl { }) } - // Configurables will be encoded and must be type_checked into "slice" - let (value, return_type) = if is_configurable && ctx.experimental.new_encoding { - let mut ctx = ctx - .by_ref() - .with_type_annotation(type_engine.insert(engines, TypeInfo::RawUntypedSlice, None)) - .with_help_text("Configurables must evaluate to slices."); - - let value = value.map(|value| { - ty::TyExpression::type_check(handler, ctx.by_ref(), &value) - .unwrap_or_else(|err| ty::TyExpression::error(err, name.span(), engines)) - }); - - ( - value, - type_engine.insert(engines, TypeInfo::RawUntypedSlice, None), - ) - } else { - let mut ctx = ctx - .by_ref() - .with_type_annotation(type_ascription.type_id) - .with_help_text( - "This declaration's type annotation does not match up with the assigned \ - expression's type.", - ); - - let value = value.map(|value| { - ty::TyExpression::type_check(handler, ctx.by_ref(), &value) - .unwrap_or_else(|err| ty::TyExpression::error(err, name.span(), engines)) - }); - // Integers are special in the sense that we can't only rely on the type of `expression` - // to get the type of the variable. The type of the variable *has* to follow - // `type_ascription` if `type_ascription` is a concrete integer type that does not - // conflict with the type of `expression` (i.e. passes the type checking above). - let return_type = match &*type_engine.get(type_ascription.type_id) { - TypeInfo::UnsignedInteger(_) => type_ascription.type_id, - _ => match &value { - Some(value) => value.return_type, - None => type_ascription.type_id, - }, - }; - - (value, return_type) + let mut ctx = ctx + .by_ref() + .with_type_annotation(type_ascription.type_id) + .with_help_text( + "This declaration's type annotation does not match up with the assigned \ + expression's type.", + ); + + let value = value.map(|value| { + ty::TyExpression::type_check(handler, ctx.by_ref(), &value) + .unwrap_or_else(|err| ty::TyExpression::error(err, name.span(), engines)) + }); + // Integers are special in the sense that we can't only rely on the type of `expression` + // to get the type of the variable. The type of the variable *has* to follow + // `type_ascription` if `type_ascription` is a concrete integer type that does not + // conflict with the type of `expression` (i.e. passes the type checking above). + let return_type = match &*type_engine.get(type_ascription.type_id) { + TypeInfo::UnsignedInteger(_) => type_ascription.type_id, + _ => match &value { + Some(value) => value.return_type, + None => type_ascription.type_id, + }, }; let mut call_path: CallPath = name.into(); diff --git a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs index 9c324cf1289..9c750722f07 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs @@ -323,7 +323,6 @@ fn type_check_not( received: engines.help_out(return_type).to_string(), help_text: "".into(), span, - internal: "8".into(), }, ))), } @@ -1241,7 +1240,6 @@ fn type_check_bitwise_binary_op( received: engines.help_out(return_type).to_string(), help_text: "".into(), span, - internal: "7".into(), }, ))), } @@ -1316,7 +1314,6 @@ fn type_check_shift_binary_op( received: engines.help_out(return_type).to_string(), help_text: "Incorrect argument type".into(), span: lhs.span, - internal: "6".into(), }, ))), } diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/if_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/if_expression.rs index fd9cb084665..bdd3679c869 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/if_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/if_expression.rs @@ -80,7 +80,6 @@ pub(crate) fn instantiate_if_expression( help_text: "The two branches of an if expression must return the same type." .to_string(), span: span.clone(), - internal: "".into(), })); } diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index 78ed08eee4e..4e70c070b5e 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -979,7 +979,6 @@ pub(crate) fn item_const_to_constant_declaration( type_ascription, value: expr, visibility: pub_token_opt_to_visibility(item_const.visibility), - is_configurable: false, attributes, span, }; diff --git a/sway-core/src/type_system/engine.rs b/sway-core/src/type_system/engine.rs index 38871fd4108..e3b945e1484 100644 --- a/sway-core/src/type_system/engine.rs +++ b/sway-core/src/type_system/engine.rs @@ -224,11 +224,6 @@ impl TypeEngine { received: engines.help_out(received).to_string(), help_text: help_text.to_string(), span: span.clone(), - internal: format!( - "expected:[{:?}]; received:[{:?}]", - engines.help_out(expected), - engines.help_out(received), - ), })); } } diff --git a/sway-core/src/type_system/unify/unifier.rs b/sway-core/src/type_system/unify/unifier.rs index 0efc7883153..1473e4c8502 100644 --- a/sway-core/src/type_system/unify/unifier.rs +++ b/sway-core/src/type_system/unify/unifier.rs @@ -324,7 +324,6 @@ impl<'a> Unifier<'a> { received, help_text: self.help_text.clone(), span: span.clone(), - internal: "4".into(), } .into(), ); @@ -353,7 +352,6 @@ impl<'a> Unifier<'a> { received, help_text: self.help_text.clone(), span: span.clone(), - internal: "3".into(), } .into(), ); @@ -397,7 +395,6 @@ impl<'a> Unifier<'a> { received, help_text: self.help_text.clone(), span: span.clone(), - internal: "2".into(), } .into(), ); @@ -428,7 +425,6 @@ impl<'a> Unifier<'a> { self.unify(handler, rtp.type_id, etp.type_id, span); }); } else { - let internal = format!("[{received:?}] versus [{expected:?}]"); let (received, expected) = self.assign_args(received, expected); handler.emit_err( TypeError::MismatchedType { @@ -436,7 +432,6 @@ impl<'a> Unifier<'a> { received, help_text: self.help_text.clone(), span: span.clone(), - internal, } .into(), ); @@ -475,7 +470,6 @@ impl<'a> Unifier<'a> { received, help_text: self.help_text.clone(), span: span.clone(), - internal: "1".into(), } .into(), ); diff --git a/sway-error/src/type_error.rs b/sway-error/src/type_error.rs index a4d7d3fd389..c3ed46b0750 100644 --- a/sway-error/src/type_error.rs +++ b/sway-error/src/type_error.rs @@ -15,7 +15,6 @@ pub enum TypeError { received: String, help_text: String, span: Span, - internal: String, }, #[error("This type is not known. Try annotating it with a type annotation.")] UnknownType { span: Span }, diff --git a/test/src/e2e_vm_tests/README.md b/test/src/e2e_vm_tests/README.md index 2bc1b02bfc8..fdc8af3fa0a 100644 --- a/test/src/e2e_vm_tests/README.md +++ b/test/src/e2e_vm_tests/README.md @@ -4,10 +4,13 @@ In order to minimize compilation time of individual tests, strive to reduce depe To achieve that, follow these guidelines: - Use `implicit-std = false` if dependency on `core` is not needed. This is often possible when testing `should_pass/language` features. +- If the dependency on `core` is not needed, instead of using the project type `script`, that will, because of the encoding, depend on `core`, try using `library` instead. - Do not use `std` just to conveniently get an arbitrary type or trait. E.g., if a test requires an arbitrary type or trait, go with `struct Dummy {}` or `trait Trait {}` instead of importing `Option` or `Hash`. - If `std` functionality is needed, import the minimal [reduced `std` library](reduced_std_libs/README.md) that provides the functionality. - Import the full `std` only if the provided [reduced `std` libraries](reduced_std_libs/README.md) do not provide required types. +Additionally, try to meaningfully group tests with high cohesion, rather then splitting them into several tests. Having only one test project reduces compilation time. E.g., instead of having two tests `test_some_feature_for_option_a` and `test_some_feature_for_option_b`, try having just `test_some_feature` and the two cases tested in, e.g., modules in that one test. Makes sure, though, that such test groupings are meaningful. We don't want to end up having artificially combined tests. + # Running end-to-end VM tests This document assumes you have `fuel-core` running on the default port. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.lock new file mode 100644 index 00000000000..2ab463c481c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.lock @@ -0,0 +1,3 @@ +[[package]] +name = "abi_associated_const_access_with_impl_in_contract" +source = "member" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.toml similarity index 51% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.toml rename to test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.toml index 903ebc9ae72..c00f59c6f30 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.toml @@ -2,8 +2,5 @@ authors = ["Fuel Labs "] entry = "main.sw" license = "Apache-2.0" -name = "associated_const_abi_default" +name = "abi_associated_const_access_with_impl_in_contract" implicit-std = false - -[dependencies] -core = { path = "../../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/src/main.sw new file mode 100644 index 00000000000..b4649062db8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/src/main.sw @@ -0,0 +1,17 @@ +contract; + +abi ConstantId { + const ID: u32 = 0; +} + +impl ConstantId for Contract { + const ID: u32 = 1; +} + +fn main() -> u32 { + let _ = ConstantId::ID; + + // Leave enough space to avoid having both `let` lines in both error messages. + + let _ = Contract::ID; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/test.toml new file mode 100644 index 00000000000..db48e353132 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/test.toml @@ -0,0 +1,7 @@ +category = "fail" + +#check: $()let _ = ConstantId::ID; +#nextln: $()Could not find symbol "ID" in this scope. + +#check: $()let _ = Contract::ID; +#nextln: $()Could not find symbol "ID" in this scope. \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_impl/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_impl/src/main.sw index 2035e3c3384..91e13e57868 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_impl/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_impl/src/main.sw @@ -1,14 +1,7 @@ -script; +contract; abi ConstantId { const ID: u32; } -struct Struct {} - -impl ConstantId for Struct { -} - -fn main() -> u32 { - 0 -} +impl ConstantId for Contract { } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_type_ascription/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_type_ascription/src/main.sw index 613b843d780..15a467a4eb8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_type_ascription/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_type_ascription/src/main.sw @@ -1,9 +1,5 @@ -script; +library; abi ConstantId { const ID; } - -fn main() -> u32 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_multiple_same_name/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_multiple_same_name/src/main.sw index 80a9d25d197..8801bf519cd 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_multiple_same_name/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_multiple_same_name/src/main.sw @@ -1,10 +1,6 @@ -script; +library; abi ConstantId { const ID: u32; const ID: u32; } - -fn main() -> u32 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob/json_abi_oracle.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob/json_abi_oracle.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.lock index d3ad4d4bee5..238aada9097 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.lock @@ -1,13 +1,8 @@ [[package]] -name = 'array_oob_global_const_index' -source = 'member' -dependencies = ['std'] +name = "array_oob_global_const_index" +source = "member" +dependencies = ["core"] [[package]] -name = 'core' -source = 'path+from-root-FA9005293D2605B5' - -[[package]] -name = 'std' -source = 'path+from-root-FA9005293D2605B5' -dependencies = ['core'] +name = "core" +source = "path+from-root-FA9005293D2605B5" diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.toml index 7e92ee3dd54..3c68b278199 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.toml @@ -3,6 +3,7 @@ authors = ["Fuel Labs "] license = "Apache-2.0" name = "array_oob_global_const_index" entry = "main.sw" +implicit-std = false [dependencies] -std = { path = "../../../reduced_std_libs/sway-lib-std-assert" } +core = { path = "../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/json_abi_oracle.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/json_abi_oracle.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/src/main.sw index 50e9afafcd5..009ccdb0ee5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/src/main.sw @@ -1,9 +1,9 @@ script; -const i: u64 = 4; +const I: u64 = 4; fn main() -> u64 { // index out of bounds: the length is 3 but the index is 4 let ary = [1, 2, 3]; - ary[i] + ary[I] } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.lock deleted file mode 100644 index 74d829edea7..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.lock +++ /dev/null @@ -1,16 +0,0 @@ -[[package]] -name = "const-instead-of-let" -source = "member" -dependencies = [ - "core", - "std", -] - -[[package]] -name = "core" -source = "path+from-root-8953E158C7D5F73E" - -[[package]] -name = "std" -source = "path+from-root-8953E158C7D5F73E" -dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/json_abi_oracle.json deleted file mode 100644 index ad50b55d54c..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/json_abi_oracle.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "configurables": [], - "functions": [ - { - "attributes": null, - "inputs": [], - "name": "main", - "output": { - "name": "", - "type": 0, - "typeArguments": null - } - } - ], - "loggedTypes": [], - "messagesTypes": [], - "types": [ - { - "components": null, - "type": "u64", - "typeId": 0, - "typeParameters": null - } - ] -} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.lock index e1a82f95453..2814fca6639 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.lock @@ -1,8 +1,3 @@ [[package]] name = "const_eval_bad_struct_with_return" source = "member" -dependencies = ["core"] - -[[package]] -name = "core" -source = "path+from-root-154BF654D5BA1912" diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.toml index ee771c3e808..02811d183f4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.toml @@ -4,6 +4,3 @@ entry = "main.sw" license = "Apache-2.0" name = "const_eval_bad_struct_with_return" implicit-std = false - -[dependencies] -core = { path = "../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/src/main.sw index 8d8712ffbd3..940865f0672 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/src/main.sw @@ -1,4 +1,4 @@ -script; +library; struct MyStruct { x: u64 @@ -18,7 +18,3 @@ const B: MyStruct = MyStruct { 1 } }; - -fn main() -> u64 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/Forc.lock similarity index 52% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.lock rename to test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/Forc.lock index 7a21e06dfe5..8926b1a0f1e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/Forc.lock @@ -1,8 +1,8 @@ [[package]] -name = "const_decl_literal" +name = "const_instead_of_let" source = "member" dependencies = ["core"] [[package]] name = "core" -source = "path+from-root-CF582537254C5032" +source = "path+from-root-9DAB4ED88942C556" diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/Forc.toml similarity index 62% rename from test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.toml rename to test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/Forc.toml index da772329ce5..59e1cad431a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/Forc.toml @@ -2,8 +2,8 @@ authors = ["Fuel Labs "] entry = "main.sw" license = "Apache-2.0" -name = "const-instead-of-let" +name = "const_instead_of_let" +implicit-std = false [dependencies] core = { path = "../../../../../../sway-lib-core" } -std = { path = "../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/src/main.sw similarity index 81% rename from test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/src/main.sw rename to test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/src/main.sw index 4626eaf81c9..ed327ce6488 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/src/main.sw @@ -12,6 +12,5 @@ pub fn main() { let contract_1 = abi(Abi1, b256::min()); const INVALID_CONST = contract_1.foo(); let contract_2 = abi(Abi2, INVALID_CONST); - let invalid = contract_2.bar(); - log(invalid); + let _ = contract_2.bar(); } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/test.toml similarity index 81% rename from test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/test.toml rename to test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/test.toml index f6e31892d43..437aba233ee 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_instead_of_let/test.toml @@ -1,7 +1,6 @@ category = "fail" # check: $()error -# check: const-instead-of-let/src/main.sw:13 # check: $()const INVALID_CONST = contract_1.foo(); # nextln: $()Could not evaluate initializer to a const declaration. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/const_top_level_no_expr/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/const_top_level_no_expr/src/main.sw index eea10258c1c..2bf19b3ff3f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/const_top_level_no_expr/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/const_top_level_no_expr/src/main.sw @@ -1,7 +1,3 @@ -script; +library; const X; - -fn main() -> u64 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_impl/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_impl/src/main.sw index 6b7dfc50141..601c07bc4d7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_impl/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_impl/src/main.sw @@ -1,14 +1,9 @@ -script; +library; trait ConstantId { const ID: u32; } -struct Struct {} +struct Struct { } -impl ConstantId for Struct { -} - -fn main() -> u32 { - 0 -} +impl ConstantId for Struct { } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_type_ascription/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_type_ascription/src/main.sw index 7e454f784a2..4d9719e8e0e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_type_ascription/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_missing_type_ascription/src/main.sw @@ -1,9 +1,5 @@ -script; +library; trait ConstantId { const ID; } - -fn main() -> u32 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_multiple_same_name/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_multiple_same_name/src/main.sw index c752354e9f5..e20c4016b48 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_multiple_same_name/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/trait_associated_const_multiple_same_name/src/main.sw @@ -1,10 +1,6 @@ -script; +library; trait ConstantId { const ID: u32; const ID: u32; } - -fn main() -> u32 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.lock index dd9b0922b9e..686cc4d810c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.lock @@ -1,8 +1,13 @@ [[package]] name = "associated_const_abi" source = "member" -dependencies = ["core"] +dependencies = ["std"] [[package]] name = "core" source = "path+from-root-A4B13C912574D35A" + +[[package]] +name = "std" +source = "path+from-root-A4B13C912574D35A" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.toml index 9f03e7e8ee4..9064f17054d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/Forc.toml @@ -6,4 +6,4 @@ name = "associated_const_abi" implicit-std = false [dependencies] -core = { path = "../../../../../../../sway-lib-core" } +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/src/main.sw index a4259799284..4486078f32b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/src/main.sw @@ -1,18 +1,118 @@ -script; +contract; abi A { - const ID: u32; - fn foo() -> u32; + const A_WITH_DEFAULT: u32 = 3; + // TODO: Uncomment this case when https://github.com/FuelLabs/sway/issues/6348 is fixed. + // const A_NO_DEFAULT: u32; + const COMMON_1: u32 = 5; + // TODO: Uncomment this version (without default) when https://github.com/FuelLabs/sway/issues/6348 is fixed. + // const COMMON_2: u32; + const COMMON_2: u32 = 111; // TODO: Remove this one in favor of the one without default. + + fn a_with_default() -> u32; + // fn a_no_default() -> u32; + + fn common_1() -> u32; + fn common_2() -> u32; +} { + // TODO: Uncomment this case once `expression_variant::find_const_decl_from_impl` is implemented. + // fn a_implemented_with_default() -> u32 { + // Self::A_WITH_DEFAULT + // } + + // fn a_implemented_no_default() -> u32 { + // Self::A_NO_DEFAULT + // } + + // fn a_implemented_common_1() -> u32 { + // Self::COMMON_1 + // } + + // fn a_implemented_common_2() -> u32 { + // Self::COMMON_2 + // } +} + +abi B { + // TODO: Uncomment this version (without default) when https://github.com/FuelLabs/sway/issues/6348 is fixed. + // const COMMON_1: u32; + const COMMON_1: u32 = 111; // TODO: Remove this one in favor of the one without default. + const COMMON_2: u32 = 7; + + fn common_1() -> u32; + fn common_2() -> u32; +} { + // TODO: Uncomment this case once `expression_variant::find_const_decl_from_impl` is implemented. + // fn b_implemented_common_1() -> u32 { + // Self::COMMON_1 + // } + + // fn b_implemented_common_2() -> u32 { + // Self::COMMON_2 + // } } impl A for Contract { - const ID: u32 = 1; + const A_WITH_DEFAULT: u32 = 13; + // const A_NO_DEFAULT: u32 = 133; + const COMMON_1: u32 = 15; + const COMMON_2: u32 = 155; + + fn a_with_default() -> u32 { + Self::A_WITH_DEFAULT + } + + // fn a_no_default() -> u32 { + // Self::A_NO_DEFAULT + // } + + fn common_1() -> u32 { + Self::COMMON_1 + } - fn foo() -> u32 { - Self::ID - } + fn common_2() -> u32 { + Self::COMMON_2 + } } -fn main() -> u32 { - 0 +impl B for Contract { + const COMMON_1: u32 = 177; + const COMMON_2: u32 = 17; + + fn common_1() -> u32 { + Self::COMMON_1 + } + + fn common_2() -> u32 { + Self::COMMON_2 + } +} + +#[test] +fn test() { + let a = abi(A, CONTRACT_ID); + // TODO: Enable these asserts once these bugs are fixed: + // https://github.com/FuelLabs/sway/issues/6310 + // https://github.com/FuelLabs/sway/issues/6306 + // https://github.com/FuelLabs/sway/issues/6348 + + // assert_eq(13, a.a_with_default()); + // assert_eq(13, a.a_implemented_with_default()); + + // assert_eq(133, a.a_no_default()); + // assert_eq(133, a.a_implemented_no_default()); + + // assert_eq(15, a.common_1()); + // assert_eq(15, a.a_implemented_common_1()); + + // assert_eq(155, a.common_2()); + // assert_eq(155, a.a_implemented_common_2()); + + let b = abi(B, CONTRACT_ID); + + // assert_eq(177, b.common_1()); + // assert_eq(177, b.b_implemented_common_1()); + + // assert_eq(17, b.common_2()); + // assert_eq(17, b.b_implemented_common_2()); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/test.toml index 09a31735c3e..f1958c1b086 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi/test.toml @@ -1,4 +1 @@ -category = "run" -expected_result = { action = "return", value = 0 } -expected_result_new_encoding = { action = "return_data", value = "00000000" } -expected_warnings = 1 +category = "unit_tests_pass" \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.lock deleted file mode 100644 index c5f965e3896..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/Forc.lock +++ /dev/null @@ -1,8 +0,0 @@ -[[package]] -name = "associated_const_abi_default" -source = "member" -dependencies = ["core"] - -[[package]] -name = "core" -source = "path+from-root-4DE28390654F2914" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/src/main.sw deleted file mode 100644 index 5b9afd27fbc..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/src/main.sw +++ /dev/null @@ -1,18 +0,0 @@ -script; - -abi A { - const ID: u32 = 1; - fn foo() -> u32; -} - -impl A for Contract { - const ID: u32 = 2; - - fn foo() -> u32 { - Self::ID - } -} - -fn main() -> u32 { - 0 -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/test.toml deleted file mode 100644 index 09a31735c3e..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_default/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -category = "run" -expected_result = { action = "return", value = 0 } -expected_result_new_encoding = { action = "return_data", value = "00000000" } -expected_warnings = 1 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.lock index 18e62b0e0be..fe7cbd9fc55 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.lock @@ -1,8 +1,13 @@ [[package]] name = "associated_const_abi_multiple" source = "member" -dependencies = ["core"] +dependencies = ["std"] [[package]] name = "core" source = "path+from-root-3E220BDD714ECD9F" + +[[package]] +name = "std" +source = "path+from-root-3E220BDD714ECD9F" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.toml index c4026d220ee..66d92d05cb6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/Forc.toml @@ -6,4 +6,4 @@ name = "associated_const_abi_multiple" implicit-std = false [dependencies] -core = { path = "../../../../../../../sway-lib-core" } +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/src/main.sw index 71a469b7f7b..fa5faf6f660 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/src/main.sw @@ -1,4 +1,4 @@ -script; +contract; abi A { const ID: u32 = 1; @@ -6,26 +6,32 @@ abi A { } impl A for Contract { - const ID: u32 = 2; + const ID: u32 = 2; - fn foo() -> u32 { - Self::ID - } + fn foo() -> u32 { + Self::ID + } } abi B { - const ID: u32 = 1; + const ID: u32 = 3; fn foo() -> u32; } impl B for Contract { - const ID: u32 = 2; + const ID: u32 = 4; - fn foo() -> u32 { - Self::ID - } + fn foo() -> u32 { + Self::ID + } } -fn main() -> u32 { - 0 +// TODO: Enable the asserts or adapt the tests once https://github.com/FuelLabs/sway/issues/6306 is implemented. +#[test] +fn test() { + let a = abi(A, CONTRACT_ID); + // assert_eq(2, a.foo()); + + let b = abi(B, CONTRACT_ID); + // assert_eq(4, b.foo()); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/test.toml index 9652497bdf0..0f3f6d7e866 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_abi_multiple/test.toml @@ -1,4 +1 @@ -category = "run" -expected_result = { action = "return", value = 0 } -expected_result_new_encoding = { action = "return_data", value = "00000000" } -expected_warnings = 2 +category = "unit_tests_pass" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.lock index df47b7d424c..ccad7c90008 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.lock @@ -1,8 +1,13 @@ [[package]] name = "associated_const_impl_multiple" source = "member" -dependencies = ["core"] +dependencies = ["std"] [[package]] name = "core" source = "path+from-root-593E053780B28B13" + +[[package]] +name = "std" +source = "path+from-root-593E053780B28B13" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.toml index c25574ce716..492f8ffe36c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/Forc.toml @@ -6,4 +6,4 @@ name = "associated_const_impl_multiple" implicit-std = false [dependencies] -core = { path = "../../../../../../../sway-lib-core" } +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/src/main.sw index 69e2d6266f5..16b0c0a137f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/src/main.sw @@ -10,6 +10,10 @@ impl Struct { const ID2: u32 = 2; } -fn main() -> u32 { - Struct::ID +fn main() {} + +#[test] +fn test() { + assert_eq(1, Struct::ID); + assert_eq(2, Struct::ID2); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/test.toml index 48bc10d2ed3..f1958c1b086 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_multiple/test.toml @@ -1,4 +1 @@ -category = "run" -expected_result = { action = "return", value = 1 } -expected_result_new_encoding = { action = "return_data", value = "00000001" } -expected_warnings = 3 +category = "unit_tests_pass" \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/src/main.sw index 5a53af0232c..f3ef8fc4816 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/src/main.sw @@ -3,14 +3,27 @@ script; struct Struct { } impl Struct { - const ID: u32 = 1; + const ID: u32 = 3; fn foo(self) -> u32 { Self::ID } } +struct StructOrder { } + +impl StructOrder { + fn foo(self) -> u32 { + Self::ID + } + + // The const declaration comes after the const usage. + const ID: u32 = 5; +} + fn main() -> u32 { let s = Struct {}; - s.foo() + let so = StructOrder {}; + + s.foo() + so.foo() } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/test.toml index 67ab8164b7f..a28e8cf188a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self/test.toml @@ -1,4 +1,4 @@ category = "run" -expected_result = { action = "return", value = 1 } -expected_result_new_encoding = { action = "return_data", value = "00000001" } +expected_result = { action = "return", value = 8 } +expected_result_new_encoding = { action = "return_data", value = "00000008" } expected_warnings = 2 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.lock deleted file mode 100644 index 7b26582f4d1..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.lock +++ /dev/null @@ -1,8 +0,0 @@ -[[package]] -name = "associated_const_impl_self_order" -source = "member" -dependencies = ["core"] - -[[package]] -name = "core" -source = "path+from-root-F5ACA883B083BA7B" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/src/main.sw deleted file mode 100644 index d728467d8c8..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/src/main.sw +++ /dev/null @@ -1,16 +0,0 @@ -script; - -struct Struct { } - -impl Struct { - fn foo(self) -> u32 { - Self::ID - } - - const ID: u32 = 1; -} - -fn main() -> u32 { - let s = Struct {}; - s.foo() -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/test.toml deleted file mode 100644 index 67ab8164b7f..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -category = "run" -expected_result = { action = "return", value = 1 } -expected_result_new_encoding = { action = "return_data", value = "00000001" } -expected_warnings = 2 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.lock index eac1df2527c..26ab8ee77b5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.lock @@ -1,8 +1,13 @@ [[package]] name = "associated_const_trait" source = "member" -dependencies = ["core"] +dependencies = ["std"] [[package]] name = "core" source = "path+from-root-48B1B6A6B3A2C079" + +[[package]] +name = "std" +source = "path+from-root-48B1B6A6B3A2C079" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.toml index ef92e798716..ea18dd79b02 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/Forc.toml @@ -6,4 +6,4 @@ name = "associated_const_trait" implicit-std = false [dependencies] -core = { path = "../../../../../../../sway-lib-core" } +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/main.sw index 0b0a68d9893..1e50dfe0cf4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/main.sw @@ -1,15 +1,106 @@ -script; +library; -trait ConstantId { - const ID: u32; -} +mod traits; + +use traits::*; + +struct Struct { } -struct Struct {} +impl Struct { + const ID: u32 = 3; + + fn foo() -> u32 { + Self::ID + } +} impl ConstantId for Struct { - const ID: u32 = 1; + const ID: u32 = 5; +} + +impl OtherConstantId for Struct { + const ID: u32 = 7; +} + +impl GenericConstantId for Struct { + const ID: u64 = 9; +} + +impl GenericConstantId for Struct { + const ID: bool = true; +} + +impl GenericConstantIdWithDefault for Struct { + const ID: u64 = 11; +} + +impl GenericConstantIdWithDefault for Struct { + const ID: bool = true; +} + +enum Enum { } + +impl Enum { + const ID: u32 = 3; + + // TODO: Uncomment this function once https://github.com/FuelLabs/sway/issues/6344 is fixed. + // fn foo() -> u32 { + // Self::ID + // } } -fn main() -> u32 { - Struct::ID +impl ConstantId for Enum { + const ID: u32 = 5; } + +impl OtherConstantId for Enum { + const ID: u32 = 7; +} + +impl GenericConstantId for Enum { + const ID: u64 = 9; +} + +impl GenericConstantId for Enum { + const ID: bool = true; +} + +impl GenericConstantIdWithDefault for Enum { + const ID: u64 = 11; +} + +impl GenericConstantIdWithDefault for Enum { + const ID: bool = true; +} + +#[test] +fn test_for_structs() { + // TODO: Uncomment this assert once https://github.com/FuelLabs/sway/issues/6345 is fixed. + // assert_eq(3, Struct::ID); + assert_eq(5, ::ID); + assert_eq(7, ::ID); + + // TODO: Uncomment these asserts once https://github.com/FuelLabs/sway/issues/6346 is fixed. + // assert_eq(9, >::ID); + // assert_eq(true, >::ID); + // assert_eq(11, >::ID); + // assert_eq(true, >::ID); + + assert_eq(3, Struct::foo()); +} + + +// TODO: Uncomment this test once https://github.com/FuelLabs/sway/issues/6344 is fixed. +// #[test] +// fn test_for_enums() { +// assert_eq(3, Enum::ID); +// assert_eq(5, ::ID); +// assert_eq(7, ::ID); + +// assert_eq(9, >::ID); +// assert_eq(true, >::ID); +// assert_eq(11, >::ID); +// assert_eq(true, >::ID); + +// assert_eq(3, Enum::foo()); +// } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/traits.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/traits.sw new file mode 100644 index 00000000000..7ede1154c2b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/src/traits.sw @@ -0,0 +1,29 @@ +library; + +pub trait ConstantId { + const ID: u32; +} + +pub trait OtherConstantId { + const ID: u32; +} + +pub trait GenericConstantId { + const ID: T; +} + +pub trait Default { + fn default() -> Self; +} + +impl Default for u64 { + fn default() -> Self { 0 } +} + +impl Default for bool { + fn default() -> Self { false } +} + +pub trait GenericConstantIdWithDefault where T: Default { + const ID: T = T::default(); +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/test.toml index 0f3dfe2219a..f1958c1b086 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait/test.toml @@ -1,4 +1 @@ -category = "run" -expected_result = { action = "return", value = 1 } -expected_result_new_encoding = { action = "return_data", value = "00000001" } -expected_warnings = 1 +category = "unit_tests_pass" \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.lock deleted file mode 100644 index 54b6b84c39a..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.lock +++ /dev/null @@ -1,8 +0,0 @@ -[[package]] -name = "associated_const_trait_const" -source = "member" -dependencies = ["core"] - -[[package]] -name = "core" -source = "path+from-root-D50E1F3A87CBFC67" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.toml deleted file mode 100644 index ea850965191..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/Forc.toml +++ /dev/null @@ -1,9 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "associated_const_trait_const" -implicit-std = false - -[dependencies] -core = { path = "../../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/src/main.sw deleted file mode 100644 index 5d7da8079fa..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/src/main.sw +++ /dev/null @@ -1,15 +0,0 @@ -script; - -trait T { - const C: bool; -} - -struct S {} - -impl T for S { - const C: bool = true; -} - -fn main() -> bool { - S::C -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/test.toml deleted file mode 100644 index 96a7137e198..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_const/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -category = "run" -expected_result = { action = "return", value = 1 } -expected_result_new_encoding = { action = "return_data", value = "01" } -expected_warnings = 1 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.lock index bfb6de86577..ecb419b2e6e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.lock @@ -1,8 +1,13 @@ [[package]] name = "associated_const_trait_default" source = "member" -dependencies = ["core"] +dependencies = ["std"] [[package]] name = "core" source = "path+from-root-78BED7E0142ECED8" + +[[package]] +name = "std" +source = "path+from-root-78BED7E0142ECED8" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.toml index d6142569826..a41ff7b53f0 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/Forc.toml @@ -7,4 +7,4 @@ implicit-std = false [dependencies] -core = { path = "../../../../../../../sway-lib-core" } +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/src/main.sw index f29057fb6d1..b61e6f93404 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/src/main.sw @@ -1,7 +1,7 @@ script; trait ConstantId { - const ID: u32 = 1; + const ID: u32 = 7; } struct Struct {} @@ -10,6 +10,10 @@ impl ConstantId for Struct { const ID: u32 = 5; } -fn main() -> u32 { - Struct::ID +fn main() { } + +#[test] +fn test() { + assert_eq(5, Struct::ID); + assert_eq(5, ::ID); } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/test.toml index ff9771a91e5..f1958c1b086 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_trait_default/test.toml @@ -1,4 +1 @@ -category = "run" -expected_result = { action = "return", value = 5 } -expected_result_new_encoding = { action = "return_data", value = "00000005" } -expected_warnings = 1 +category = "unit_tests_pass" \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw index 08aec64bda0..192fa6ffda7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/main.sw @@ -3,6 +3,7 @@ script; mod heaven; mod earth; mod hell; +mod moon; use heaven::UNKNOWN_DEITY_VALUE; use earth::MAN; @@ -19,8 +20,12 @@ fn god() -> u64 { use heaven::MONKEYS_GONE_HERE; fn main() -> bool { - if god() == 7 { - MONKEYS_GONE_HERE + if moon::WE_WERE_NEVER_HERE { + if god() == 7 { + MONKEYS_GONE_HERE + } else { + false + } } else { false } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/moon.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/moon.sw new file mode 100644 index 00000000000..bb339df8151 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_in_library/src/moon.sw @@ -0,0 +1,3 @@ +library; + +pub const WE_WERE_NEVER_HERE: bool = true; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.toml deleted file mode 100644 index 02d72431094..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -license = "Apache-2.0" -name = "const_decl_literal" -entry = "main.sw" - -[dependencies] -core = { path = "../../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle.json deleted file mode 100644 index ad50b55d54c..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "configurables": [], - "functions": [ - { - "attributes": null, - "inputs": [], - "name": "main", - "output": { - "name": "", - "type": 0, - "typeArguments": null - } - } - ], - "loggedTypes": [], - "messagesTypes": [], - "types": [ - { - "components": null, - "type": "u64", - "typeId": 0, - "typeParameters": null - } - ] -} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle_new_encoding.json deleted file mode 100644 index 068da3305ab..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/json_abi_oracle_new_encoding.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "configurables": [], - "encoding": "1", - "functions": [ - { - "attributes": null, - "inputs": [], - "name": "main", - "output": { - "name": "", - "type": 0, - "typeArguments": null - } - } - ], - "loggedTypes": [], - "messagesTypes": [], - "types": [ - { - "components": null, - "type": "u64", - "typeId": 0, - "typeParameters": null - } - ] -} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/src/main.sw deleted file mode 100644 index 6cb7e968704..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/src/main.sw +++ /dev/null @@ -1,8 +0,0 @@ -script; - -const GLOBAL_VAL: u64 = 99; - -fn main() -> u64 { - const LOCAL_VAL = 1; - GLOBAL_VAL + LOCAL_VAL -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/test.toml deleted file mode 100644 index 156a03feb89..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_literal/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -category = "run" -expected_result = { action = "return", value = 100 } -expected_result_new_encoding = { action = "return_data", value = "0000000000000064" } -validate_abi = true diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.lock deleted file mode 100644 index 49639c978a3..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.lock +++ /dev/null @@ -1,13 +0,0 @@ -[[package]] -name = 'const_decl_with_call_path' -source = 'member' -dependencies = ['std'] - -[[package]] -name = 'core' -source = 'path+from-root-8403A6B918C3B0C1' - -[[package]] -name = 'std' -source = 'path+from-root-8403A6B918C3B0C1' -dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.toml deleted file mode 100644 index 0c9f0acbdee..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "const_decl_with_call_path" - -[dependencies] -std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle.json deleted file mode 100644 index ad50b55d54c..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "configurables": [], - "functions": [ - { - "attributes": null, - "inputs": [], - "name": "main", - "output": { - "name": "", - "type": 0, - "typeArguments": null - } - } - ], - "loggedTypes": [], - "messagesTypes": [], - "types": [ - { - "components": null, - "type": "u64", - "typeId": 0, - "typeParameters": null - } - ] -} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle_new_encoding.json deleted file mode 100644 index 068da3305ab..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/json_abi_oracle_new_encoding.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "configurables": [], - "encoding": "1", - "functions": [ - { - "attributes": null, - "inputs": [], - "name": "main", - "output": { - "name": "", - "type": 0, - "typeArguments": null - } - } - ], - "loggedTypes": [], - "messagesTypes": [], - "types": [ - { - "components": null, - "type": "u64", - "typeId": 0, - "typeParameters": null - } - ] -} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw deleted file mode 100644 index 74a0f848b79..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/main.sw +++ /dev/null @@ -1,13 +0,0 @@ -script; - -mod test_lib; - -fn main() -> u64 { - let x = test_lib::NUMBER; - let zero = b256::zero(); - let base_asset_id = AssetId::base(); - let base_asset_id_b256: b256 = base_asset_id.into(); - assert(zero == 0x0000000000000000000000000000000000000000000000000000000000000000); - assert(base_asset_id_b256 == zero); - x -} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw deleted file mode 100644 index 2bdbcad65a1..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/src/test_lib.sw +++ /dev/null @@ -1,3 +0,0 @@ -library; - -pub const NUMBER: u64 = 10; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/test.toml deleted file mode 100644 index 4ce10cccb80..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_with_call_path/test.toml +++ /dev/null @@ -1,4 +0,0 @@ -category = "run" -expected_result = { action = "return", value = 10 } -expected_result_new_encoding = { action = "return_data", value = "000000000000000A" } -validate_abi = true diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.lock new file mode 100644 index 00000000000..9dfb581aa37 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "contract_implements_multiple_abis_with_same_methods" +source = "member" +dependencies = ["std"] + +[[package]] +name = "core" +source = "path+from-root-3480CC9F7FAAA8DF" + +[[package]] +name = "std" +source = "path+from-root-3480CC9F7FAAA8DF" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.toml similarity index 50% rename from test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.toml rename to test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.toml index 2492c0bf71b..5012bd4bf5e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/associated_const_impl_self_order/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/Forc.toml @@ -2,8 +2,8 @@ authors = ["Fuel Labs "] entry = "main.sw" license = "Apache-2.0" -name = "associated_const_impl_self_order" +name = "contract_implements_multiple_abis_with_same_methods" implicit-std = false [dependencies] -core = { path = "../../../../../../../sway-lib-core" } +std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/src/main.sw new file mode 100644 index 00000000000..a2f67f680bc --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/src/main.sw @@ -0,0 +1,31 @@ +contract; + +abi A { + fn foo() -> u64; +} + +abi B { + fn foo() -> u64; +} + +impl A for Contract { + fn foo() -> u64 { + 3 + } +} + +impl B for Contract { + fn foo() -> u64 { + 5 + } +} + +// TODO: Enable the asserts or adapt the tests once https://github.com/FuelLabs/sway/issues/6306 is implemented. +#[test] +fn test() { + let a = abi(A, CONTRACT_ID); + // assert_eq(3, a.foo()); + + let b = abi(B, CONTRACT_ID); + // assert_eq(5, b.foo()); +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/test.toml new file mode 100644 index 00000000000..0f3f6d7e866 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/contract_implements_multiple_abis_with_same_methods/test.toml @@ -0,0 +1 @@ +category = "unit_tests_pass" diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle.json index 03b2f150939..4df01e84191 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle.json @@ -12,7 +12,40 @@ } } ], - "loggedTypes": [], + "loggedTypes": [ + { + "logId": "1515152261580153489", + "loggedType": { + "name": "", + "type": 3, + "typeArguments": null + } + }, + { + "logId": "15520703124961489725", + "loggedType": { + "name": "", + "type": 2, + "typeArguments": null + } + }, + { + "logId": "2992671284987479467", + "loggedType": { + "name": "", + "type": 1, + "typeArguments": null + } + }, + { + "logId": "14454674236531057292", + "loggedType": { + "name": "", + "type": 4, + "typeArguments": null + } + } + ], "messagesTypes": [], "types": [ { @@ -20,6 +53,30 @@ "type": "bool", "typeId": 0, "typeParameters": null + }, + { + "components": null, + "type": "u16", + "typeId": 1, + "typeParameters": null + }, + { + "components": null, + "type": "u32", + "typeId": 2, + "typeParameters": null + }, + { + "components": null, + "type": "u64", + "typeId": 3, + "typeParameters": null + }, + { + "components": null, + "type": "u8", + "typeId": 4, + "typeParameters": null } ] } \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle_new_encoding.json index b89d516ddd1..d7fc3a10846 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/json_abi_oracle_new_encoding.json @@ -13,7 +13,40 @@ } } ], - "loggedTypes": [], + "loggedTypes": [ + { + "logId": "1515152261580153489", + "loggedType": { + "name": "", + "type": 3, + "typeArguments": null + } + }, + { + "logId": "15520703124961489725", + "loggedType": { + "name": "", + "type": 2, + "typeArguments": null + } + }, + { + "logId": "2992671284987479467", + "loggedType": { + "name": "", + "type": 1, + "typeArguments": null + } + }, + { + "logId": "14454674236531057292", + "loggedType": { + "name": "", + "type": 4, + "typeArguments": null + } + } + ], "messagesTypes": [], "types": [ { @@ -21,6 +54,30 @@ "type": "bool", "typeId": 0, "typeParameters": null + }, + { + "components": null, + "type": "u16", + "typeId": 1, + "typeParameters": null + }, + { + "components": null, + "type": "u32", + "typeId": 2, + "typeParameters": null + }, + { + "components": null, + "type": "u64", + "typeId": 3, + "typeParameters": null + }, + { + "components": null, + "type": "u8", + "typeId": 4, + "typeParameters": null } ] } \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/src/main.sw index 855f039ded8..a9cb3b76873 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/numeric_constants/src/main.sw @@ -1,19 +1,19 @@ script; fn main() -> bool { - assert(u64::max() == 18446744073709551615u64); - assert(u64::min() == 0u64); - assert(u32::max() == 4294967295u32); - assert(u32::min() == 0u32); - assert(u16::max() == 65535u16); - assert(u16::min() == 0u16); - assert(u8::max() == 255u8); - assert(u8::min() == 0u8); + assert_eq(u64::max(), 18446744073709551615u64); + assert_eq(u64::min(), 0u64); + assert_eq(u32::max(), 4294967295u32); + assert_eq(u32::min(), 0u32); + assert_eq(u16::max(), 65535u16); + assert_eq(u16::min(), 0u16); + assert_eq(u8::max(), 255u8); + assert_eq(u8::min(), 0u8); - assert(u64::bits() == 64u64); - assert(u32::bits() == 32u64); - assert(u16::bits() == 16u64); - assert(u8::bits() == 8u64); + assert_eq(u64::bits(), 64u64); + assert_eq(u32::bits(), 32u64); + assert_eq(u16::bits(), 16u64); + assert_eq(u8::bits(), 8u64); true }