Skip to content

Commit

Permalink
Merge pull request #146 from nninkovicSQA/TESTCOV-Sputnik-Factory-Own…
Browse files Browse the repository at this point in the history
…ership

TESTCOV: Sputnik Factory: Ownership
  • Loading branch information
TrevorJTClarke authored Apr 5, 2022
2 parents 32ca00a + 31af94d commit f7bc52c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions sputnikdao-factory2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ pub extern "C" fn store() {

#[cfg(test)]
mod tests {
use near_sdk::test_utils::test_env::{alice, bob, carol};
use near_sdk::test_utils::{accounts, VMContextBuilder};
use near_sdk::{testing_env, PromiseResult};

Expand Down Expand Up @@ -448,4 +449,72 @@ mod tests {
vec![format!("test.{}", accounts(0)).parse().unwrap()]
);
}

// ################################# //
// # Factory ownership 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(to_yocto("5"))
.build());
let factory = SputnikDAOFactory::new();

assert_eq!(factory.get_owner(), alice());
}

#[test]
#[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(to_yocto("5"))
.build());
let factory = SputnikDAOFactory::new();

factory.set_owner(bob());
}

#[test]
fn test_owner_can_be_a_dao_account() {
let mut context = VMContextBuilder::new();
testing_env!(context
.current_account_id(bob())
.predecessor_account_id(bob())
.attached_deposit(to_yocto("6"))
.build());
let mut factory = SputnikDAOFactory::new();

factory.create(bob(), "{}".as_bytes().to_vec().into());

factory.set_owner(AccountId::new_unchecked("bob.sputnik-dao.near".to_string()));

assert_eq!(
factory.get_owner(),
AccountId::new_unchecked("bob.sputnik-dao.near".to_string())
)
}

#[test]
fn test_owner_gets_succesfully_updated() {
let mut context = VMContextBuilder::new();
testing_env!(context
.current_account_id(accounts(0))
.predecessor_account_id(accounts(0))
.attached_deposit(to_yocto("5"))
.build());
let factory = SputnikDAOFactory::new();

assert_ne!(factory.get_owner(), bob());

factory.set_owner(bob());

assert_eq!(factory.get_owner(), bob())
}
}

0 comments on commit f7bc52c

Please sign in to comment.