-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cd57d4
commit 962f248
Showing
9 changed files
with
139 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use model::Duration; | ||
use near_sdk::near_bindgen; | ||
|
||
use crate::{Contract, ContractExt}; | ||
|
||
pub trait ConfigApi { | ||
fn set_claim_period(&mut self, period: Duration); | ||
fn set_burn_period(&mut self, period: Duration); | ||
} | ||
|
||
#[near_bindgen] | ||
impl ConfigApi for Contract { | ||
fn set_claim_period(&mut self, period: Duration) { | ||
self.assert_oracle(); | ||
|
||
self.claim_period = period; | ||
} | ||
|
||
fn set_burn_period(&mut self, period: Duration) { | ||
self.assert_oracle(); | ||
|
||
self.burn_period = period; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod api; | ||
mod tests; |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#![cfg(test)] | ||
|
||
use crate::{common::tests::Context, config::api::ConfigApi}; | ||
|
||
#[test] | ||
fn set_claim_period_by_oracle() { | ||
let (mut context, mut contract, accounts) = Context::init_with_oracle(); | ||
|
||
let claim_period = 1_000_000; | ||
context.switch_account(&accounts.oracle); | ||
contract.set_claim_period(claim_period); | ||
|
||
assert_eq!(claim_period, contract.claim_period); | ||
|
||
let claim_period = 3_000_000; | ||
context.switch_account(&accounts.oracle); | ||
contract.set_claim_period(claim_period); | ||
|
||
assert_eq!(claim_period, contract.claim_period); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Unauthorized access")] | ||
fn set_claim_period_by_not_oracle() { | ||
let (mut context, mut contract, accounts) = Context::init_with_oracle(); | ||
|
||
let claim_period = 1_000_000; | ||
context.switch_account(&accounts.alice); | ||
contract.set_claim_period(claim_period); | ||
} | ||
|
||
#[test] | ||
fn set_burn_period_by_oracle() { | ||
let (mut context, mut contract, accounts) = Context::init_with_oracle(); | ||
|
||
let burn_period = 1_000_000; | ||
context.switch_account(&accounts.oracle); | ||
contract.set_burn_period(burn_period); | ||
|
||
assert_eq!(burn_period, contract.burn_period); | ||
|
||
let burn_period = 3_000_000; | ||
context.switch_account(&accounts.oracle); | ||
contract.set_burn_period(burn_period); | ||
|
||
assert_eq!(burn_period, contract.burn_period); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Unauthorized access")] | ||
fn set_burn_period_by_not_oracle() { | ||
let (mut context, mut contract, accounts) = Context::init_with_oracle(); | ||
|
||
let burn_period = 1_000_000; | ||
context.switch_account(&accounts.alice); | ||
contract.set_burn_period(burn_period); | ||
} |
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 +1,2 @@ | ||
pub(crate) mod api; | ||
mod tests; |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![cfg(test)] | ||
|
||
use model::api::{ClaimApi, RecordApi}; | ||
use near_sdk::{json_types::U128, test_utils::accounts}; | ||
|
||
use crate::common::tests::Context; | ||
|
||
#[test] | ||
fn record_by_oracle() { | ||
let (mut context, mut contract, accounts) = Context::init_with_oracle(); | ||
|
||
let alice_balance_1 = 1_000_000; | ||
|
||
context.switch_account(&accounts.oracle); | ||
contract.record_batch_for_hold(vec![(accounts.alice.clone(), U128(alice_balance_1))]); | ||
|
||
let alice_actual_balance = contract.get_claimable_balance_for_account(accounts.alice.clone()); | ||
assert_eq!(alice_balance_1, alice_actual_balance.0); | ||
|
||
context.set_block_timestamp_in_seconds(1_000); | ||
|
||
let alice_balance_2 = 500_000; | ||
let bob_balance = 200_000; | ||
|
||
contract.record_batch_for_hold(vec![ | ||
(accounts.alice.clone(), U128(alice_balance_2)), | ||
(accounts.bob.clone(), U128(bob_balance)), | ||
]); | ||
|
||
let alice_actual_balance = contract.get_claimable_balance_for_account(accounts.alice.clone()); | ||
assert_eq!(alice_balance_1 + alice_balance_2, alice_actual_balance.0); | ||
|
||
let bob_actual_balance = contract.get_claimable_balance_for_account(accounts.bob.clone()); | ||
assert_eq!(bob_balance, bob_actual_balance.0); | ||
} |
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