fix unit test

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-07 07:22:41 +00:00
parent 7e4db6e904
commit 3aba8f4c26
3 changed files with 14 additions and 7 deletions

View file

@ -903,7 +903,7 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
}
if c.HookReward != nil && number%rCheckpoint == 0 {
if !c.EnableCache && c.BlockSigners.Len() >= 2700 {
if !c.EnableCache && uint64(c.BlockSigners.Len()) >= (rCheckpoint*3) {
fmt.Println("EnableCache true c.BlockSigners.Len()", c.BlockSigners.Len())
c.EnableCache = true
}

View file

@ -350,7 +350,7 @@ func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, blockSign
} else {
var wg sync.WaitGroup
squeue := make(chan []common.Address, 1)
wg.Add(900)
wg.Add(int(rCheckpoint))
for i := startBlockNumber; i <= endBlockNumber; i++ {
go func(i uint64) {
@ -484,6 +484,7 @@ func GetRewardBalancesRate(c *posv.Posv, foudationWalletAddr common.Address, mas
vote.Masternode = masterAddr
vote.Voter = voteAddr
if c != nil {
if vCap, ok := c.Votes.Get(vote); ok {
voterCap = vCap.(*big.Int)
} else {
@ -494,6 +495,12 @@ func GetRewardBalancesRate(c *posv.Posv, foudationWalletAddr common.Address, mas
fmt.Println("Add to Votes cache", vote.Masternode.String(), vote.Voter.String(), voterCap.String())
c.Votes.Add(vote, voterCap)
}
} else {
voterCap, err = validator.GetVoterCap(opts, masterAddr, voteAddr)
if err != nil {
log.Crit("Fail to get vote capacity", "error", err)
}
}
totalCap.Add(totalCap, voterCap)
voterCaps[voteAddr] = voterCap

View file

@ -144,7 +144,7 @@ func TestRewardBalance(t *testing.T) {
foundationAddr := common.HexToAddress(common.FoudationAddr)
totalReward := new(big.Int).SetInt64(15 * 1000)
rewards, err := contracts.GetRewardBalancesRate(foundationAddr, acc3Addr, totalReward, baseValidator)
rewards, err := contracts.GetRewardBalancesRate(nil, foundationAddr, acc3Addr, totalReward, baseValidator)
if err != nil {
t.Error("Fail to get reward balances rate.", err)
}