-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathview.rs
123 lines (105 loc) · 3.72 KB
/
view.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
mod setup;
use crate::setup::*;
#[test]
fn test_hash_schedule() {
let e = Env::init(None);
let amount = d(60000, TOKEN_DECIMALS);
let (lockup_schedule, vesting_schedule) = lockup_vesting_schedule_2(amount);
assert_eq!(
e.hash_schedule(&vesting_schedule),
e.hash_schedule(&vesting_schedule)
);
assert_ne!(
e.hash_schedule(&vesting_schedule),
e.hash_schedule(&lockup_schedule),
);
}
#[test]
fn test_validate_schedule() {
let e = Env::init(None);
let users = Users::init(&e);
let amount = d(60000, TOKEN_DECIMALS);
e.set_time_sec(GENESIS_TIMESTAMP_SEC);
let lockups = e.get_account_lockups(&users.alice);
assert!(lockups.is_empty());
let (lockup_schedule, vesting_schedule) = lockup_vesting_schedule_2(amount);
let res = e.validate_schedule(&lockup_schedule, amount.into(), Some(&vesting_schedule));
assert!(res.is_ok());
let incompatible_vesting_schedule = Schedule(vec![
Checkpoint {
timestamp: GENESIS_TIMESTAMP_SEC + ONE_YEAR_SEC * 4,
balance: 0,
},
Checkpoint {
timestamp: GENESIS_TIMESTAMP_SEC + ONE_YEAR_SEC * 4 + 1,
balance: amount,
},
]);
let res = e.validate_schedule(
&lockup_schedule,
amount.into(),
Some(&incompatible_vesting_schedule),
);
assert!(!res.is_ok());
assert!(format!("{:?}", res.unwrap_err()).contains("The lockup schedule is ahead of"));
}
#[test]
fn test_get_lockups() {
let e = Env::init(None);
let users = Users::init(&e);
let amount = d(1, TOKEN_DECIMALS);
e.set_time_sec(GENESIS_TIMESTAMP_SEC);
let lockups = e.get_account_lockups(&users.alice);
assert!(lockups.is_empty());
// create some lockups
for user in vec![&users.alice, &users.bob, &users.charlie] {
let balance: WrappedBalance = e
.add_lockup(
&e.owner,
amount,
&LockupCreate::new_unlocked(user.valid_account_id().clone(), amount),
)
.unwrap_json();
assert_eq!(balance.0, amount);
}
// get_num_lockups
let num_lockups = e.get_num_lockups();
assert_eq!(num_lockups, 3);
// get_lockups by indices
let res = e.get_lockups(&vec![2, 0]);
assert_eq!(res.len(), 2);
assert_eq!(res[0].1.account_id, users.charlie.valid_account_id());
assert_eq!(res[1].1.account_id, users.alice.valid_account_id());
// get_lockups_paged from to
let res = e.get_lockups_paged(Some(1), Some(2));
assert_eq!(res.len(), 1);
assert_eq!(res[0].1.account_id, users.bob.valid_account_id());
// get_lockups_paged from
let res = e.get_lockups_paged(Some(1), None);
assert_eq!(res.len(), 2);
assert_eq!(res[0].1.account_id, users.bob.valid_account_id());
assert_eq!(res[1].1.account_id, users.charlie.valid_account_id());
// get_lockups_paged to
let res = e.get_lockups_paged(None, Some(2));
assert_eq!(res.len(), 2);
assert_eq!(res[0].1.account_id, users.alice.valid_account_id());
assert_eq!(res[1].1.account_id, users.bob.valid_account_id());
// get_lockups_paged all
let res = e.get_lockups_paged(None, None);
assert_eq!(res.len(), 3);
assert_eq!(res[0].1.account_id, users.alice.valid_account_id());
assert_eq!(res[1].1.account_id, users.bob.valid_account_id());
assert_eq!(res[2].1.account_id, users.charlie.valid_account_id());
}
#[test]
fn test_get_token_account_id() {
let e = Env::init(None);
let result = e.get_token_account_id();
assert_eq!(result, e.token.valid_account_id());
}
#[test]
fn test_get_version() {
let e = Env::init(None);
let result = e.get_version();
assert_eq!(result, env!("CARGO_PKG_VERSION").to_string());
}