-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
executable file
·67 lines (56 loc) · 1.9 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This has been built with the original flipper smart contract code from Parity
// Original Code available at https://github.com/paritytech/ink
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
#[ink::contract]
pub mod authorize_access {
#[ink(storage)]
pub struct AuthorizeAccess {
value: bool,
}
impl AuthorizeAccess {
/// Creates a new Authorize Acccess smart contract initialized with the given value.
#[ink(constructor)]
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
}
/// Creates a new Authorize Access smart contract initialized to `false`.
#[ink(constructor)]
pub fn default() -> Self {
Self::new(Default::default())
}
/// changes the current value of the Authorize Access's bool to true.
#[ink(message)]
pub fn authorize_access(&mut self) {
self.value = true;
}
/// changes the current value of the Authorize Access's bool to false.
#[ink(message)]
pub fn revoke_access(&mut self) {
self.value = false;
}
/// Returns the current value of the Authorize Access's bool.
#[ink(message)]
pub fn get(&self) -> bool {
self.value
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_works() {
let authorize_access = AuthorizeAccess::default();
assert_eq!(authorize_access.get(), false);
}
#[test]
fn it_works() {
let mut authorize_access = AuthorizeAccess::new(false);
assert_eq!(authorize_access.get(), false);
authorize_access.authorize_access();
assert_eq!(authorize_access.get(), true);
authorize_access.revoke_access();
assert_eq!(authorize_access.get(), false);
}
}
}