From f617f2d775429072c80ca799cf1d68530fdd31c1 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 20 Apr 2023 14:20:46 +0200 Subject: [PATCH 01/24] adds storage_types contract from https://github.com/paritytech/ink-examples/pull/15 --- integration-tests/storage_types/Cargo.toml | 30 +++ integration-tests/storage_types/lib.rs | 258 +++++++++++++++++++++ 2 files changed, 288 insertions(+) create mode 100755 integration-tests/storage_types/Cargo.toml create mode 100755 integration-tests/storage_types/lib.rs diff --git a/integration-tests/storage_types/Cargo.toml b/integration-tests/storage_types/Cargo.toml new file mode 100755 index 0000000000..c9d6599c2b --- /dev/null +++ b/integration-tests/storage_types/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "storage_types" +version = "1.0.0" +authors = ["Parity Technologies "] +edition = "2021" + +[dependencies] +ink = { version = "4.1", default-features = false } + +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } + +[dev-dependencies] +ink_e2e = { version = "4.1" } + +[lib] +name = "storage_types" +path = "lib.rs" +crate-type = [ + "cdylib", +] + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", +] +ink-as-dependency = [] diff --git a/integration-tests/storage_types/lib.rs b/integration-tests/storage_types/lib.rs new file mode 100755 index 0000000000..e3be9bae51 --- /dev/null +++ b/integration-tests/storage_types/lib.rs @@ -0,0 +1,258 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +#[ink::contract] +mod storage_types { + use ink::prelude::string::String; + use ink::prelude::vec::Vec; + use ink::storage::{traits::ManualKey, Mapping}; + use scale::{Decode, Encode}; + + #[derive(Debug, Decode, Encode)] + #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] + pub enum CustomError { + ErrorWithMessage(String), + } + + #[derive(Clone, Debug, Decode, Default, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub enum EnumWithoutValues { + #[default] + A, + B, + C, + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub enum EnumWithValues { + OneValue(u32), + TwoValues(u32, u32), + ThreeValues(u32, u32, u32), + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct PrimitiveTypes { + bool_value: bool, + enum_without_values: EnumWithoutValues, + enum_with_values: EnumWithValues, + array_value: [u32; 3], + tuple_value: (u32, u32), + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct SignedIntegers { + i128_value_max: i128, + i128_value_min: i128, + i16_value_max: i16, + i16_value_min: i16, + i32_value_max: i32, + i32_value_min: i32, + i64_value_max: i64, + i64_value_min: i64, + i8_value_max: i8, + i8_value_min: i8, + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct SubstrateTypes { + account_id_value: AccountId, + balance_value_max: Balance, + balance_value_min: Balance, + hash_value: Hash, + } + + #[derive(Clone, Debug, Decode, scale::Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct InkPreludeTypes { + string_value: String, + vec_string_value: Vec, + vec_vec_string_value: Vec>, + } + + #[derive(Clone, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(Debug, scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct UnsignedIntegers { + u128_value_max: u128, + u128_value_min: u128, + u16_value_max: u16, + u16_value_min: u16, + u32_value_max: u32, + u32_value_min: u32, + u64_value_max: u64, + u64_value_min: u64, + u8_value_max: u8, + u8_value_min: u8, + } + + #[derive(Debug)] + #[ink::storage_item] + pub struct MappingTypes { + mapping_u128_u128_value: Mapping, + mapping_account_balance_value: Mapping, + mapping_account_hash_value: Mapping, + mapping_account_account_balance_value: Mapping<(AccountId, AccountId), Balance>, + } + + #[ink(storage)] + pub struct StorageTypes { + ink_prelude_types: InkPreludeTypes, + primitive_types: PrimitiveTypes, + signed_integers: SignedIntegers, + substrate_types: SubstrateTypes, + unsigned_integers: UnsignedIntegers, + mapping_account_balance: Mapping>, + } + + impl StorageTypes { + #[ink(constructor)] + pub fn new() -> Self { + // Vectors + let mut vec_string_value: Vec = Vec::new(); + vec_string_value.push(String::from("This is a string")); + vec_string_value.push(String::from("This is another string")); + + let mut vec_vec_string_value: Vec> = Vec::new(); + vec_vec_string_value.push(vec_string_value.clone()); + + let mut vec_vec_string_value: Vec> = Vec::new(); + vec_vec_string_value.push(vec_string_value.clone()); + + // Mappings + let mut mapping_account_balance = Mapping::new(); + mapping_account_balance.insert(AccountId::from([0x01; 32]), &100); + + Self { + unsigned_integers: UnsignedIntegers { + u128_value_max: u128::MAX, + u128_value_min: u128::MIN, + u16_value_max: u16::MAX, + u16_value_min: u16::MIN, + u32_value_max: u32::MAX, + u32_value_min: u32::MIN, + u64_value_max: u64::MAX, + u64_value_min: u64::MIN, + u8_value_max: u8::MAX, + u8_value_min: u8::MIN, + }, + signed_integers: SignedIntegers { + i128_value_max: i128::MAX, + i128_value_min: i128::MIN, + i16_value_max: i16::MAX, + i16_value_min: i16::MIN, + i32_value_max: i32::MAX, + i32_value_min: i32::MIN, + i64_value_max: i64::MAX, + i64_value_min: i64::MIN, + i8_value_max: i8::MAX, + i8_value_min: i8::MIN, + }, + ink_prelude_types: InkPreludeTypes { + string_value: String::from("This is a string"), + vec_string_value, + vec_vec_string_value, + }, + primitive_types: PrimitiveTypes { + bool_value: true, + enum_with_values: EnumWithValues::ThreeValues(1, 2, 3), + enum_without_values: EnumWithoutValues::A, + array_value: [3, 2, 1], + tuple_value: (7, 8), + }, + substrate_types: SubstrateTypes { + account_id_value: AccountId::from([0x00; 32]), + balance_value_max: Balance::MAX, + balance_value_min: Balance::MIN, + hash_value: Hash::from([0x00; 32]), + }, + mapping_account_balance, + } + } + + #[ink(message)] + pub fn get_unsigned_integers(&self) -> UnsignedIntegers { + self.unsigned_integers.clone() + } + + #[ink(message)] + pub fn get_signed_integers(&self) -> SignedIntegers { + self.signed_integers.clone() + } + + #[ink(message)] + pub fn get_ink_prelude_types(&self) -> InkPreludeTypes { + self.ink_prelude_types.clone() + } + + #[ink(message)] + pub fn get_substrate_types(&self) -> SubstrateTypes { + self.substrate_types.clone() + } + + #[ink(message)] + pub fn get_primitive_types(&self) -> PrimitiveTypes { + self.primitive_types.clone() + } + + #[ink(message)] + pub fn get_option_some(&self) -> Option<()> { + Some(()) + } + + #[ink(message)] + pub fn get_option_none(&self) -> Option<()> { + None + } + + #[ink(message)] + pub fn get_result_ok(&self) -> Result<(), CustomError> { + Ok(()) + } + + #[ink(message)] + pub fn get_result_error(&self) -> Result<(), CustomError> { + Err(CustomError::ErrorWithMessage(String::from( + "This is the Error Message.", + ))) + } + + #[ink(message)] + pub fn get_panic(&self) -> Result<(), ()> { + panic!("This is the Panic message.") + } + + #[ink(message)] + pub fn get_mapping_account_balance( + &self, + account_id: AccountId, + ) -> Option { + self.mapping_account_balance.get(account_id) + } + } + + #[cfg(test)] + mod tests {} +} From dfc9e5a185b05433878165db2f0797d82cd8efc8 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 20 Apr 2023 15:44:39 +0200 Subject: [PATCH 02/24] renames folder --- .../{storage_types => storage-types}/Cargo.toml | 0 integration-tests/{storage_types => storage-types}/lib.rs | 5 +++++ 2 files changed, 5 insertions(+) rename integration-tests/{storage_types => storage-types}/Cargo.toml (100%) rename integration-tests/{storage_types => storage-types}/lib.rs (97%) diff --git a/integration-tests/storage_types/Cargo.toml b/integration-tests/storage-types/Cargo.toml similarity index 100% rename from integration-tests/storage_types/Cargo.toml rename to integration-tests/storage-types/Cargo.toml diff --git a/integration-tests/storage_types/lib.rs b/integration-tests/storage-types/lib.rs similarity index 97% rename from integration-tests/storage_types/lib.rs rename to integration-tests/storage-types/lib.rs index e3be9bae51..d15d51a511 100755 --- a/integration-tests/storage_types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -1,3 +1,8 @@ +//! # Integration Test for Storage Types +//! +//! This contract is made to showcase all of ink!'s storage types. +//! With this the proper decoding of the storage types can be tested. + #![cfg_attr(not(feature = "std"), no_std)] #[ink::contract] From 23b1592f16fd9e6a18e040a313612a9b58991bac Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 20 Apr 2023 15:56:32 +0200 Subject: [PATCH 03/24] aligns contract name with folder name --- integration-tests/storage-types/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/storage-types/Cargo.toml b/integration-tests/storage-types/Cargo.toml index c9d6599c2b..184ffa7e8d 100755 --- a/integration-tests/storage-types/Cargo.toml +++ b/integration-tests/storage-types/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "storage_types" +name = "storage-types" version = "1.0.0" authors = ["Parity Technologies "] edition = "2021" From c1a2da76736fbf9ea05bc4b4d89685ecad2f443e Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 21 Apr 2023 10:19:13 +0200 Subject: [PATCH 04/24] resolves clippy recommendations --- integration-tests/storage-types/lib.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index d15d51a511..6dbd7ecbf6 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -132,19 +132,21 @@ mod storage_types { mapping_account_balance: Mapping>, } + impl Default for StorageTypes { + fn default() -> Self { + Self::new() + } + } + impl StorageTypes { #[ink(constructor)] pub fn new() -> Self { - // Vectors - let mut vec_string_value: Vec = Vec::new(); - vec_string_value.push(String::from("This is a string")); - vec_string_value.push(String::from("This is another string")); - - let mut vec_vec_string_value: Vec> = Vec::new(); - vec_vec_string_value.push(vec_string_value.clone()); + let vec_string_value = vec![ + "This is a String".to_string(), + "This is another String".to_string(), + ]; - let mut vec_vec_string_value: Vec> = Vec::new(); - vec_vec_string_value.push(vec_string_value.clone()); + let vec_vec_string_value = vec![vec_string_value.clone()]; // Mappings let mut mapping_account_balance = Mapping::new(); From b3a10267d6de1264b72b078a4401ec2e799c3aa4 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 21 Apr 2023 11:08:12 +0200 Subject: [PATCH 05/24] correcting imports --- integration-tests/storage-types/lib.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 6dbd7ecbf6..5981d80530 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -7,10 +7,18 @@ #[ink::contract] mod storage_types { - use ink::prelude::string::String; - use ink::prelude::vec::Vec; - use ink::storage::{traits::ManualKey, Mapping}; - use scale::{Decode, Encode}; + use ink::{ + prelude::{ + string::String, + vec, + vec::Vec, + }, + storage::Mapping, + }; + use scale::{ + Decode, + Encode, + }; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] @@ -129,7 +137,7 @@ mod storage_types { signed_integers: SignedIntegers, substrate_types: SubstrateTypes, unsigned_integers: UnsignedIntegers, - mapping_account_balance: Mapping>, + mapping_account_balance: Mapping, } impl Default for StorageTypes { @@ -142,10 +150,9 @@ mod storage_types { #[ink(constructor)] pub fn new() -> Self { let vec_string_value = vec![ - "This is a String".to_string(), - "This is another String".to_string(), + String::from("This is a String"), + String::from("This is another String"), ]; - let vec_vec_string_value = vec![vec_string_value.clone()]; // Mappings From e12ab8e2611a77cc77229d6b927afec4c24be83e Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 21 Apr 2023 12:06:24 +0200 Subject: [PATCH 06/24] fixes riscv ci pipeline by aligning Cargo.toml with other integration-tests --- integration-tests/storage-types/Cargo.toml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/integration-tests/storage-types/Cargo.toml b/integration-tests/storage-types/Cargo.toml index 184ffa7e8d..ad7628dffa 100755 --- a/integration-tests/storage-types/Cargo.toml +++ b/integration-tests/storage-types/Cargo.toml @@ -3,22 +3,19 @@ name = "storage-types" version = "1.0.0" authors = ["Parity Technologies "] edition = "2021" +publish = false [dependencies] -ink = { version = "4.1", default-features = false } +ink = { path = "../../crates/ink", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } [dev-dependencies] -ink_e2e = { version = "4.1" } +ink_e2e = { path = "../../crates/e2e" } [lib] -name = "storage_types" path = "lib.rs" -crate-type = [ - "cdylib", -] [features] default = ["std"] From c35b47a1303783b2454be430fd3f6ded91555d15 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Tue, 9 May 2023 14:05:44 +0200 Subject: [PATCH 07/24] returns Option and Result with a value in success cases --- integration-tests/storage-types/lib.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 5981d80530..63af6d3f18 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -8,17 +8,10 @@ #[ink::contract] mod storage_types { use ink::{ - prelude::{ - string::String, - vec, - vec::Vec, - }, + prelude::{string::String, vec, vec::Vec}, storage::Mapping, }; - use scale::{ - Decode, - Encode, - }; + use scale::{Decode, Encode}; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] @@ -232,22 +225,22 @@ mod storage_types { } #[ink(message)] - pub fn get_option_some(&self) -> Option<()> { - Some(()) + pub fn get_option_some(&self) -> Option { + Some(true) } #[ink(message)] - pub fn get_option_none(&self) -> Option<()> { + pub fn get_option_none(&self) -> Option { None } #[ink(message)] - pub fn get_result_ok(&self) -> Result<(), CustomError> { - Ok(()) + pub fn get_result_ok(&self) -> Result { + Ok(true) } #[ink(message)] - pub fn get_result_error(&self) -> Result<(), CustomError> { + pub fn get_result_error(&self) -> Result { Err(CustomError::ErrorWithMessage(String::from( "This is the Error Message.", ))) From ae1cd94a783ac95da811ec445807a0366fe08bcd Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Tue, 9 May 2023 15:17:13 +0200 Subject: [PATCH 08/24] use nightly formatter --- integration-tests/storage-types/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 63af6d3f18..64388af04e 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -8,10 +8,17 @@ #[ink::contract] mod storage_types { use ink::{ - prelude::{string::String, vec, vec::Vec}, + prelude::{ + string::String, + vec, + vec::Vec, + }, storage::Mapping, }; - use scale::{Decode, Encode}; + use scale::{ + Decode, + Encode, + }; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] From 123c4d4b6845aa7259aaae7caa440d2b4380178e Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Tue, 9 May 2023 15:43:43 +0200 Subject: [PATCH 09/24] removes code regarding `Mapping` type. Afaik a mapping can't be returned by an ink message, therefore there is nothing to be tested regarding decoding. --- integration-tests/storage-types/lib.rs | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 64388af04e..29283f1d79 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -7,13 +7,10 @@ #[ink::contract] mod storage_types { - use ink::{ - prelude::{ - string::String, - vec, - vec::Vec, - }, - storage::Mapping, + use ink::prelude::{ + string::String, + vec, + vec::Vec, }; use scale::{ Decode, @@ -121,15 +118,6 @@ mod storage_types { u8_value_min: u8, } - #[derive(Debug)] - #[ink::storage_item] - pub struct MappingTypes { - mapping_u128_u128_value: Mapping, - mapping_account_balance_value: Mapping, - mapping_account_hash_value: Mapping, - mapping_account_account_balance_value: Mapping<(AccountId, AccountId), Balance>, - } - #[ink(storage)] pub struct StorageTypes { ink_prelude_types: InkPreludeTypes, @@ -137,7 +125,6 @@ mod storage_types { signed_integers: SignedIntegers, substrate_types: SubstrateTypes, unsigned_integers: UnsignedIntegers, - mapping_account_balance: Mapping, } impl Default for StorageTypes { @@ -155,10 +142,6 @@ mod storage_types { ]; let vec_vec_string_value = vec![vec_string_value.clone()]; - // Mappings - let mut mapping_account_balance = Mapping::new(); - mapping_account_balance.insert(AccountId::from([0x01; 32]), &100); - Self { unsigned_integers: UnsignedIntegers { u128_value_max: u128::MAX, @@ -202,7 +185,6 @@ mod storage_types { balance_value_min: Balance::MIN, hash_value: Hash::from([0x00; 32]), }, - mapping_account_balance, } } @@ -257,14 +239,6 @@ mod storage_types { pub fn get_panic(&self) -> Result<(), ()> { panic!("This is the Panic message.") } - - #[ink(message)] - pub fn get_mapping_account_balance( - &self, - account_id: AccountId, - ) -> Option { - self.mapping_account_balance.get(account_id) - } } #[cfg(test)] From 43a511c67672f432f32bde668ce5c19d2688f979 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 6 Jul 2023 13:38:06 +0200 Subject: [PATCH 10/24] update storage_types contract to work with latest master changes --- integration-tests/storage-types/Cargo.toml | 5 +++-- integration-tests/storage-types/lib.rs | 13 +++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/integration-tests/storage-types/Cargo.toml b/integration-tests/storage-types/Cargo.toml index ad7628dffa..e6ebaa316d 100755 --- a/integration-tests/storage-types/Cargo.toml +++ b/integration-tests/storage-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "storage-types" -version = "1.0.0" +version = "4.2.0" authors = ["Parity Technologies "] edition = "2021" publish = false @@ -9,7 +9,7 @@ publish = false ink = { path = "../../crates/ink", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } -scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } [dev-dependencies] ink_e2e = { path = "../../crates/e2e" } @@ -25,3 +25,4 @@ std = [ "scale-info/std", ] ink-as-dependency = [] +e2e-tests = [] diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 29283f1d79..80c0cd6852 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -3,19 +3,12 @@ //! This contract is made to showcase all of ink!'s storage types. //! With this the proper decoding of the storage types can be tested. -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), no_std, no_main)] #[ink::contract] mod storage_types { - use ink::prelude::{ - string::String, - vec, - vec::Vec, - }; - use scale::{ - Decode, - Encode, - }; + use ink::prelude::{string::String, vec, vec::Vec}; + use scale::{Decode, Encode}; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] From 251c45f5069b97a09304ea515db9751fc40dfbba Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 16 Nov 2023 14:25:42 +0100 Subject: [PATCH 11/24] adds empty enums as well as tuples to test how they are decoded by FE libs --- integration-tests/storage-types/lib.rs | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 80c0cd6852..410645e38e 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -13,7 +13,10 @@ mod storage_types { #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] pub enum CustomError { - ErrorWithMessage(String), + EmptyError, + StringError(String), + StringStringError(String, String), + StringUnsignedError(String, u32), } #[derive(Clone, Debug, Decode, Default, Encode)] @@ -50,6 +53,7 @@ mod storage_types { enum_with_values: EnumWithValues, array_value: [u32; 3], tuple_value: (u32, u32), + tuple_triplet_value: (i32, i32, i32), } #[derive(Clone, Debug, Decode, Encode)] @@ -171,6 +175,7 @@ mod storage_types { enum_without_values: EnumWithoutValues::A, array_value: [3, 2, 1], tuple_value: (7, 8), + tuple_triplet_value: (-123, 0, 123), }, substrate_types: SubstrateTypes { account_id_value: AccountId::from([0x00; 32]), @@ -223,11 +228,32 @@ mod storage_types { #[ink(message)] pub fn get_result_error(&self) -> Result { - Err(CustomError::ErrorWithMessage(String::from( + Err(CustomError::EmptyError) + } + + #[ink(message)] + pub fn get_result_error_with_string(&self) -> Result { + Err(CustomError::StringError(String::from( "This is the Error Message.", ))) } + #[ink(message)] + pub fn get_result_error_with_string_string(&self) -> Result { + Err(CustomError::StringStringError( + "This is the Error Message.".to_string(), + "This is the second string of this Error Message.".to_string(), + )) + } + + #[ink(message)] + pub fn get_result_error_with_string_unsigned(&self) -> Result { + Err(CustomError::StringUnsignedError( + "This is the Error Message.".to_string(), + 42, + )) + } + #[ink(message)] pub fn get_panic(&self) -> Result<(), ()> { panic!("This is the Panic message.") From 261c9528e3436ff40a36b57e90a670834b31ce32 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 20 Apr 2023 14:20:46 +0200 Subject: [PATCH 12/24] adds storage_types contract from https://github.com/paritytech/ink-examples/pull/15 --- integration-tests/storage_types/Cargo.toml | 30 +++ integration-tests/storage_types/lib.rs | 258 +++++++++++++++++++++ 2 files changed, 288 insertions(+) create mode 100755 integration-tests/storage_types/Cargo.toml create mode 100755 integration-tests/storage_types/lib.rs diff --git a/integration-tests/storage_types/Cargo.toml b/integration-tests/storage_types/Cargo.toml new file mode 100755 index 0000000000..c9d6599c2b --- /dev/null +++ b/integration-tests/storage_types/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "storage_types" +version = "1.0.0" +authors = ["Parity Technologies "] +edition = "2021" + +[dependencies] +ink = { version = "4.1", default-features = false } + +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } + +[dev-dependencies] +ink_e2e = { version = "4.1" } + +[lib] +name = "storage_types" +path = "lib.rs" +crate-type = [ + "cdylib", +] + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", +] +ink-as-dependency = [] diff --git a/integration-tests/storage_types/lib.rs b/integration-tests/storage_types/lib.rs new file mode 100755 index 0000000000..e3be9bae51 --- /dev/null +++ b/integration-tests/storage_types/lib.rs @@ -0,0 +1,258 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +#[ink::contract] +mod storage_types { + use ink::prelude::string::String; + use ink::prelude::vec::Vec; + use ink::storage::{traits::ManualKey, Mapping}; + use scale::{Decode, Encode}; + + #[derive(Debug, Decode, Encode)] + #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] + pub enum CustomError { + ErrorWithMessage(String), + } + + #[derive(Clone, Debug, Decode, Default, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub enum EnumWithoutValues { + #[default] + A, + B, + C, + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub enum EnumWithValues { + OneValue(u32), + TwoValues(u32, u32), + ThreeValues(u32, u32, u32), + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct PrimitiveTypes { + bool_value: bool, + enum_without_values: EnumWithoutValues, + enum_with_values: EnumWithValues, + array_value: [u32; 3], + tuple_value: (u32, u32), + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct SignedIntegers { + i128_value_max: i128, + i128_value_min: i128, + i16_value_max: i16, + i16_value_min: i16, + i32_value_max: i32, + i32_value_min: i32, + i64_value_max: i64, + i64_value_min: i64, + i8_value_max: i8, + i8_value_min: i8, + } + + #[derive(Clone, Debug, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct SubstrateTypes { + account_id_value: AccountId, + balance_value_max: Balance, + balance_value_min: Balance, + hash_value: Hash, + } + + #[derive(Clone, Debug, Decode, scale::Encode)] + #[cfg_attr( + feature = "std", + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct InkPreludeTypes { + string_value: String, + vec_string_value: Vec, + vec_vec_string_value: Vec>, + } + + #[derive(Clone, Decode, Encode)] + #[cfg_attr( + feature = "std", + derive(Debug, scale_info::TypeInfo, ink::storage::traits::StorageLayout) + )] + pub struct UnsignedIntegers { + u128_value_max: u128, + u128_value_min: u128, + u16_value_max: u16, + u16_value_min: u16, + u32_value_max: u32, + u32_value_min: u32, + u64_value_max: u64, + u64_value_min: u64, + u8_value_max: u8, + u8_value_min: u8, + } + + #[derive(Debug)] + #[ink::storage_item] + pub struct MappingTypes { + mapping_u128_u128_value: Mapping, + mapping_account_balance_value: Mapping, + mapping_account_hash_value: Mapping, + mapping_account_account_balance_value: Mapping<(AccountId, AccountId), Balance>, + } + + #[ink(storage)] + pub struct StorageTypes { + ink_prelude_types: InkPreludeTypes, + primitive_types: PrimitiveTypes, + signed_integers: SignedIntegers, + substrate_types: SubstrateTypes, + unsigned_integers: UnsignedIntegers, + mapping_account_balance: Mapping>, + } + + impl StorageTypes { + #[ink(constructor)] + pub fn new() -> Self { + // Vectors + let mut vec_string_value: Vec = Vec::new(); + vec_string_value.push(String::from("This is a string")); + vec_string_value.push(String::from("This is another string")); + + let mut vec_vec_string_value: Vec> = Vec::new(); + vec_vec_string_value.push(vec_string_value.clone()); + + let mut vec_vec_string_value: Vec> = Vec::new(); + vec_vec_string_value.push(vec_string_value.clone()); + + // Mappings + let mut mapping_account_balance = Mapping::new(); + mapping_account_balance.insert(AccountId::from([0x01; 32]), &100); + + Self { + unsigned_integers: UnsignedIntegers { + u128_value_max: u128::MAX, + u128_value_min: u128::MIN, + u16_value_max: u16::MAX, + u16_value_min: u16::MIN, + u32_value_max: u32::MAX, + u32_value_min: u32::MIN, + u64_value_max: u64::MAX, + u64_value_min: u64::MIN, + u8_value_max: u8::MAX, + u8_value_min: u8::MIN, + }, + signed_integers: SignedIntegers { + i128_value_max: i128::MAX, + i128_value_min: i128::MIN, + i16_value_max: i16::MAX, + i16_value_min: i16::MIN, + i32_value_max: i32::MAX, + i32_value_min: i32::MIN, + i64_value_max: i64::MAX, + i64_value_min: i64::MIN, + i8_value_max: i8::MAX, + i8_value_min: i8::MIN, + }, + ink_prelude_types: InkPreludeTypes { + string_value: String::from("This is a string"), + vec_string_value, + vec_vec_string_value, + }, + primitive_types: PrimitiveTypes { + bool_value: true, + enum_with_values: EnumWithValues::ThreeValues(1, 2, 3), + enum_without_values: EnumWithoutValues::A, + array_value: [3, 2, 1], + tuple_value: (7, 8), + }, + substrate_types: SubstrateTypes { + account_id_value: AccountId::from([0x00; 32]), + balance_value_max: Balance::MAX, + balance_value_min: Balance::MIN, + hash_value: Hash::from([0x00; 32]), + }, + mapping_account_balance, + } + } + + #[ink(message)] + pub fn get_unsigned_integers(&self) -> UnsignedIntegers { + self.unsigned_integers.clone() + } + + #[ink(message)] + pub fn get_signed_integers(&self) -> SignedIntegers { + self.signed_integers.clone() + } + + #[ink(message)] + pub fn get_ink_prelude_types(&self) -> InkPreludeTypes { + self.ink_prelude_types.clone() + } + + #[ink(message)] + pub fn get_substrate_types(&self) -> SubstrateTypes { + self.substrate_types.clone() + } + + #[ink(message)] + pub fn get_primitive_types(&self) -> PrimitiveTypes { + self.primitive_types.clone() + } + + #[ink(message)] + pub fn get_option_some(&self) -> Option<()> { + Some(()) + } + + #[ink(message)] + pub fn get_option_none(&self) -> Option<()> { + None + } + + #[ink(message)] + pub fn get_result_ok(&self) -> Result<(), CustomError> { + Ok(()) + } + + #[ink(message)] + pub fn get_result_error(&self) -> Result<(), CustomError> { + Err(CustomError::ErrorWithMessage(String::from( + "This is the Error Message.", + ))) + } + + #[ink(message)] + pub fn get_panic(&self) -> Result<(), ()> { + panic!("This is the Panic message.") + } + + #[ink(message)] + pub fn get_mapping_account_balance( + &self, + account_id: AccountId, + ) -> Option { + self.mapping_account_balance.get(account_id) + } + } + + #[cfg(test)] + mod tests {} +} From 4ff27cee6809a2fbd4263ce3ab0eefb70f8e1ff7 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 20 Apr 2023 15:44:39 +0200 Subject: [PATCH 13/24] renames folder --- .../{storage_types => storage-types}/Cargo.toml | 0 integration-tests/{storage_types => storage-types}/lib.rs | 5 +++++ 2 files changed, 5 insertions(+) rename integration-tests/{storage_types => storage-types}/Cargo.toml (100%) rename integration-tests/{storage_types => storage-types}/lib.rs (97%) diff --git a/integration-tests/storage_types/Cargo.toml b/integration-tests/storage-types/Cargo.toml similarity index 100% rename from integration-tests/storage_types/Cargo.toml rename to integration-tests/storage-types/Cargo.toml diff --git a/integration-tests/storage_types/lib.rs b/integration-tests/storage-types/lib.rs similarity index 97% rename from integration-tests/storage_types/lib.rs rename to integration-tests/storage-types/lib.rs index e3be9bae51..d15d51a511 100755 --- a/integration-tests/storage_types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -1,3 +1,8 @@ +//! # Integration Test for Storage Types +//! +//! This contract is made to showcase all of ink!'s storage types. +//! With this the proper decoding of the storage types can be tested. + #![cfg_attr(not(feature = "std"), no_std)] #[ink::contract] From a8c12a177c5f8a37b4de1567c4adeb0e5e4b768f Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 20 Apr 2023 15:56:32 +0200 Subject: [PATCH 14/24] aligns contract name with folder name --- integration-tests/storage-types/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/storage-types/Cargo.toml b/integration-tests/storage-types/Cargo.toml index c9d6599c2b..184ffa7e8d 100755 --- a/integration-tests/storage-types/Cargo.toml +++ b/integration-tests/storage-types/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "storage_types" +name = "storage-types" version = "1.0.0" authors = ["Parity Technologies "] edition = "2021" From 7b11ad3de5ddb6a14818a4dd770f8edc7dd24682 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 21 Apr 2023 10:19:13 +0200 Subject: [PATCH 15/24] resolves clippy recommendations --- integration-tests/storage-types/lib.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index d15d51a511..6dbd7ecbf6 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -132,19 +132,21 @@ mod storage_types { mapping_account_balance: Mapping>, } + impl Default for StorageTypes { + fn default() -> Self { + Self::new() + } + } + impl StorageTypes { #[ink(constructor)] pub fn new() -> Self { - // Vectors - let mut vec_string_value: Vec = Vec::new(); - vec_string_value.push(String::from("This is a string")); - vec_string_value.push(String::from("This is another string")); - - let mut vec_vec_string_value: Vec> = Vec::new(); - vec_vec_string_value.push(vec_string_value.clone()); + let vec_string_value = vec![ + "This is a String".to_string(), + "This is another String".to_string(), + ]; - let mut vec_vec_string_value: Vec> = Vec::new(); - vec_vec_string_value.push(vec_string_value.clone()); + let vec_vec_string_value = vec![vec_string_value.clone()]; // Mappings let mut mapping_account_balance = Mapping::new(); From adfbebad684fa844c4415854f95a8cd90e60ceae Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 21 Apr 2023 11:08:12 +0200 Subject: [PATCH 16/24] correcting imports --- integration-tests/storage-types/lib.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 6dbd7ecbf6..5981d80530 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -7,10 +7,18 @@ #[ink::contract] mod storage_types { - use ink::prelude::string::String; - use ink::prelude::vec::Vec; - use ink::storage::{traits::ManualKey, Mapping}; - use scale::{Decode, Encode}; + use ink::{ + prelude::{ + string::String, + vec, + vec::Vec, + }, + storage::Mapping, + }; + use scale::{ + Decode, + Encode, + }; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] @@ -129,7 +137,7 @@ mod storage_types { signed_integers: SignedIntegers, substrate_types: SubstrateTypes, unsigned_integers: UnsignedIntegers, - mapping_account_balance: Mapping>, + mapping_account_balance: Mapping, } impl Default for StorageTypes { @@ -142,10 +150,9 @@ mod storage_types { #[ink(constructor)] pub fn new() -> Self { let vec_string_value = vec![ - "This is a String".to_string(), - "This is another String".to_string(), + String::from("This is a String"), + String::from("This is another String"), ]; - let vec_vec_string_value = vec![vec_string_value.clone()]; // Mappings From 52fb0253977a41688c07cb83c7ce02197a12893c Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Fri, 21 Apr 2023 12:06:24 +0200 Subject: [PATCH 17/24] fixes riscv ci pipeline by aligning Cargo.toml with other integration-tests --- integration-tests/storage-types/Cargo.toml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/integration-tests/storage-types/Cargo.toml b/integration-tests/storage-types/Cargo.toml index 184ffa7e8d..ad7628dffa 100755 --- a/integration-tests/storage-types/Cargo.toml +++ b/integration-tests/storage-types/Cargo.toml @@ -3,22 +3,19 @@ name = "storage-types" version = "1.0.0" authors = ["Parity Technologies "] edition = "2021" +publish = false [dependencies] -ink = { version = "4.1", default-features = false } +ink = { path = "../../crates/ink", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } [dev-dependencies] -ink_e2e = { version = "4.1" } +ink_e2e = { path = "../../crates/e2e" } [lib] -name = "storage_types" path = "lib.rs" -crate-type = [ - "cdylib", -] [features] default = ["std"] From ef0d43ac362a417ee1c2874b475292457c1c246e Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Tue, 9 May 2023 14:05:44 +0200 Subject: [PATCH 18/24] returns Option and Result with a value in success cases --- integration-tests/storage-types/lib.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 5981d80530..63af6d3f18 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -8,17 +8,10 @@ #[ink::contract] mod storage_types { use ink::{ - prelude::{ - string::String, - vec, - vec::Vec, - }, + prelude::{string::String, vec, vec::Vec}, storage::Mapping, }; - use scale::{ - Decode, - Encode, - }; + use scale::{Decode, Encode}; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] @@ -232,22 +225,22 @@ mod storage_types { } #[ink(message)] - pub fn get_option_some(&self) -> Option<()> { - Some(()) + pub fn get_option_some(&self) -> Option { + Some(true) } #[ink(message)] - pub fn get_option_none(&self) -> Option<()> { + pub fn get_option_none(&self) -> Option { None } #[ink(message)] - pub fn get_result_ok(&self) -> Result<(), CustomError> { - Ok(()) + pub fn get_result_ok(&self) -> Result { + Ok(true) } #[ink(message)] - pub fn get_result_error(&self) -> Result<(), CustomError> { + pub fn get_result_error(&self) -> Result { Err(CustomError::ErrorWithMessage(String::from( "This is the Error Message.", ))) From fcef200162ae24641638644552faa8959a669d97 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Tue, 9 May 2023 15:17:13 +0200 Subject: [PATCH 19/24] use nightly formatter --- integration-tests/storage-types/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 63af6d3f18..64388af04e 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -8,10 +8,17 @@ #[ink::contract] mod storage_types { use ink::{ - prelude::{string::String, vec, vec::Vec}, + prelude::{ + string::String, + vec, + vec::Vec, + }, storage::Mapping, }; - use scale::{Decode, Encode}; + use scale::{ + Decode, + Encode, + }; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] From 4675b1e5b4729c029e823fe70fe1f00a3aaa3677 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Tue, 9 May 2023 15:43:43 +0200 Subject: [PATCH 20/24] removes code regarding `Mapping` type. Afaik a mapping can't be returned by an ink message, therefore there is nothing to be tested regarding decoding. --- integration-tests/storage-types/lib.rs | 34 +++----------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 64388af04e..29283f1d79 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -7,13 +7,10 @@ #[ink::contract] mod storage_types { - use ink::{ - prelude::{ - string::String, - vec, - vec::Vec, - }, - storage::Mapping, + use ink::prelude::{ + string::String, + vec, + vec::Vec, }; use scale::{ Decode, @@ -121,15 +118,6 @@ mod storage_types { u8_value_min: u8, } - #[derive(Debug)] - #[ink::storage_item] - pub struct MappingTypes { - mapping_u128_u128_value: Mapping, - mapping_account_balance_value: Mapping, - mapping_account_hash_value: Mapping, - mapping_account_account_balance_value: Mapping<(AccountId, AccountId), Balance>, - } - #[ink(storage)] pub struct StorageTypes { ink_prelude_types: InkPreludeTypes, @@ -137,7 +125,6 @@ mod storage_types { signed_integers: SignedIntegers, substrate_types: SubstrateTypes, unsigned_integers: UnsignedIntegers, - mapping_account_balance: Mapping, } impl Default for StorageTypes { @@ -155,10 +142,6 @@ mod storage_types { ]; let vec_vec_string_value = vec![vec_string_value.clone()]; - // Mappings - let mut mapping_account_balance = Mapping::new(); - mapping_account_balance.insert(AccountId::from([0x01; 32]), &100); - Self { unsigned_integers: UnsignedIntegers { u128_value_max: u128::MAX, @@ -202,7 +185,6 @@ mod storage_types { balance_value_min: Balance::MIN, hash_value: Hash::from([0x00; 32]), }, - mapping_account_balance, } } @@ -257,14 +239,6 @@ mod storage_types { pub fn get_panic(&self) -> Result<(), ()> { panic!("This is the Panic message.") } - - #[ink(message)] - pub fn get_mapping_account_balance( - &self, - account_id: AccountId, - ) -> Option { - self.mapping_account_balance.get(account_id) - } } #[cfg(test)] From 13ca08e1fe40db29b8d950a7e849e2199ccd30d5 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 6 Jul 2023 13:38:06 +0200 Subject: [PATCH 21/24] update storage_types contract to work with latest master changes --- integration-tests/storage-types/Cargo.toml | 5 +++-- integration-tests/storage-types/lib.rs | 13 +++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/integration-tests/storage-types/Cargo.toml b/integration-tests/storage-types/Cargo.toml index ad7628dffa..e6ebaa316d 100755 --- a/integration-tests/storage-types/Cargo.toml +++ b/integration-tests/storage-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "storage-types" -version = "1.0.0" +version = "4.2.0" authors = ["Parity Technologies "] edition = "2021" publish = false @@ -9,7 +9,7 @@ publish = false ink = { path = "../../crates/ink", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } -scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } [dev-dependencies] ink_e2e = { path = "../../crates/e2e" } @@ -25,3 +25,4 @@ std = [ "scale-info/std", ] ink-as-dependency = [] +e2e-tests = [] diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 29283f1d79..80c0cd6852 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -3,19 +3,12 @@ //! This contract is made to showcase all of ink!'s storage types. //! With this the proper decoding of the storage types can be tested. -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), no_std, no_main)] #[ink::contract] mod storage_types { - use ink::prelude::{ - string::String, - vec, - vec::Vec, - }; - use scale::{ - Decode, - Encode, - }; + use ink::prelude::{string::String, vec, vec::Vec}; + use scale::{Decode, Encode}; #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] From 1bfaec23fe9fcb16674f327c836ec7daef06ef25 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 16 Nov 2023 14:25:42 +0100 Subject: [PATCH 22/24] adds empty enums as well as tuples to test how they are decoded by FE libs --- integration-tests/storage-types/lib.rs | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 80c0cd6852..410645e38e 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -13,7 +13,10 @@ mod storage_types { #[derive(Debug, Decode, Encode)] #[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))] pub enum CustomError { - ErrorWithMessage(String), + EmptyError, + StringError(String), + StringStringError(String, String), + StringUnsignedError(String, u32), } #[derive(Clone, Debug, Decode, Default, Encode)] @@ -50,6 +53,7 @@ mod storage_types { enum_with_values: EnumWithValues, array_value: [u32; 3], tuple_value: (u32, u32), + tuple_triplet_value: (i32, i32, i32), } #[derive(Clone, Debug, Decode, Encode)] @@ -171,6 +175,7 @@ mod storage_types { enum_without_values: EnumWithoutValues::A, array_value: [3, 2, 1], tuple_value: (7, 8), + tuple_triplet_value: (-123, 0, 123), }, substrate_types: SubstrateTypes { account_id_value: AccountId::from([0x00; 32]), @@ -223,11 +228,32 @@ mod storage_types { #[ink(message)] pub fn get_result_error(&self) -> Result { - Err(CustomError::ErrorWithMessage(String::from( + Err(CustomError::EmptyError) + } + + #[ink(message)] + pub fn get_result_error_with_string(&self) -> Result { + Err(CustomError::StringError(String::from( "This is the Error Message.", ))) } + #[ink(message)] + pub fn get_result_error_with_string_string(&self) -> Result { + Err(CustomError::StringStringError( + "This is the Error Message.".to_string(), + "This is the second string of this Error Message.".to_string(), + )) + } + + #[ink(message)] + pub fn get_result_error_with_string_unsigned(&self) -> Result { + Err(CustomError::StringUnsignedError( + "This is the Error Message.".to_string(), + 42, + )) + } + #[ink(message)] pub fn get_panic(&self) -> Result<(), ()> { panic!("This is the Panic message.") From 4b29f02cc1d9532b60ae3adccc64c03039bd5d25 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Thu, 16 Nov 2023 14:35:54 +0100 Subject: [PATCH 23/24] replace .to_string with String::from --- integration-tests/storage-types/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 410645e38e..880b4580a3 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -241,15 +241,15 @@ mod storage_types { #[ink(message)] pub fn get_result_error_with_string_string(&self) -> Result { Err(CustomError::StringStringError( - "This is the Error Message.".to_string(), - "This is the second string of this Error Message.".to_string(), + String::from("This is the Error Message."), + String::from("This is the second string of this Error Message."), )) } #[ink(message)] pub fn get_result_error_with_string_unsigned(&self) -> Result { Err(CustomError::StringUnsignedError( - "This is the Error Message.".to_string(), + String::from("This is the Error Message."), 42, )) } From 76d46ccf30780c995087f6a74aaca0cc8b00c103 Mon Sep 17 00:00:00 2001 From: peetzweg/ Date: Wed, 22 Nov 2023 16:24:38 +0100 Subject: [PATCH 24/24] adds a payable function --- integration-tests/storage-types/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/integration-tests/storage-types/lib.rs b/integration-tests/storage-types/lib.rs index 880b4580a3..6cb5b96035 100755 --- a/integration-tests/storage-types/lib.rs +++ b/integration-tests/storage-types/lib.rs @@ -258,6 +258,11 @@ mod storage_types { pub fn get_panic(&self) -> Result<(), ()> { panic!("This is the Panic message.") } + + #[ink(message, payable)] + pub fn payable(&self) -> Result { + Ok(self.env().transferred_value()) + } } #[cfg(test)]