mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
fix time elapsed calculation + test (#838)
This commit is contained in:
parent
6c88c01eb8
commit
0a51a737cb
@ -1,6 +1,8 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/kava-labs/kava/x/hard/types"
|
||||
@ -64,7 +66,9 @@ func (k Keeper) AccrueInterest(ctx sdk.Context, denom string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
timeElapsed := ctx.BlockTime().Unix() - previousAccrualTime.Unix()
|
||||
timeElapsed := int64(math.RoundToEven(
|
||||
ctx.BlockTime().Sub(previousAccrualTime).Seconds(),
|
||||
))
|
||||
if timeElapsed == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -887,7 +887,7 @@ func (suite *KeeperTestSuite) TestBorrowInterest() {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
// Set up snapshot chain context and run begin blocker
|
||||
runAtTime := time.Unix(prevCtx.BlockTime().Unix()+(snapshot.elapsedTime), 0)
|
||||
runAtTime := prevCtx.BlockTime().Add(time.Duration(int64(time.Second) * snapshot.elapsedTime))
|
||||
snapshotCtx := prevCtx.WithBlockTime(runAtTime)
|
||||
hard.BeginBlocker(snapshotCtx, suite.keeper)
|
||||
|
||||
@ -1317,7 +1317,7 @@ func (suite *KeeperTestSuite) TestSupplyInterest() {
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
// Set up snapshot chain context and run begin blocker
|
||||
runAtTime := time.Unix(prevCtx.BlockTime().Unix()+(snapshot.elapsedTime), 0)
|
||||
runAtTime := prevCtx.BlockTime().Add(time.Duration(int64(time.Second) * snapshot.elapsedTime))
|
||||
snapshotCtx := prevCtx.WithBlockTime(runAtTime)
|
||||
hard.BeginBlocker(snapshotCtx, suite.keeper)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user