Repository: paritytech/ink
Pull request #744 (2021-03-24 14:23:42)

Use `#[ink::test]` instead of `#[test]`
Needed for https://github.com/paritytech/ink/issues/714.


Patch:
diff --git a/README.md b/README.md
index 1e3ac55f77..186fbd9952 100644
--- a/README.md
+++ b/README.md
@@ -147,8 +147,9 @@ mod flipper {
     #[cfg(test)]
     mod tests {
         use super::*;
+        use ink_lang as ink;
 
-        #[test]
+        #[ink::test]
         fn it_works() {
             let mut flipper = Flipper::new(false);
             assert_eq!(flipper.get(), false);
diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml
index e4869b1bb8..62d24249df 100644
--- a/crates/storage/Cargo.toml
+++ b/crates/storage/Cargo.toml
@@ -25,7 +25,7 @@ scale = { package = "parity-scale-codec", version = "2.0", default-features = fa
 derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
 scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
 cfg-if = "1.0"
-array-init = { version = "1.0", default-features = false, features = ["const-generics"] }
+array-init = { version = "2.0", default-features = false }
 
 # Workaround: we actually just need criterion as a dev-dependency, but
 # there is an issue with a doubly included std lib when executing
@@ -56,7 +56,6 @@ std = [
     "scale-info/std",
 ]
 ink-fuzz-tests = ["std"]
-ink-unstable = ["std"]
 
 [[bench]]
 name = "bench_lazy"
diff --git a/crates/storage/src/collections/mod.rs b/crates/storage/src/collections/mod.rs
index 7acd7d2b81..07ade806f2 100644
--- a/crates/storage/src/collections/mod.rs
+++ b/crates/storage/src/collections/mod.rs
@@ -22,7 +22,6 @@ pub mod binary_heap;
 pub mod bitstash;
 pub mod bitvec;
 pub mod hashmap;
-#[cfg(feature = "ink-unstable")]
 pub mod smallvec;
 pub mod stash;
 pub mod vec;
@@ -37,7 +36,6 @@ pub use self::{
     vec::Vec,
 };
 
-#[cfg(feature = "ink-unstable")]
 #[doc(inline)]
 pub use self::smallvec::SmallVec;
 
diff --git a/crates/storage/src/collections/smallvec/storage.rs b/crates/storage/src/collections/smallvec/storage.rs
index 510ec1b725..cabbe2d1d8 100644
--- a/crates/storage/src/collections/smallvec/storage.rs
+++ b/crates/storage/src/collections/smallvec/storage.rs
@@ -21,9 +21,10 @@ use crate::traits::{
 
 #[cfg(feature = "std")]
 const _: () = {
-    #[cfg(feature = "ink-unstable")]
-    use crate::lazy::LazyArray;
-    use crate::traits::StorageLayout;
+    use crate::{
+        lazy::LazyArray,
+        traits::StorageLayout,
+    };
     use ink_metadata::layout::{
         FieldLayout,
         Layout,
diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs
index be22d26f6d..f3dcf5d13e 100644
--- a/crates/storage/src/lazy/mod.rs
+++ b/crates/storage/src/lazy/mod.rs
@@ -28,12 +28,10 @@ pub mod lazy_hmap;
 
 mod cache_cell;
 mod entry;
-#[cfg(feature = "ink-unstable")]
 mod lazy_array;
 mod lazy_cell;
 mod lazy_imap;
 
-#[cfg(feature = "ink-unstable")]
 #[doc(inline)]
 pub use self::lazy_array::LazyArray;
 use self::{
diff --git a/crates/storage/src/traits/impls/arrays.rs b/crates/storage/src/traits/impls/arrays.rs
index 69e0645570..22c3bb5a81 100644
--- a/crates/storage/src/traits/impls/arrays.rs
+++ b/crates/storage/src/traits/impls/arrays.rs
@@ -55,7 +55,7 @@ macro_rules! impl_layout_for_array {
                 }
 
                 fn pull_spread(ptr: &mut KeyPtr) -> Self {
-                    array_init::<Self, _>(|_| <T as SpreadLayout>::pull_spread(ptr))
+                    array_init::<_, T, $len>(|_| <T as SpreadLayout>::pull_spread(ptr))
                 }
             }
 
diff --git a/examples/flipper/lib.rs b/examples/flipper/lib.rs
index 78429d3a17..7e380414b3 100644
--- a/examples/flipper/lib.rs
+++ b/examples/flipper/lib.rs
@@ -52,14 +52,15 @@ pub mod flipper {
     #[cfg(test)]
     mod tests {
         use super::*;
+        use ink_lang as ink;
 
-        #[test]
+        #[ink::test]
         fn default_works() {
             let flipper = Flipper::default();
             assert_eq!(flipper.get(), false);
         }
 
-        #[test]
+        #[ink::test]
         fn it_works() {
             let mut flipper = Flipper::new(false);
             assert_eq!(flipper.get(), false);
diff --git a/examples/incrementer/lib.rs b/examples/incrementer/lib.rs
index ca0f79723b..cacb5e7c0b 100644
--- a/examples/incrementer/lib.rs
+++ b/examples/incrementer/lib.rs
@@ -48,14 +48,15 @@ mod incrementer {
     #[cfg(test)]
     mod tests {
         use super::*;
+        use ink_lang as ink;
 
-        #[test]
+        #[ink::test]
         fn default_works() {
             let contract = Incrementer::default();
             assert_eq!(contract.get(), 0);
         }
 
-        #[test]
+        #[ink::test]
         fn it_works() {
             let mut contract = Incrementer::new(42);
             assert_eq!(contract.get(), 42);
diff --git a/examples/multisig_plain/lib.rs b/examples/multisig_plain/lib.rs
index 4f1057b517..7021d30438 100755
--- a/examples/multisig_plain/lib.rs
+++ b/examples/multisig_plain/lib.rs
@@ -670,6 +670,7 @@ mod multisig_plain {
             call,
             test,
         };
+        use ink_lang as ink;
         type Accounts = test::DefaultAccounts<Environment>;
         const WALLET: [u8; 32] = [7; 32];
 
@@ -737,7 +738,7 @@ mod multisig_plain {
             contract
         }
 
-        #[test]
+        #[ink::test]
         fn construction_works() {
             let accounts = default_accounts();
             let owners = ink_prelude::vec![accounts.alice, accounts.bob, accounts.eve];
@@ -757,27 +758,27 @@ mod multisig_plain {
             assert_eq!(contract.transactions.len(), 0);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn empty_owner_construction_fails() {
             MultisigPlain::new(0, vec![]);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn zero_requirement_construction_fails() {
             let accounts = default_accounts();
             MultisigPlain::new(0, vec![accounts.alice, accounts.bob]);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn too_large_requirement_construction_fails() {
             let accounts = default_accounts();
             MultisigPlain::new(3, vec![accounts.alice, accounts.bob]);
         }
 
-        #[test]
+        #[ink::test]
         fn add_owner_works() {
             let accounts = default_accounts();
             let mut contract = build_contract();
@@ -789,7 +790,7 @@ mod multisig_plain {
             assert_eq!(test::recorded_events().count(), 1);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn add_existing_owner_fails() {
             let accounts = default_accounts();
@@ -798,7 +799,7 @@ mod multisig_plain {
             contract.add_owner(accounts.bob);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn add_owner_permission_denied() {
             let accounts = default_accounts();
@@ -807,7 +808,7 @@ mod multisig_plain {
             contract.add_owner(accounts.frank);
         }
 
-        #[test]
+        #[ink::test]
         fn remove_owner_works() {
             let accounts = default_accounts();
             let mut contract = build_contract();
@@ -819,7 +820,7 @@ mod multisig_plain {
             assert_eq!(test::recorded_events().count(), 1);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn remove_owner_nonexisting_fails() {
             let accounts = default_accounts();
@@ -828,7 +829,7 @@ mod multisig_plain {
             contract.remove_owner(accounts.django);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn remove_owner_permission_denied() {
             let accounts = default_accounts();
@@ -837,7 +838,7 @@ mod multisig_plain {
             contract.remove_owner(accounts.alice);
         }
 
-        #[test]
+        #[ink::test]
         fn replace_owner_works() {
             let accounts = default_accounts();
             let mut contract = build_contract();
@@ -850,7 +851,7 @@ mod multisig_plain {
             assert_eq!(test::recorded_events().count(), 2);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn replace_owner_existing_fails() {
             let accounts = default_accounts();
@@ -859,7 +860,7 @@ mod multisig_plain {
             contract.replace_owner(accounts.alice, accounts.bob);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn replace_owner_nonexisting_fails() {
             let accounts = default_accounts();
@@ -868,7 +869,7 @@ mod multisig_plain {
             contract.replace_owner(accounts.django, accounts.frank);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn replace_owner_permission_denied() {
             let accounts = default_accounts();
@@ -877,7 +878,7 @@ mod multisig_plain {
             contract.replace_owner(accounts.alice, accounts.django);
         }
 
-        #[test]
+        #[ink::test]
         fn change_requirement_works() {
             let mut contract = build_contract();
             assert_eq!(*contract.requirement, 2);
@@ -887,7 +888,7 @@ mod multisig_plain {
             assert_eq!(test::recorded_events().count(), 1);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn change_requirement_too_high() {
             let mut contract = build_contract();
@@ -895,7 +896,7 @@ mod multisig_plain {
             contract.change_requirement(4);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn change_requirement_zero_fails() {
             let mut contract = build_contract();
@@ -903,12 +904,12 @@ mod multisig_plain {
             contract.change_requirement(0);
         }
 
-        #[test]
+        #[ink::test]
         fn submit_transaction_works() {
             submit_transaction();
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn submit_transaction_noowner_fails() {
             let mut contract = build_contract();
@@ -916,7 +917,7 @@ mod multisig_plain {
             contract.submit_transaction(Transaction::change_requirement(1));
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn submit_transaction_wallet_fails() {
             let mut contract = build_contract();
@@ -924,7 +925,7 @@ mod multisig_plain {
             contract.submit_transaction(Transaction::change_requirement(1));
         }
 
-        #[test]
+        #[ink::test]
         fn cancel_transaction_works() {
             let mut contract = submit_transaction();
             set_from_wallet();
@@ -933,7 +934,7 @@ mod multisig_plain {
             assert_eq!(test::recorded_events().count(), 3);
         }
 
-        #[test]
+        #[ink::test]
         fn cancel_transaction_nonexisting() {
             let mut contract = submit_transaction();
             set_from_wallet();
@@ -942,14 +943,14 @@ mod multisig_plain {
             assert_eq!(test::recorded_events().count(), 2);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn cancel_transaction_no_permission() {
             let mut contract = submit_transaction();
             contract.cancel_transaction(0);
         }
 
-        #[test]
+        #[ink::test]
         fn confirm_transaction_works() {
             let mut contract = submit_transaction();
             let accounts = default_accounts();
@@ -961,7 +962,7 @@ mod multisig_plain {
             assert_eq!(*contract.confirmation_count.get(&0).unwrap(), 2);
         }
 
-        #[test]
+        #[ink::test]
         fn revoke_confirmations() {
             // given
             let mut contract = submit_transaction();
@@ -983,7 +984,7 @@ mod multisig_plain {
             assert_eq!(*contract.confirmation_count.get(&0).unwrap(), 1);
         }
 
-        #[test]
+        #[ink::test]
         fn confirm_transaction_already_confirmed() {
             let mut contract = submit_transaction();
             let accounts = default_accounts();
@@ -995,7 +996,7 @@ mod multisig_plain {
             assert_eq!(*contract.confirmation_count.get(&0).unwrap(), 1);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn confirm_transaction_noowner_fail() {
             let mut contract = submit_transaction();
@@ -1003,7 +1004,7 @@ mod multisig_plain {
             contract.confirm_transaction(0);
         }
 
-        #[test]
+        #[ink::test]
         fn revoke_transaction_works() {
             let mut contract = submit_transaction();
             let accounts = default_accounts();
@@ -1015,7 +1016,7 @@ mod multisig_plain {
             assert_eq!(*contract.confirmation_count.get(&0).unwrap(), 0);
         }
 
-        #[test]
+        #[ink::test]
         fn revoke_transaction_no_confirmer() {
             let mut contract = submit_transaction();
             let accounts = default_accounts();
@@ -1027,7 +1028,7 @@ mod multisig_plain {
             assert_eq!(*contract.confirmation_count.get(&0).unwrap(), 1);
         }
 
-        #[test]
+        #[ink::test]
         #[should_panic]
         fn revoke_transaction_noowner_fail() {
             let mut contract = submit_transaction();
@@ -1036,7 +1037,7 @@ mod multisig_plain {
             contract.revoke_confirmation(0);
         }
 
-        #[test]
+        #[ink::test]
         fn execute_transaction_works() {
             // Execution of calls is currently unsupported in off-chain test.
             // Calling execute_transaction panics in any case.
diff --git a/examples/trait-flipper/lib.rs b/examples/trait-flipper/lib.rs
index 6bbaddfadd..4251aa1bf9 100644
--- a/examples/trait-flipper/lib.rs
+++ b/examples/trait-flipper/lib.rs
@@ -68,14 +68,15 @@ pub mod flipper {
     #[cfg(test)]
     mod tests {
         use super::*;
+        use ink_lang as ink;
 
-        #[test]
+        #[ink::test]
         fn default_works() {
             let flipper = Flipper::default();
             assert_eq!(flipper.get(), false);
         }
 
-        #[test]
+        #[ink::test]
         fn it_works() {
             let mut flipper = Flipper::new(false);
             // Can call using universal call syntax using the trait.


Test patch:
diff --git a/crates/lang/macro/tests/ui/pass/02-flipper-contract.rs b/crates/lang/macro/tests/ui/pass/02-flipper-contract.rs
index 052fe1fa03..6f3592aede 100644
--- a/crates/lang/macro/tests/ui/pass/02-flipper-contract.rs
+++ b/crates/lang/macro/tests/ui/pass/02-flipper-contract.rs
@@ -32,8 +32,9 @@ mod flipper {
     #[cfg(test)]
     mod tests {
         use super::*;
+        use ink_lang as ink;
 
-        #[test]
+        #[ink::test]
         fn it_works() {
             let mut flipper = Flipper::new(false);
             assert_eq!(flipper.get(), false);