-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * some more migration progress * fixed all todos, removed JarState * fixed claim * all tests passing * store last jar index in contract * fixed and updated integration tests * claim jars by indices * remove account id from withdraw api * remeasure after claim * return slices instead of vector for account jars getter * remove account id parameter from restake * added documentation * renamed index to ID * added ids to get principal and get interest * store last jar id for each user * ID -> Id * increment jar index in one place * delete jar only after full claim and withdraw, some test fixes * new github token * Rename * delete empty jar on after_claim * extracted claim_interest * removed unreachable test part * build push binary in docker --------- Co-authored-by: Vasily Styagov <[email protected]>
- Loading branch information
1 parent
d2bbae1
commit c10c09f
Showing
29 changed files
with
1,152 additions
and
862 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,2 @@ | ||
pub mod api; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use near_sdk::{json_types::U128, test_utils::accounts, PromiseOrValue}; | ||
|
||
use crate::{ | ||
claim::api::ClaimApi, | ||
common::{tests::Context, u32::U32, udecimal::UDecimal, MS_IN_YEAR}, | ||
jar::{api::JarApi, model::Jar}, | ||
product::model::{Apy, Product}, | ||
}; | ||
|
||
#[test] | ||
fn claim_total_when_nothing_to_claim() { | ||
let alice = accounts(0); | ||
let admin = accounts(1); | ||
|
||
let product = generate_product(); | ||
let jar = Jar::generate(0, &alice, &product.id).principal(100_000_000); | ||
let mut context = Context::new(admin).with_products(&[product]).with_jars(&[jar]); | ||
|
||
context.switch_account(&alice); | ||
let result = context.contract.claim_total(); | ||
|
||
if let PromiseOrValue::Value(value) = result { | ||
assert_eq!(0, value.0); | ||
} else { | ||
panic!(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn claim_partially_when_having_tokens_to_claim() { | ||
let alice = accounts(0); | ||
let admin = accounts(1); | ||
|
||
let product = generate_product(); | ||
let jar = Jar::generate(0, &alice, &product.id).principal(100_000_000_000); | ||
let mut context = Context::new(admin).with_products(&[product]).with_jars(&[jar.clone()]); | ||
|
||
context.set_block_timestamp_in_days(365); | ||
|
||
context.switch_account(&alice); | ||
context.contract.claim_jars(vec![jar.index], Some(U128(100))); | ||
|
||
let jar = context.contract.get_jar(U32(jar.index)); | ||
assert_eq!(100, jar.claimed_balance.0); | ||
} | ||
|
||
fn generate_product() -> Product { | ||
Product::generate("product") | ||
.enabled(true) | ||
.lockup_term(MS_IN_YEAR) | ||
.apy(Apy::Constant(UDecimal::new(12, 2))) | ||
} | ||
} | ||
mod tests; |
Oops, something went wrong.