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.
Add a test to verify the order of
Option
variants (FuelLabs#2334)
Added test to check for none in storagemap
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
test/src/sdk-harness/test_projects/option_field_order/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-9CF9D5A3681400C0' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'option_field_order' | ||
source = 'root' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-9CF9D5A3681400C0' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_projects/option_field_order/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 = "option_field_order" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../sway-lib-std" } |
31 changes: 31 additions & 0 deletions
31
test/src/sdk-harness/test_projects/option_field_order/mod.rs
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,31 @@ | ||
use fuels::prelude::*; | ||
|
||
abigen!( | ||
MyContract, | ||
"test_projects/option_field_order/out/debug/option_field_order-abi.json" | ||
); | ||
|
||
#[tokio::test] | ||
async fn default_is_none() { | ||
let instance = setup().await; | ||
assert!(instance.is_none().call().await.unwrap().value); | ||
} | ||
|
||
async fn setup() -> MyContract { | ||
let wallet = launch_provider_and_get_wallet().await; | ||
|
||
let id = Contract::deploy( | ||
"test_projects/option_field_order/out/debug/option_field_order.bin", | ||
&wallet, | ||
TxParameters::default(), | ||
StorageConfiguration::with_storage_path(Some( | ||
"test_projects/option_field_order/out/debug/option_field_order-storage_slots.json".to_string(), | ||
)), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
let instance = MyContract::new(id.to_string(), wallet); | ||
|
||
instance | ||
} |
23 changes: 23 additions & 0 deletions
23
test/src/sdk-harness/test_projects/option_field_order/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,23 @@ | ||
contract; | ||
|
||
use std::{option::Option, storage::StorageMap}; | ||
|
||
struct Data { | ||
value: u64 | ||
} | ||
|
||
storage { | ||
value: StorageMap<u64, Option<Data>> = StorageMap {} | ||
} | ||
|
||
abi MyContract { | ||
#[storage(read)] | ||
fn is_none() -> bool; | ||
} | ||
|
||
impl MyContract for Contract { | ||
#[storage(read)] | ||
fn is_none() -> bool { | ||
storage.value.get(0).is_none() | ||
} | ||
} |