The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/staking/reward/values_test.go

41 lines
1.4 KiB

Make token supply related fns more accurate (#3509) * [staking] Move reward values from Network pkg to its own * Refactor code for the move * Implement logic to accurately set total supply Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Add totalPreStakingNetworkRewards to reward values * Implement GetTotalTokens for use in other packages Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [core] Move getGenesisSpec to core pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [core] Update gen spec docs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Hook in updateInitialRewardValues on node init * Add some docs for clarification Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Fix GetCirculatingSupply & GetTotalSupply RPCs * Updated err msg in staking reward values.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Move GetCirculatingSupply logic into internal pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [explorer] Update circulating supply & total supply vals Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Add Localnet rewards val & Errs * [internal] Make GetCirculatingSupply consistent with WhatPercentStakedNow Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Fix imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [consensus] Make PercentageForTimeStamp return 1 for non-mainnet chains Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Fix reward dec math + Testnet testnet vals Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Make all const reward vals ONE instead of ATTO Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal] Correct returned value to ONE instead of Atto Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Fix dec precision Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Fix TestGetPreStakingRewardsFromBlockNumber test Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [staking] Use TotalInitialTokens instead of TotalPreStakingTokens * Done so basis is off block 0 to account for phased mainnet release Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal] Fix GetCirculatingSupply Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
package reward
import (
"math/big"
"testing"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/numeric"
)
func TestFiveSecondsBaseStakedReward(t *testing.T) {
expectedNewReward := StakedBlocks.Mul(numeric.MustNewDecFromStr("5")).Quo(numeric.MustNewDecFromStr("8"))
if !expectedNewReward.Equal(FiveSecStakedBlocks) {
t.Errorf(
"Expected: %s, Got: %s", FiveSecStakedBlocks.String(), expectedNewReward.String(),
)
}
expectedNewReward = StakedBlocks.Mul(numeric.MustNewDecFromStr("2")).Quo(numeric.MustNewDecFromStr("8"))
if !expectedNewReward.Equal(TwoSecStakedBlocks) {
t.Errorf(
"Expected: %s, Got: %s", TwoSecStakedBlocks.String(), expectedNewReward.String(),
)
}
}
func TestGetPreStakingRewardsFromBlockNumber(t *testing.T) {
refMainnetRewards, _ := new(big.Int).SetString("319237464000000000000000000", 10)
mainnetRewards := getTotalPreStakingNetworkRewards(shardingconfig.MainNet)
if refMainnetRewards.Cmp(mainnetRewards) != 0 {
t.Errorf("Expected mainnet rewards to be %v NOT %v", refMainnetRewards, mainnetRewards)
}
refTestnetRewards, _ := new(big.Int).SetString("7104000000000000000000", 10)
testnetRewards := getTotalPreStakingNetworkRewards(shardingconfig.TestNet)
if refTestnetRewards.Cmp(testnetRewards) != 0 {
t.Errorf("Expected testnet rewards to be %v NOT %v", refTestnetRewards, testnetRewards)
}
}