Skip to content

Commit

Permalink
Storage Vector Test Refactor (FuelLabs#4171)
Browse files Browse the repository at this point in the history
## Description

> Note: Part 1 of 3 breakout of PR FuelLabs#3935

This PR refactors the `StorageVec` tests by removing the old test
directory structure and replaces it with a single declarative macro,
`testgen!`, that reduces boilerplate and future maintenance when methods
are added or refactored.

## Checklist

- [✅] I have linked to any relevant issues.
- [✅] 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).
- [✅] 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.
- [✅] 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).
- [✅] I have requested a review from the relevant team or maintainers.
  • Loading branch information
jtriley2p authored Feb 24, 2023
1 parent 8e797a1 commit 6d0ec3e
Show file tree
Hide file tree
Showing 46 changed files with 984 additions and 4,681 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ use std::storage::StorageVec;

abi MyContract {
#[storage(read, write)]
fn array_push(value: [u8; 3]);
#[storage(read)]
fn array_get(index: u64) -> [u8; 3];
fn push(value: [u8; 3]);

#[storage(read, write)]
fn array_pop() -> [u8; 3];
fn pop() -> [u8; 3];

#[storage(read)]
fn get(index: u64) -> [u8; 3];

#[storage(read, write)]
fn array_remove(index: u64) -> [u8; 3];
fn remove(index: u64) -> [u8; 3];

#[storage(read, write)]
fn array_swap_remove(index: u64) -> [u8; 3];
fn swap_remove(index: u64) -> [u8; 3];

#[storage(read, write)]
fn array_set(index: u64, value: [u8; 3]);
fn set(index: u64, value: [u8; 3]);

#[storage(read, write)]
fn array_insert(index: u64, value: [u8; 3]);
fn insert(index: u64, value: [u8; 3]);

#[storage(read)]
fn array_len() -> u64;
fn len() -> u64;

#[storage(read)]
fn array_is_empty() -> bool;
fn is_empty() -> bool;

#[storage(write)]
fn array_clear();
fn clear();
}

storage {
Expand All @@ -31,43 +40,52 @@ storage {

impl MyContract for Contract {
#[storage(read, write)]
fn array_push(value: [u8; 3]) {
fn 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] {
fn pop() -> [u8; 3] {
storage.my_vec.pop().unwrap()
}

#[storage(read)]
fn get(index: u64) -> [u8; 3] {
storage.my_vec.get(index).unwrap()
}

#[storage(read, write)]
fn array_remove(index: u64) -> [u8; 3] {
fn remove(index: u64) -> [u8; 3] {
storage.my_vec.remove(index)
}

#[storage(read, write)]
fn array_swap_remove(index: u64) -> [u8; 3] {
fn swap_remove(index: u64) -> [u8; 3] {
storage.my_vec.swap_remove(index)
}

#[storage(read, write)]
fn array_set(index: u64, value: [u8; 3]) {
fn set(index: u64, value: [u8; 3]) {
storage.my_vec.set(index, value);
}

#[storage(read, write)]
fn array_insert(index: u64, value: [u8; 3]) {
fn insert(index: u64, value: [u8; 3]) {
storage.my_vec.insert(index, value);
}

#[storage(read)]
fn array_len() -> u64 {
fn len() -> u64 {
storage.my_vec.len()
}

#[storage(read)]
fn array_is_empty() -> bool {
fn is_empty() -> bool {
storage.my_vec.is_empty()
}

#[storage(write)]
fn array_clear() {
fn clear() {
storage.my_vec.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ use std::storage::StorageVec;

abi MyContract {
#[storage(read, write)]
fn b256_push(value: b256);
#[storage(read)]
fn b256_get(index: u64) -> b256;
fn push(value: b256);

#[storage(read, write)]
fn b256_pop() -> b256;
fn pop() -> b256;

#[storage(read)]
fn get(index: u64) -> b256;

#[storage(read, write)]
fn b256_remove(index: u64) -> b256;
fn remove(index: u64) -> b256;

#[storage(read, write)]
fn b256_swap_remove(index: u64) -> b256;
fn swap_remove(index: u64) -> b256;

#[storage(read, write)]
fn b256_set(index: u64, value: b256);
fn set(index: u64, value: b256);

#[storage(read, write)]
fn b256_insert(index: u64, value: b256);
fn insert(index: u64, value: b256);

#[storage(read)]
fn b256_len() -> u64;
fn len() -> u64;

#[storage(read)]
fn b256_is_empty() -> bool;
fn is_empty() -> bool;

#[storage(write)]
fn b256_clear();
fn clear();
}

storage {
Expand All @@ -31,43 +40,52 @@ storage {

impl MyContract for Contract {
#[storage(read, write)]
fn b256_push(value: b256) {
fn push(value: b256) {
storage.my_vec.push(value);
}
#[storage(read)]
fn b256_get(index: u64) -> b256 {
storage.my_vec.get(index).unwrap()
}

#[storage(read, write)]
fn b256_pop() -> b256 {
fn pop() -> b256 {
storage.my_vec.pop().unwrap()
}

#[storage(read)]
fn get(index: u64) -> b256 {
storage.my_vec.get(index).unwrap()
}

#[storage(read, write)]
fn b256_remove(index: u64) -> b256 {
fn remove(index: u64) -> b256 {
storage.my_vec.remove(index)
}

#[storage(read, write)]
fn b256_swap_remove(index: u64) -> b256 {
fn swap_remove(index: u64) -> b256 {
storage.my_vec.swap_remove(index)
}

#[storage(read, write)]
fn b256_set(index: u64, value: b256) {
fn set(index: u64, value: b256) {
storage.my_vec.set(index, value);
}

#[storage(read, write)]
fn b256_insert(index: u64, value: b256) {
fn insert(index: u64, value: b256) {
storage.my_vec.insert(index, value);
}

#[storage(read)]
fn b256_len() -> u64 {
fn len() -> u64 {
storage.my_vec.len()
}

#[storage(read)]
fn b256_is_empty() -> bool {
fn is_empty() -> bool {
storage.my_vec.is_empty()
}

#[storage(write)]
fn b256_clear() {
fn clear() {
storage.my_vec.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ use std::storage::StorageVec;

abi MyContract {
#[storage(read, write)]
fn bool_push(value: bool);
#[storage(read)]
fn bool_get(index: u64) -> bool;
fn push(value: bool);

#[storage(read, write)]
fn bool_pop() -> bool;
fn pop() -> bool;

#[storage(read)]
fn get(index: u64) -> bool;

#[storage(read, write)]
fn bool_remove(index: u64) -> bool;
fn remove(index: u64) -> bool;

#[storage(read, write)]
fn bool_swap_remove(index: u64) -> bool;
fn swap_remove(index: u64) -> bool;

#[storage(read, write)]
fn bool_set(index: u64, value: bool);
fn set(index: u64, value: bool);

#[storage(read, write)]
fn bool_insert(index: u64, value: bool);
fn insert(index: u64, value: bool);

#[storage(read)]
fn bool_len() -> u64;
fn len() -> u64;

#[storage(read)]
fn bool_is_empty() -> bool;
fn is_empty() -> bool;

#[storage(write)]
fn bool_clear();
fn clear();
}

storage {
Expand All @@ -31,43 +40,52 @@ storage {

impl MyContract for Contract {
#[storage(read, write)]
fn bool_push(value: bool) {
fn push(value: bool) {
storage.my_vec.push(value);
}
#[storage(read)]
fn bool_get(index: u64) -> bool {
storage.my_vec.get(index).unwrap()
}

#[storage(read, write)]
fn bool_pop() -> bool {
fn pop() -> bool {
storage.my_vec.pop().unwrap()
}

#[storage(read)]
fn get(index: u64) -> bool {
storage.my_vec.get(index).unwrap()
}

#[storage(read, write)]
fn bool_remove(index: u64) -> bool {
fn remove(index: u64) -> bool {
storage.my_vec.remove(index)
}

#[storage(read, write)]
fn bool_swap_remove(index: u64) -> bool {
fn swap_remove(index: u64) -> bool {
storage.my_vec.swap_remove(index)
}

#[storage(read, write)]
fn bool_set(index: u64, value: bool) {
fn set(index: u64, value: bool) {
storage.my_vec.set(index, value);
}

#[storage(read, write)]
fn bool_insert(index: u64, value: bool) {
fn insert(index: u64, value: bool) {
storage.my_vec.insert(index, value);
}

#[storage(read)]
fn bool_len() -> u64 {
fn len() -> u64 {
storage.my_vec.len()
}

#[storage(read)]
fn bool_is_empty() -> bool {
fn is_empty() -> bool {
storage.my_vec.is_empty()
}

#[storage(write)]
fn bool_clear() {
fn clear() {
storage.my_vec.clear();
}
}
Loading

0 comments on commit 6d0ec3e

Please sign in to comment.