From 01651cbdad6daf4c0687e32f9a4047b975342a4d Mon Sep 17 00:00:00 2001 From: Braqzen <103777923+Braqzen@users.noreply.github.com> Date: Fri, 15 Jul 2022 14:11:43 +0100 Subject: [PATCH] Add a test to verify the order of `Option` variants (#2334) Added test to check for none in storagemap --- test/src/sdk-harness/test_projects/harness.rs | 1 + .../option_field_order/Forc.lock | 14 +++++++++ .../option_field_order/Forc.toml | 8 +++++ .../test_projects/option_field_order/mod.rs | 31 +++++++++++++++++++ .../option_field_order/src/main.sw | 23 ++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 test/src/sdk-harness/test_projects/option_field_order/Forc.lock create mode 100644 test/src/sdk-harness/test_projects/option_field_order/Forc.toml create mode 100644 test/src/sdk-harness/test_projects/option_field_order/mod.rs create mode 100644 test/src/sdk-harness/test_projects/option_field_order/src/main.sw diff --git a/test/src/sdk-harness/test_projects/harness.rs b/test/src/sdk-harness/test_projects/harness.rs index 78e97103c4c..05dd561cb45 100644 --- a/test/src/sdk-harness/test_projects/harness.rs +++ b/test/src/sdk-harness/test_projects/harness.rs @@ -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; diff --git a/test/src/sdk-harness/test_projects/option_field_order/Forc.lock b/test/src/sdk-harness/test_projects/option_field_order/Forc.lock new file mode 100644 index 00000000000..369e7e8a4b6 --- /dev/null +++ b/test/src/sdk-harness/test_projects/option_field_order/Forc.lock @@ -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'] diff --git a/test/src/sdk-harness/test_projects/option_field_order/Forc.toml b/test/src/sdk-harness/test_projects/option_field_order/Forc.toml new file mode 100644 index 00000000000..466883f969e --- /dev/null +++ b/test/src/sdk-harness/test_projects/option_field_order/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "option_field_order" + +[dependencies] +std = { path = "../../../../../sway-lib-std" } diff --git a/test/src/sdk-harness/test_projects/option_field_order/mod.rs b/test/src/sdk-harness/test_projects/option_field_order/mod.rs new file mode 100644 index 00000000000..a4dddb5cc5f --- /dev/null +++ b/test/src/sdk-harness/test_projects/option_field_order/mod.rs @@ -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 +} diff --git a/test/src/sdk-harness/test_projects/option_field_order/src/main.sw b/test/src/sdk-harness/test_projects/option_field_order/src/main.sw new file mode 100644 index 00000000000..ca95ccda8fe --- /dev/null +++ b/test/src/sdk-harness/test_projects/option_field_order/src/main.sw @@ -0,0 +1,23 @@ +contract; + +use std::{option::Option, storage::StorageMap}; + +struct Data { + value: u64 +} + +storage { + value: StorageMap> = 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() + } +}