From e163041b5ef08f1e5cf900105b7fccd8e2993883 Mon Sep 17 00:00:00 2001 From: herolind-sqa Date: Mon, 21 Mar 2022 14:53:39 +0100 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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() + ); } }