Skip to content

Commit

Permalink
added view
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Mar 29, 2024
1 parent 35b4311 commit 48b15c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions contracts/voting_snapshot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn get_voter_information(self, voter: &AccountId) -> VoterInformation
pub fn get_voters_info(self, voters: Vec<AccountId>) -> Vec<(AccountId, VoterInformation)>
pub fn get_total_eligible_users(&self) -> u32
pub fn get_total_voters(&self) -> u32
pub fn get_eligible_voter_info(&self, account_id: &AccountId) -> Option<UserData>

// Callbacks:
pub fn on_refund_success(self, account_id: AccountId) -> ()
Expand Down
16 changes: 15 additions & 1 deletion contracts/voting_snapshot/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,27 @@ impl Contract {
.collect()
}

/// *View*: Returns amount of eligible users to become voters
pub fn get_total_eligible_users(&self) -> u32 {
self.total_eligible_users
}

/// *View*: Shows total number of voters that are registered
pub fn get_total_voters(&self) -> u32 {
self.total_voters
}

/// *View*: displays information about snapshot data for particular account
pub fn get_eligible_voter_info(&self, account_id: &AccountId) -> Option<UserData> {
self.eligible_voters.get(account_id).cloned()
}
}

#[cfg(test)]
mod tests {
use near_sdk::{testing_env, NearToken};

use crate::test_utils::*;
use crate::{test_utils::*, types::UserData};

#[test]
fn user_can_get_vote_config() {
Expand All @@ -124,6 +131,13 @@ mod tests {
let (_context, contract) = setup_ctr();

let vote_power = contract.get_vote_power(&acc(1)).unwrap();
assert_eq!(
Some(UserData {
stake: NearToken::from_near(1),
active_months: 1,
}),
contract.get_eligible_voter_info(&acc(1))
);
assert_eq!(vote_power, 11);
}

Expand Down

0 comments on commit 48b15c6

Please sign in to comment.