-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
88 changed files
with
588 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...sts/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[package]] | ||
name = "abi_associated_const_access_with_impl_in_contract" | ||
source = "member" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,5 @@ | |
authors = ["Fuel Labs <[email protected]>"] | ||
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" } |
17 changes: 17 additions & 0 deletions
17
...s/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
7 changes: 7 additions & 0 deletions
7
...sts/test_programs/should_fail/abi_associated_const_access_with_impl_in_contract/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
11 changes: 2 additions & 9 deletions
11
.../src/e2e_vm_tests/test_programs/should_fail/abi_associated_const_missing_impl/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { } |
6 changes: 1 addition & 5 deletions
6
..._tests/test_programs/should_fail/abi_associated_const_missing_type_ascription/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
script; | ||
library; | ||
|
||
abi ConstantId { | ||
const ID; | ||
} | ||
|
||
fn main() -> u32 { | ||
0 | ||
} |
6 changes: 1 addition & 5 deletions
6
...2e_vm_tests/test_programs/should_fail/abi_associated_const_multiple_same_name/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
script; | ||
library; | ||
|
||
abi ConstantId { | ||
const ID: u32; | ||
const ID: u32; | ||
} | ||
|
||
fn main() -> u32 { | ||
0 | ||
} |
1 change: 0 additions & 1 deletion
1
test/src/e2e_vm_tests/test_programs/should_fail/array_oob/json_abi_oracle.json
This file was deleted.
Oops, something went wrong.
15 changes: 5 additions & 10 deletions
15
test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ authors = ["Fuel Labs <[email protected]>"] | |
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" } |
1 change: 0 additions & 1 deletion
1
.../e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/json_abi_oracle.json
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
test/src/e2e_vm_tests/test_programs/should_fail/array_oob_global_const_index/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
} |
16 changes: 0 additions & 16 deletions
16
test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/Forc.lock
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
test/src/e2e_vm_tests/test_programs/should_fail/const-instead-of-let/json_abi_oracle.json
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
test/src/e2e_vm_tests/test_programs/should_fail/const_eval_bad_struct_with_return/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
[[package]] | ||
name = "const_eval_bad_struct_with_return" | ||
source = "member" | ||
dependencies = ["core"] | ||
|
||
[[package]] | ||
name = "core" | ||
source = "path+from-root-154BF654D5BA1912" |
Oops, something went wrong.