Skip to content

Commit

Permalink
Add a test to verify the order of Option variants (FuelLabs#2334)
Browse files Browse the repository at this point in the history
Added test to check for none in storagemap
  • Loading branch information
Braqzen authored Jul 15, 2022
1 parent 717ca97 commit 01651cb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/src/sdk-harness/test_projects/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod exponentiation;
mod hashing;
mod logging;
mod methods;
mod option_field_order;
mod predicate_data_simple;
mod predicate_data_struct;
mod reentrancy;
Expand Down
14 changes: 14 additions & 0 deletions test/src/sdk-harness/test_projects/option_field_order/Forc.lock
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']
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 test/src/sdk-harness/test_projects/option_field_order/mod.rs
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 test/src/sdk-harness/test_projects/option_field_order/src/main.sw
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()
}
}

0 comments on commit 01651cb

Please sign in to comment.