Skip to content

Commit

Permalink
fix: genesis type cast (#1968)
Browse files Browse the repository at this point in the history
* fix genesis type cast

* changelog

* Update CHANGELOG.md

Co-authored-by: Adam Moser <63419657+toteki@users.noreply.github.com>

---------

Co-authored-by: Adam Moser <63419657+toteki@users.noreply.github.com>
  • Loading branch information
kosegor and toteki authored Mar 31, 2023
1 parent 4157464 commit 208d607
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1956](https://github.com/umee-network/umee/pull/1956) Leverage: token liquidation threshold must be bigger than collateral_weight.
- [1954](https://github.com/umee-network/umee/pull/1954) Leverage: `MaxBorrow` now accounts for
`MinCollateralLiquidity` and `MaxSupplyUtilization`
- [1968](https://github.com/umee-network/umee/pull/1968) Leverage: fix type cast of AdjustedBorrow in ExportGenesis

## [v4.2.0](https://github.com/umee-network/umee/releases/tag/v4.2.0) - 2023-03-15

Expand Down
4 changes: 2 additions & 2 deletions x/leverage/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func (k Keeper) getAllAdjustedBorrows(ctx sdk.Context) []types.AdjustedBorrow {
addr := types.AddressFromKey(key, prefix)
denom := types.DenomFromKeyWithAddress(key, prefix)

var amount sdkmath.Int
var amount sdk.Dec
if err := amount.Unmarshal(val); err != nil {
// improperly marshaled borrow amount should never happen
return err
}

borrows = append(borrows, types.NewAdjustedBorrow(addr.String(), sdk.NewDecCoin(denom, amount)))
borrows = append(borrows, types.NewAdjustedBorrow(addr.String(), sdk.NewDecCoinFromDec(denom, amount)))
return nil
}

Expand Down
58 changes: 58 additions & 0 deletions x/leverage/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package keeper_test

import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/umee-network/umee/v4/x/leverage/types"
"gotest.tools/v3/assert"
)

const (
testAddr = "umee1s84d29zk3k20xk9f0hvczkax90l9t94g72n6wm"
denom = "umee"
uDenom = "u/umee"
)

func (s *IntegrationTestSuite) TestKeeper_ExportGenesis() {
borrows := []types.AdjustedBorrow{
{
Address: testAddr,
Amount: sdk.NewDecCoin(denom, sdk.NewInt(100)),
},
}
collateral := []types.Collateral{
{
Address: testAddr,
Amount: sdk.NewCoin(uDenom, sdk.NewInt(1000)),
},
}
reserves := sdk.Coins{
sdk.NewCoin(denom, sdkmath.NewInt(10)),
}
badDebts := []types.BadDebt{
{
Address: testAddr,
Denom: denom,
},
}
interestScalars := []types.InterestScalar{
{
Denom: denom,
Scalar: sdk.NewDec(10),
},
}
genesis := types.DefaultGenesis()
genesis.AdjustedBorrows = borrows
genesis.Collateral = collateral
genesis.Reserves = reserves
genesis.BadDebts = badDebts
genesis.InterestScalars = interestScalars
s.app.LeverageKeeper.InitGenesis(s.ctx, *genesis)

export := s.app.LeverageKeeper.ExportGenesis(s.ctx)
assert.DeepEqual(s.T(), borrows, export.AdjustedBorrows)
assert.DeepEqual(s.T(), collateral, export.Collateral)
assert.DeepEqual(s.T(), reserves, export.Reserves)
assert.DeepEqual(s.T(), badDebts, export.BadDebts)
assert.DeepEqual(s.T(), interestScalars, export.InterestScalars)
}

0 comments on commit 208d607

Please sign in to comment.