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