-
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.
Move std-lib
StorageKey
tests to in-language tests (#6363)
## Description Tests in the std-lib were moved to the in-language test programs. The following additional tests were also added: - Added tests for `slot()` - Added tests for `field_id()` - Added tests for `offset()` - Added tests for `zero()` - Added tests for `is_zero()` ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] 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. - [x] 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. --------- Co-authored-by: IGI-111 <[email protected]>
- Loading branch information
Showing
4 changed files
with
132 additions
and
43 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
8 changes: 8 additions & 0 deletions
8
test/src/in_language_tests/test_programs/storage_key_inline_tests/Forc.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,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "storage_key_inline_tests" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../sway-lib-std" } |
123 changes: 123 additions & 0 deletions
123
test/src/in_language_tests/test_programs/storage_key_inline_tests/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,123 @@ | ||
library; | ||
|
||
#[test] | ||
fn storage_key_slot() { | ||
let key_1 = StorageKey::<u64>::new(b256::min(), u64::zero(), b256::zero()); | ||
assert(key_1.slot() == b256::min()); | ||
|
||
let key_2 = StorageKey::<u64>::new( | ||
0x0000000000000000000000000000000000000000000000000000000000000001, | ||
u64::zero(), | ||
b256::zero(), | ||
); | ||
assert( | ||
key_2 | ||
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
|
||
let key_3 = StorageKey::<u64>::new(b256::max(), u64::zero(), b256::zero()); | ||
assert(key_3.slot() == b256::max()); | ||
} | ||
|
||
#[test] | ||
fn storage_key_offset() { | ||
let key_1 = StorageKey::<u64>::new(b256::zero(), u64::min(), b256::zero()); | ||
assert(key_1.offset() == u64::min()); | ||
|
||
let key_2 = StorageKey::<u64>::new(b256::zero(), 1, b256::zero()); | ||
assert(key_2.offset() == 1); | ||
|
||
let key_3 = StorageKey::<u64>::new(b256::zero(), u64::max(), b256::zero()); | ||
assert(key_3.offset() == u64::max()); | ||
} | ||
|
||
#[test] | ||
fn storage_key_field_id() { | ||
let key_1 = StorageKey::<u64>::new(b256::zero(), u64::zero(), b256::min()); | ||
assert(key_1.field_id() == b256::min()); | ||
|
||
let key_2 = StorageKey::<u64>::new( | ||
b256::zero(), | ||
u64::zero(), | ||
0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
assert( | ||
key_2 | ||
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
|
||
let key_3 = StorageKey::<u64>::new(b256::zero(), u64::zero(), b256::max()); | ||
assert(key_3.field_id() == b256::max()); | ||
} | ||
|
||
#[test] | ||
fn storage_key_new() { | ||
let key = StorageKey::<u64>::new(b256::min(), u64::min(), b256::min()); | ||
assert(key.slot() == b256::min()); | ||
assert(key.offset() == u64::min()); | ||
assert(key.field_id() == b256::min()); | ||
|
||
let key = StorageKey::<u64>::new( | ||
0x0000000000000000000000000000000000000000000000000000000000000001, | ||
1, | ||
0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
assert( | ||
key | ||
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
assert(key.offset() == 1); | ||
assert( | ||
key | ||
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
|
||
let key = StorageKey::<u64>::new(b256::max(), u64::max(), b256::max()); | ||
assert(key.slot() == b256::max()); | ||
assert(key.offset() == u64::max()); | ||
assert(key.field_id() == b256::max()); | ||
} | ||
|
||
#[test] | ||
fn storage_key_zero() { | ||
let storage_key = StorageKey::<u64>::zero(); | ||
assert( | ||
storage_key | ||
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000000, | ||
); | ||
assert(storage_key.offset() == 0); | ||
assert( | ||
storage_key | ||
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000000, | ||
); | ||
} | ||
|
||
#[test] | ||
fn storage_key_is_zero() { | ||
let zero_storage_key = StorageKey::<u64>::zero(); | ||
assert(zero_storage_key.is_zero()); | ||
|
||
let storage_key_2 = StorageKey::<u64>::new( | ||
0x0000000000000000000000000000000000000000000000000000000000000001, | ||
0, | ||
0x0000000000000000000000000000000000000000000000000000000000000000, | ||
); | ||
assert(!storage_key_2.is_zero()); | ||
|
||
let storage_key_3 = StorageKey::<u64>::new( | ||
0x0000000000000000000000000000000000000000000000000000000000000000, | ||
1, | ||
0x0000000000000000000000000000000000000000000000000000000000000000, | ||
); | ||
assert(!storage_key_3.is_zero()); | ||
|
||
let storage_key_4 = StorageKey::<u64>::new( | ||
0x0000000000000000000000000000000000000000000000000000000000000000, | ||
0, | ||
0x0000000000000000000000000000000000000000000000000000000000000001, | ||
); | ||
assert(!storage_key_4.is_zero()); | ||
|
||
let storage_key_5 = StorageKey::<u64>::new(b256::max(), u64::max(), b256::max()); | ||
assert(!storage_key_5.is_zero()); | ||
} |