|
1 | 1 | #![cfg(test)]
|
2 | 2 |
|
3 |
| -use fake::Fake; |
4 | 3 | use near_sdk::{
|
5 | 4 | json_types::{U128, U64},
|
6 | 5 | test_utils::test_env::alice,
|
7 | 6 | };
|
8 |
| -use sweat_jar_model::{UDecimal, MS_IN_YEAR}; |
9 |
| - |
10 |
| -use crate::{ |
11 |
| - common::{tests::Context, Timestamp}, |
12 |
| - jar::{ |
13 |
| - account::v1::AccountV1, |
14 |
| - model::{JarTicket, JarV2}, |
15 |
| - }, |
16 |
| - product::model::{Apy, FixedProductTerms, InterestCalculator, Product, Terms}, |
17 |
| - test_utils::admin, |
18 |
| -}; |
19 |
| -// TODO: move interest calculation tests to product module |
20 |
| - |
21 |
| -#[test] |
22 |
| -fn get_interest_before_maturity() { |
23 |
| - let terms = Terms::Fixed(FixedProductTerms { |
24 |
| - apy: Apy::Constant(UDecimal::new(12, 2)), |
25 |
| - lockup_term: 2 * MS_IN_YEAR, |
26 |
| - }); |
27 |
| - let jar = JarV2::new().with_deposit(0, 100_000_000); |
28 |
| - let account = AccountV1::default(); |
29 |
| - |
30 |
| - let (interest, _) = terms.get_interest(&account, &jar, MS_IN_YEAR); |
31 |
| - assert_eq!(12_000_000, interest); |
32 |
| -} |
33 |
| - |
34 |
| -#[test] |
35 |
| -fn get_interest_after_maturity() { |
36 |
| - let terms = Terms::Fixed(FixedProductTerms { |
37 |
| - apy: Apy::Constant(UDecimal::new(12, 2)), |
38 |
| - lockup_term: MS_IN_YEAR, |
39 |
| - }); |
40 |
| - let jar = JarV2::new().with_deposit(0, 100_000_000); |
41 |
| - let account = AccountV1::default(); |
42 |
| - |
43 |
| - let (interest, _) = terms.get_interest(&account, &jar, 400 * 24 * 60 * 60 * 1000); |
44 |
| - assert_eq!(12_000_000, interest); |
45 |
| -} |
46 | 7 |
|
47 |
| -#[test] |
48 |
| -fn interest_precision() { |
49 |
| - let terms = Terms::Fixed(FixedProductTerms { |
50 |
| - apy: Apy::Constant(UDecimal::new(1, 0)), |
51 |
| - lockup_term: MS_IN_YEAR, |
52 |
| - }); |
53 |
| - let jar = JarV2::new().with_deposit(0, u128::from(MS_IN_YEAR)); |
54 |
| - let account = AccountV1::default(); |
55 |
| - |
56 |
| - assert_eq!(terms.get_interest(&account, &jar, 10000000000).0, 10000000000); |
57 |
| - assert_eq!(terms.get_interest(&account, &jar, 10000000001).0, 10000000001); |
58 |
| - |
59 |
| - for _ in 0..100 { |
60 |
| - let time: Timestamp = (10..MS_IN_YEAR).fake(); |
61 |
| - assert_eq!(terms.get_interest(&account, &jar, time).0, time as u128); |
62 |
| - } |
63 |
| -} |
| 8 | +use crate::{common::tests::Context, jar::model::JarTicket, product::model::Product, test_utils::admin}; |
64 | 9 |
|
65 | 10 | #[test]
|
66 | 11 | #[should_panic(expected = "It's not possible to create new jars for this product")]
|
|
0 commit comments