From e163041b5ef08f1e5cf900105b7fccd8e2993883 Mon Sep 17 00:00:00 2001 From: herolind-sqa Date: Mon, 21 Mar 2022 14:53:39 +0100 Subject: [PATCH 01/18] Ownership test env --- sputnikdao-factory2/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index f87135911..80c668711 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -394,6 +394,7 @@ pub extern "C" fn store() { #[cfg(test)] mod tests { + use near_sdk::env::current_account_id; use near_sdk::test_utils::{accounts, VMContextBuilder}; use near_sdk::{testing_env, PromiseResult}; @@ -432,4 +433,15 @@ mod tests { vec![format!("test.{}", accounts(0)).parse().unwrap()] ); } + + fn test_basics() { + let mut context = VMContextBuilder::new(); + testing_env!(context + .current_account_id(accounts(0)) + .predecessor_account_id(accounts(0)) + .build()); + let mut factory = SputnikDAOFactory::new(); + + assert_eq!(factory.get_owner(), current_account_id()); + } } From 1044bea2f3e8126b9085d01163914b248e15e6d7 Mon Sep 17 00:00:00 2001 From: herolind-sqa Date: Mon, 21 Mar 2022 15:00:39 +0100 Subject: [PATCH 02/18] Ownership test env --- sputnikdao-factory2/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 80c668711..fc887f8cd 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -434,14 +434,16 @@ mod tests { ); } - fn test_basics() { + #[test] + fn test_ownership() { let mut context = VMContextBuilder::new(); testing_env!(context .current_account_id(accounts(0)) .predecessor_account_id(accounts(0)) .build()); - let mut factory = SputnikDAOFactory::new(); + let factory = SputnikDAOFactory::new(); + //can get current owner assert_eq!(factory.get_owner(), current_account_id()); } } From b72e9355dc176a51e8f095a1903b3a0666b85e76 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 22 Mar 2022 16:05:23 +0100 Subject: [PATCH 03/18] added first test --- sputnikdao-factory2/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index fc887f8cd..3edf9dc5b 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -394,7 +394,6 @@ pub extern "C" fn store() { #[cfg(test)] mod tests { - use near_sdk::env::current_account_id; use near_sdk::test_utils::{accounts, VMContextBuilder}; use near_sdk::{testing_env, PromiseResult}; @@ -435,7 +434,7 @@ mod tests { } #[test] - fn test_ownership() { + fn test_factory_can_get_current_owner() { let mut context = VMContextBuilder::new(); testing_env!(context .current_account_id(accounts(0)) @@ -443,7 +442,6 @@ mod tests { .build()); let factory = SputnikDAOFactory::new(); - //can get current owner - assert_eq!(factory.get_owner(), current_account_id()); + assert_eq!(factory.get_owner(), env::current_account_id()); } } From 4520a0e7d65e5f6b6a117537a87274a9f56dcbf6 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 22 Mar 2022 19:39:10 +0100 Subject: [PATCH 04/18] Refactored test_factory_can_get_current_owner --- sputnikdao-factory2/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 3edf9dc5b..5bd4977aa 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -394,6 +394,7 @@ pub extern "C" fn store() { #[cfg(test)] mod tests { + use near_sdk::test_utils::test_env::alice; use near_sdk::test_utils::{accounts, VMContextBuilder}; use near_sdk::{testing_env, PromiseResult}; @@ -439,9 +440,15 @@ mod tests { testing_env!(context .current_account_id(accounts(0)) .predecessor_account_id(accounts(0)) + .attached_deposit(10) .build()); - let factory = SputnikDAOFactory::new(); + let mut factory = SputnikDAOFactory::new(); + + factory.create(alice(), "{}".as_bytes().to_vec().into()); - assert_eq!(factory.get_owner(), env::current_account_id()); + assert_eq!( + factory.get_owner().to_string(), + alice().to_string().strip_suffix(".near").unwrap() + ); } } From c2755badb8b219a0a709fc2fe49637f26138342b Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Wed, 23 Mar 2022 14:24:26 +0100 Subject: [PATCH 05/18] Added comments of readability --- sputnikdao-factory2/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 5bd4977aa..e830c28c7 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -434,6 +434,10 @@ mod tests { ); } + // ################################# + // # Factory ownership tests # + // ################################# + #[test] fn test_factory_can_get_current_owner() { let mut context = VMContextBuilder::new(); From 84750a852b766535e1d2da04d90ab1505e702fd9 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Wed, 23 Mar 2022 14:26:49 +0100 Subject: [PATCH 06/18] Added few tests and test placeholders --- sputnikdao-factory2/src/lib.rs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index e830c28c7..8c7529904 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -394,7 +394,7 @@ pub extern "C" fn store() { #[cfg(test)] mod tests { - use near_sdk::test_utils::test_env::alice; + use near_sdk::test_utils::test_env::{alice, bob}; use near_sdk::test_utils::{accounts, VMContextBuilder}; use near_sdk::{testing_env, PromiseResult}; @@ -440,6 +440,27 @@ mod tests { #[test] fn test_factory_can_get_current_owner() { + let mut context = VMContextBuilder::new(); + testing_env!(context + .current_account_id(alice()) + .predecessor_account_id(alice()) + .attached_deposit(10) + .build()); + let mut factory = SputnikDAOFactory::new(); + + factory.create(alice(), "{}".as_bytes().to_vec().into()); + + assert_eq!(factory.get_owner(), alice()); + } + + #[test] + fn test_factory_fails_setting_owner_from_not_owner_account() {} + + #[test] + fn test_owner_can_be_a_dao_account() {} + + #[test] + fn test_owner_gets_succesfully_updated() { let mut context = VMContextBuilder::new(); testing_env!(context .current_account_id(accounts(0)) @@ -450,9 +471,10 @@ mod tests { factory.create(alice(), "{}".as_bytes().to_vec().into()); - assert_eq!( - factory.get_owner().to_string(), - alice().to_string().strip_suffix(".near").unwrap() - ); + assert_ne!(factory.get_owner(), bob()); + + factory.set_owner(bob()); + + assert_eq!(factory.get_owner(), bob()) } } From 47a7704f0bda49a58415c45a2b41a2f30606d938 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Wed, 23 Mar 2022 15:20:44 +0100 Subject: [PATCH 07/18] Added test_factory_fails_setting_owner --- sputnikdao-factory2/src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 8c7529904..64359deae 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -394,7 +394,7 @@ pub extern "C" fn store() { #[cfg(test)] mod tests { - use near_sdk::test_utils::test_env::{alice, bob}; + use near_sdk::test_utils::test_env::{alice, bob, carol}; use near_sdk::test_utils::{accounts, VMContextBuilder}; use near_sdk::{testing_env, PromiseResult}; @@ -454,7 +454,22 @@ mod tests { } #[test] - fn test_factory_fails_setting_owner_from_not_owner_account() {} + #[should_panic] + fn test_factory_fails_setting_owner_from_not_owner_account() { + let mut context = VMContextBuilder::new(); + testing_env!(context + .current_account_id(alice()) + .predecessor_account_id(carol()) + .attached_deposit(10) + .build()); + let mut factory = SputnikDAOFactory::new(); + + factory.create(alice(), "{}".as_bytes().to_vec().into()); + + assert_eq!(factory.get_owner(), alice()); + + factory.set_owner(bob()); + } #[test] fn test_owner_can_be_a_dao_account() {} From e909d9be8dc1653dc02a176204ee04c37c08519f Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Wed, 23 Mar 2022 15:31:18 +0100 Subject: [PATCH 08/18] Commented out unfinished test --- sputnikdao-factory2/src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 64359deae..034e36dd6 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -434,9 +434,9 @@ mod tests { ); } - // ################################# - // # Factory ownership tests # - // ################################# + // ################################# // + // # Factory ownership tests # // + // ################################# // #[test] fn test_factory_can_get_current_owner() { @@ -471,8 +471,10 @@ mod tests { factory.set_owner(bob()); } - #[test] - fn test_owner_can_be_a_dao_account() {} + // #[test] + // fn test_owner_can_be_a_dao_account() { + // // To be implemented. + // } #[test] fn test_owner_gets_succesfully_updated() { From 1be144c434327a5a7d40ee5dec9d8b505ad38c61 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Wed, 23 Mar 2022 15:41:58 +0100 Subject: [PATCH 09/18] Refactored test_owner_gets_succesfully_updated --- sputnikdao-factory2/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 034e36dd6..327e7cb12 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -480,8 +480,8 @@ mod tests { fn test_owner_gets_succesfully_updated() { let mut context = VMContextBuilder::new(); testing_env!(context - .current_account_id(accounts(0)) - .predecessor_account_id(accounts(0)) + .current_account_id(alice()) + .predecessor_account_id(alice()) .attached_deposit(10) .build()); let mut factory = SputnikDAOFactory::new(); From 742dfb65b19aa77216b074527b07c4be05c9e41d Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Wed, 23 Mar 2022 16:38:28 +0100 Subject: [PATCH 10/18] Removed unnecessary check. --- sputnikdao-factory2/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 327e7cb12..19f07d286 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -466,8 +466,6 @@ mod tests { factory.create(alice(), "{}".as_bytes().to_vec().into()); - assert_eq!(factory.get_owner(), alice()); - factory.set_owner(bob()); } From 4f08c2e3338c7f05ac5738044c5c6c2b326ee6be Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 29 Mar 2022 14:01:13 +0200 Subject: [PATCH 11/18] Added test owner_can_be_a_dao_account. --- sputnikdao-factory2/src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 19f07d286..73e77be0f 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -469,10 +469,20 @@ mod tests { factory.set_owner(bob()); } - // #[test] - // fn test_owner_can_be_a_dao_account() { - // // To be implemented. - // } + #[test] + fn test_owner_can_be_a_dao_account() { + let mut context = VMContextBuilder::new(); + testing_env!(context + .current_account_id(accounts(0)) + .predecessor_account_id(accounts(0)) + .attached_deposit(20) + .build()); + let mut factory = SputnikDAOFactory::new(); + + factory.create(alice(), "{}".as_bytes().to_vec().into()); + + factory.create(alice(), "{}".as_bytes().to_vec().into()); + } #[test] fn test_owner_gets_succesfully_updated() { From 33007d43c775caa5c5b2a118d610bc9997fe77e5 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 29 Mar 2022 19:39:14 +0200 Subject: [PATCH 12/18] Fixed test_factory_can_get_current_owner. --- sputnikdao-factory2/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 73e77be0f..3e580492b 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -446,9 +446,7 @@ mod tests { .predecessor_account_id(alice()) .attached_deposit(10) .build()); - let mut factory = SputnikDAOFactory::new(); - - factory.create(alice(), "{}".as_bytes().to_vec().into()); + let factory = SputnikDAOFactory::new(); assert_eq!(factory.get_owner(), alice()); } From 30073ffbf73bab117379e2efeb20ca9e965b6472 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 29 Mar 2022 19:41:24 +0200 Subject: [PATCH 13/18] Fixed test_factory_fails_setting_owner. --- sputnikdao-factory2/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 3e580492b..69469aacf 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -460,9 +460,7 @@ mod tests { .predecessor_account_id(carol()) .attached_deposit(10) .build()); - let mut factory = SputnikDAOFactory::new(); - - factory.create(alice(), "{}".as_bytes().to_vec().into()); + let factory = SputnikDAOFactory::new(); factory.set_owner(bob()); } From db2a2138b2de52e939d0e1460d8eaa0b314bda8c Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 29 Mar 2022 19:42:53 +0200 Subject: [PATCH 14/18] Fixed test_owner_can_be_a_dao_account. --- sputnikdao-factory2/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 69469aacf..082e5239b 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -469,15 +469,15 @@ mod tests { fn test_owner_can_be_a_dao_account() { let mut context = VMContextBuilder::new(); testing_env!(context - .current_account_id(accounts(0)) - .predecessor_account_id(accounts(0)) + .current_account_id(alice()) + .predecessor_account_id(alice()) .attached_deposit(20) .build()); let mut factory = SputnikDAOFactory::new(); factory.create(alice(), "{}".as_bytes().to_vec().into()); - factory.create(alice(), "{}".as_bytes().to_vec().into()); + assert_eq!(factory.get_owner(), alice()) } #[test] From acb0f0c2c0cae99e4a84b96361f5b8952510cc10 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Tue, 29 Mar 2022 19:44:15 +0200 Subject: [PATCH 15/18] Fixed test_owner_gets_succesfully_updated. --- sputnikdao-factory2/src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 082e5239b..64a5218ac 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -484,13 +484,11 @@ mod tests { fn test_owner_gets_succesfully_updated() { let mut context = VMContextBuilder::new(); testing_env!(context - .current_account_id(alice()) - .predecessor_account_id(alice()) + .current_account_id(accounts(0)) + .predecessor_account_id(accounts(0)) .attached_deposit(10) .build()); - let mut factory = SputnikDAOFactory::new(); - - factory.create(alice(), "{}".as_bytes().to_vec().into()); + let factory = SputnikDAOFactory::new(); assert_ne!(factory.get_owner(), bob()); From 5e3235377308a2df9477920049803822f7658229 Mon Sep 17 00:00:00 2001 From: herolind-sqa Date: Wed, 30 Mar 2022 15:48:55 +0200 Subject: [PATCH 16/18] changed test owner_can_be_a_dao_account --- sputnikdao-factory2/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 64a5218ac..5fc701bd2 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -469,13 +469,15 @@ mod tests { fn test_owner_can_be_a_dao_account() { let mut context = VMContextBuilder::new(); testing_env!(context - .current_account_id(alice()) - .predecessor_account_id(alice()) + .current_account_id(bob()) + .predecessor_account_id(bob()) .attached_deposit(20) .build()); let mut factory = SputnikDAOFactory::new(); - factory.create(alice(), "{}".as_bytes().to_vec().into()); + factory.create(bob(), "{}".as_bytes().to_vec().into()); + + factory.set_owner(alice()); assert_eq!(factory.get_owner(), alice()) } From 0de9d27a228a475b532dabf88dfc3fece9b2c655 Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Mon, 4 Apr 2022 16:27:14 +0200 Subject: [PATCH 17/18] Changed test_owner_can_be_a_dao_account --- sputnikdao-factory2/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 5fc701bd2..b989e7f39 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -471,15 +471,18 @@ mod tests { testing_env!(context .current_account_id(bob()) .predecessor_account_id(bob()) - .attached_deposit(20) + .attached_deposit(10) .build()); let mut factory = SputnikDAOFactory::new(); factory.create(bob(), "{}".as_bytes().to_vec().into()); - factory.set_owner(alice()); + factory.set_owner(AccountId::new_unchecked("bob.sputnik-dao.near".to_string())); - assert_eq!(factory.get_owner(), alice()) + assert_eq!( + factory.get_owner(), + AccountId::new_unchecked("bob.sputnik-dao.near".to_string()) + ) } #[test] From 31af94d7400ad89c6f2482b95ab45a4d430e23aa Mon Sep 17 00:00:00 2001 From: nninkoviSQA Date: Mon, 4 Apr 2022 16:40:46 +0200 Subject: [PATCH 18/18] Fixed attached_deposit in factory unit tests. --- sputnikdao-factory2/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sputnikdao-factory2/src/lib.rs b/sputnikdao-factory2/src/lib.rs index 01477d8a5..b1f028e1f 100644 --- a/sputnikdao-factory2/src/lib.rs +++ b/sputnikdao-factory2/src/lib.rs @@ -460,7 +460,7 @@ mod tests { testing_env!(context .current_account_id(alice()) .predecessor_account_id(alice()) - .attached_deposit(10) + .attached_deposit(to_yocto("5")) .build()); let factory = SputnikDAOFactory::new(); @@ -474,7 +474,7 @@ mod tests { testing_env!(context .current_account_id(alice()) .predecessor_account_id(carol()) - .attached_deposit(10) + .attached_deposit(to_yocto("5")) .build()); let factory = SputnikDAOFactory::new(); @@ -487,7 +487,7 @@ mod tests { testing_env!(context .current_account_id(bob()) .predecessor_account_id(bob()) - .attached_deposit(10) + .attached_deposit(to_yocto("6")) .build()); let mut factory = SputnikDAOFactory::new(); @@ -507,7 +507,7 @@ mod tests { testing_env!(context .current_account_id(accounts(0)) .predecessor_account_id(accounts(0)) - .attached_deposit(10) + .attached_deposit(to_yocto("5")) .build()); let factory = SputnikDAOFactory::new();