mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
4a8b5696cb
* initial sketch * add module migrations * add migrations for all accout types * test account migration * add tendermint migration and migrate cmd * remove need for errors pkg dependency * add bech32 decoding fork * add suggested params and cmd to write them * add basic upgrade instructions * fix tests * address some migration todos * tidy contrib folder * finalize params values * align cdp init genesis with other modules * add tendermint and distribution test add custom distribution migration to patch bug * add staking migration test * add slashing, evidence tests, refactor auth tests * add full migration test * remove go-amino dependency from go.mod also tidy up unused indirect dependencies * address remaining TODOs * remove commented out code from legacy types * add spot/liquidation markets ids to kava-3 params * Apply suggestions from code review Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * address code review suggestions * add validate genesis to migrate test * refactor add params func * remove commented out code from old types * fix add params * add deputy address * add tests using exported kava-2 state * incorporate new cdp params from master * update params from review Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> * add deputy account * add committee permissions for new params Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/cdp/keeper"
|
|
"github.com/kava-labs/kava/x/cdp/types"
|
|
)
|
|
|
|
type SavingsTestSuite struct {
|
|
suite.Suite
|
|
|
|
keeper keeper.Keeper
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
addrs []sdk.AccAddress
|
|
}
|
|
|
|
func (suite *SavingsTestSuite) SetupTest() {
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(3)
|
|
authGS := app.NewAuthGenState(
|
|
addrs,
|
|
[]sdk.Coins{
|
|
cs(c("usdx", 100000)), cs(c("usdx", 50000)), cs(c("usdx", 50000)),
|
|
},
|
|
)
|
|
tApp.InitializeFromGenesisStates(
|
|
authGS,
|
|
NewPricefeedGenStateMulti(),
|
|
NewCDPGenStateMulti(),
|
|
)
|
|
sk := tApp.GetSupplyKeeper()
|
|
macc := sk.GetModuleAccount(ctx, types.SavingsRateMacc)
|
|
err := sk.MintCoins(ctx, macc.GetName(), cs(c("usdx", 10000)))
|
|
suite.NoError(err)
|
|
keeper := tApp.GetCDPKeeper()
|
|
suite.app = tApp
|
|
suite.keeper = keeper
|
|
suite.ctx = ctx
|
|
suite.addrs = addrs
|
|
}
|
|
|
|
func (suite *SavingsTestSuite) TestApplySavingsRate() {
|
|
err := suite.keeper.DistributeSavingsRate(suite.ctx, "usdx")
|
|
suite.NoError(err)
|
|
ak := suite.app.GetAccountKeeper()
|
|
acc0 := ak.GetAccount(suite.ctx, suite.addrs[0])
|
|
suite.Equal(cs(c("usdx", 105000)), acc0.GetCoins())
|
|
acc1 := ak.GetAccount(suite.ctx, suite.addrs[1])
|
|
suite.Equal(cs(c("usdx", 52500)), acc1.GetCoins())
|
|
acc2 := ak.GetAccount(suite.ctx, suite.addrs[2])
|
|
suite.Equal(cs(c("usdx", 52500)), acc2.GetCoins())
|
|
sk := suite.app.GetSupplyKeeper()
|
|
macc := sk.GetModuleAccount(suite.ctx, types.SavingsRateMacc)
|
|
suite.True(macc.GetCoins().AmountOf("usdx").IsZero())
|
|
}
|
|
|
|
func (suite *SavingsTestSuite) TestGetSetPreviousDistributionTime() {
|
|
now := tmtime.Now()
|
|
|
|
_, f := suite.keeper.GetPreviousSavingsDistribution(suite.ctx)
|
|
suite.Require().False(f) // distr time not set at genesis when the default genesis is used
|
|
|
|
suite.NotPanics(func() { suite.keeper.SetPreviousSavingsDistribution(suite.ctx, now) })
|
|
|
|
pdt, f := suite.keeper.GetPreviousSavingsDistribution(suite.ctx)
|
|
suite.True(f)
|
|
suite.Equal(now, pdt)
|
|
|
|
}
|
|
|
|
func TestSavingsTestSuite(t *testing.T) {
|
|
suite.Run(t, new(SavingsTestSuite))
|
|
}
|