-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/per 1k estimate always zero (#1152)
* add fix for return per 1k * extract helper and add test
- Loading branch information
1 parent
2bb5e20
commit 09e205b
Showing
3 changed files
with
64 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use codec::Compact; | ||
use substrate_fixed::types::U64F64; | ||
|
||
use super::mock::*; | ||
|
||
#[test] | ||
fn test_return_per_1000_tao() { | ||
let take = // 18% take to the Validator | ||
Compact::<u16>::from((U64F64::from_num(0.18 * u16::MAX as f64)).saturating_to_num::<u16>()); | ||
|
||
// 10_000 TAO total validator stake | ||
let total_stake = U64F64::from_num(10_000.0 * 1e9); | ||
// 1000 TAO emissions per day | ||
let emissions_per_day = U64F64::from_num(1000.0 * 1e9); | ||
|
||
let return_per_1000 = | ||
SubtensorModule::return_per_1000_tao_test(take, total_stake, emissions_per_day); | ||
|
||
// We expect 82 TAO per day with 10% of total_stake | ||
let expected_return_per_1000 = U64F64::from_num(82.0); | ||
|
||
let diff_from_expected: f64 = (return_per_1000 / U64F64::from_num(1e9)) | ||
.saturating_sub(expected_return_per_1000) | ||
.to_num::<f64>(); | ||
|
||
let eps: f64 = 0.0005e9; // Precision within 0.0005 TAO | ||
assert!( | ||
diff_from_expected.abs() <= eps, | ||
"Difference from expected: {} is greater than precision: {}", | ||
diff_from_expected, | ||
eps | ||
); | ||
} |
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,6 +1,7 @@ | ||
mod batch_tx; | ||
mod children; | ||
mod coinbase; | ||
mod delegate_info; | ||
mod difficulty; | ||
mod emission; | ||
mod epoch; | ||
|