forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StorageVec fixing issues and adding features (FuelLabs#2345)
* Added "set" method to storagevec and fixed edgecase for insert * added tuple/arr tests and fixed set * cargo fmt * removed dead files
- Loading branch information
1 parent
95968a0
commit 02b7e94
Showing
43 changed files
with
1,461 additions
and
28 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
2 changes: 2 additions & 0 deletions
2
test/src/sdk-harness/test_artifacts/storage_vec/svec_array/.gitignore
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,2 @@ | ||
out | ||
target |
14 changes: 14 additions & 0 deletions
14
test/src/sdk-harness/test_artifacts/storage_vec/svec_array/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,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-F1A9B05C249770CB' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-F1A9B05C249770CB' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'svec_array' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/storage_vec/svec_array/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 = "svec_array" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
73 changes: 73 additions & 0 deletions
73
test/src/sdk-harness/test_artifacts/storage_vec/svec_array/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,73 @@ | ||
contract; | ||
|
||
use std::{option::Option, result::Result, storage::StorageVec}; | ||
|
||
abi MyContract { | ||
#[storage(read, write)] | ||
fn array_push(value: [u8; 3]); | ||
#[storage(read)] | ||
fn array_get(index: u64) -> [u8; 3]; | ||
#[storage(read, write)] | ||
fn array_pop() -> [u8; 3]; | ||
#[storage(read, write)] | ||
fn array_remove(index: u64) -> [u8; 3]; | ||
#[storage(read, write)] | ||
fn array_swap_remove(index: u64) -> [u8; 3]; | ||
#[storage(read, write)] | ||
fn array_set(index: u64, value: [u8; 3]); | ||
#[storage(read, write)] | ||
fn array_insert(index: u64, value: [u8; 3]); | ||
#[storage(read)] | ||
fn array_len() -> u64; | ||
#[storage(read)] | ||
fn array_is_empty() -> bool; | ||
#[storage(write)] | ||
fn array_clear(); | ||
} | ||
|
||
storage { | ||
my_vec: StorageVec<[u8; 3]> = StorageVec {}, | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read, write)] | ||
fn array_push(value: [u8; 3]) { | ||
storage.my_vec.push(value); | ||
} | ||
#[storage(read)] | ||
fn array_get(index: u64) -> [u8; 3] { | ||
storage.my_vec.get(index).unwrap() | ||
} | ||
#[storage(read, write)] | ||
fn array_pop() -> [u8; 3] { | ||
storage.my_vec.pop().unwrap() | ||
} | ||
#[storage(read, write)] | ||
fn array_remove(index: u64) -> [u8; 3] { | ||
storage.my_vec.remove(index) | ||
} | ||
#[storage(read, write)] | ||
fn array_swap_remove(index: u64) -> [u8; 3] { | ||
storage.my_vec.swap_remove(index) | ||
} | ||
#[storage(read, write)] | ||
fn array_set(index: u64, value: [u8; 3]) { | ||
storage.my_vec.set(index, value); | ||
} | ||
#[storage(read, write)] | ||
fn array_insert(index: u64, value: [u8; 3]) { | ||
storage.my_vec.insert(index, value); | ||
} | ||
#[storage(read)] | ||
fn array_len() -> u64 { | ||
storage.my_vec.len() | ||
} | ||
#[storage(read)] | ||
fn array_is_empty() -> bool { | ||
storage.my_vec.is_empty() | ||
} | ||
#[storage(write)] | ||
fn array_clear() { | ||
storage.my_vec.clear(); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
test/src/sdk-harness/test_artifacts/storage_vec/svec_tuple/.gitignore
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,2 @@ | ||
out | ||
target |
14 changes: 14 additions & 0 deletions
14
test/src/sdk-harness/test_artifacts/storage_vec/svec_tuple/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,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-ADD23FE8604712AD' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-ADD23FE8604712AD' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'svec_tuple' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/storage_vec/svec_tuple/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 = "svec_tuple" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
73 changes: 73 additions & 0 deletions
73
test/src/sdk-harness/test_artifacts/storage_vec/svec_tuple/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,73 @@ | ||
contract; | ||
|
||
use std::{option::Option, result::Result, storage::StorageVec}; | ||
|
||
abi MyContract { | ||
#[storage(read, write)] | ||
fn tuple_push(value: (u8, u8, u8)); | ||
#[storage(read)] | ||
fn tuple_get(index: u64) -> (u8, u8, u8); | ||
#[storage(read, write)] | ||
fn tuple_pop() -> (u8, u8, u8); | ||
#[storage(read, write)] | ||
fn tuple_remove(index: u64) -> (u8, u8, u8); | ||
#[storage(read, write)] | ||
fn tuple_swap_remove(index: u64) -> (u8, u8, u8); | ||
#[storage(read, write)] | ||
fn tuple_set(index: u64, value: (u8, u8, u8)); | ||
#[storage(read, write)] | ||
fn tuple_insert(index: u64, value: (u8, u8, u8)); | ||
#[storage(read)] | ||
fn tuple_len() -> u64; | ||
#[storage(read)] | ||
fn tuple_is_empty() -> bool; | ||
#[storage(write)] | ||
fn tuple_clear(); | ||
} | ||
|
||
storage { | ||
my_vec: StorageVec<(u8, u8, u8)> = StorageVec {}, | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read, write)] | ||
fn tuple_push(value: (u8, u8, u8)) { | ||
storage.my_vec.push(value); | ||
} | ||
#[storage(read)] | ||
fn tuple_get(index: u64) -> (u8, u8, u8) { | ||
storage.my_vec.get(index).unwrap() | ||
} | ||
#[storage(read, write)] | ||
fn tuple_pop() -> (u8, u8, u8) { | ||
storage.my_vec.pop().unwrap() | ||
} | ||
#[storage(read, write)] | ||
fn tuple_remove(index: u64) -> (u8, u8, u8) { | ||
storage.my_vec.remove(index) | ||
} | ||
#[storage(read, write)] | ||
fn tuple_swap_remove(index: u64) -> (u8, u8, u8) { | ||
storage.my_vec.swap_remove(index) | ||
} | ||
#[storage(read, write)] | ||
fn tuple_set(index: u64, value: (u8, u8, u8)) { | ||
storage.my_vec.set(index, value); | ||
} | ||
#[storage(read, write)] | ||
fn tuple_insert(index: u64, value: (u8, u8, u8)) { | ||
storage.my_vec.insert(index, value); | ||
} | ||
#[storage(read)] | ||
fn tuple_len() -> u64 { | ||
storage.my_vec.len() | ||
} | ||
#[storage(read)] | ||
fn tuple_is_empty() -> bool { | ||
storage.my_vec.is_empty() | ||
} | ||
#[storage(write)] | ||
fn tuple_clear() { | ||
storage.my_vec.clear(); | ||
} | ||
} |
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
Oops, something went wrong.