chore: math lib update and type fixes (#12791)

## Description

Upgrades the math library in the repo root and find/replaces many usages of sdk.Dec, sdk.ZeroDec, sdk.OneDec, sdk.NewDec with their legacy-ified-math-lib replacements.

Note for review: I assume that I did not find 100% of usages

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Jacob Gadikian
2022-08-02 11:16:40 +00:00
committed by GitHub
parent 2932e11c1c
commit cb31043d35
91 changed files with 535 additions and 483 deletions
+2 -2
View File
@@ -39,9 +39,9 @@ func TestDecodeStore(t *testing.T) {
val, err := types.NewValidator(valAddr1, delPk1, types.NewDescription("test", "test", "test", "test", "test"))
require.NoError(t, err)
del := types.NewDelegation(delAddr1, valAddr1, sdk.OneDec())
del := types.NewDelegation(delAddr1, valAddr1, math.LegacyOneDec())
ubd := types.NewUnbondingDelegation(delAddr1, valAddr1, 15, bondTime, math.OneInt())
red := types.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, math.OneInt(), sdk.OneDec())
red := types.NewRedelegation(delAddr1, valAddr1, valAddr1, 12, bondTime, math.OneInt(), math.LegacyOneDec())
kvPairs := kv.Pairs{
Pairs: []kv.Pair{
+8 -7
View File
@@ -6,6 +6,7 @@ import (
"testing"
"time"
"cosmossdk.io/math"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
@@ -119,7 +120,7 @@ func TestSimulateMsgCancelUnbondingDelegation(t *testing.T) {
delegator := accounts[1]
delegation := types.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares)
app.StakingKeeper.SetDelegation(ctx, delegation)
app.DistrKeeper.SetDelegatorStartingInfo(ctx, validator0.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, sdk.OneDec(), 200))
app.DistrKeeper.SetDelegatorStartingInfo(ctx, validator0.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))
setupValidatorRewards(app, ctx, validator0.GetOperator())
@@ -233,7 +234,7 @@ func TestSimulateMsgUndelegate(t *testing.T) {
delegator := accounts[1]
delegation := types.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares)
app.StakingKeeper.SetDelegation(ctx, delegation)
app.DistrKeeper.SetDelegatorStartingInfo(ctx, validator0.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, sdk.OneDec(), 200))
app.DistrKeeper.SetDelegatorStartingInfo(ctx, validator0.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))
setupValidatorRewards(app, ctx, validator0.GetOperator())
@@ -281,7 +282,7 @@ func TestSimulateMsgBeginRedelegate(t *testing.T) {
delegator := accounts[2]
delegation := types.NewDelegation(delegator.Address, validator1.GetOperator(), issuedShares)
app.StakingKeeper.SetDelegation(ctx, delegation)
app.DistrKeeper.SetDelegatorStartingInfo(ctx, validator1.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, sdk.OneDec(), 200))
app.DistrKeeper.SetDelegatorStartingInfo(ctx, validator1.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, math.LegacyOneDec(), 200))
setupValidatorRewards(app, ctx, validator0.GetOperator())
setupValidatorRewards(app, ctx, validator1.GetOperator())
@@ -351,12 +352,12 @@ func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.S
}
func getTestingValidator0(t *testing.T, app *simapp.SimApp, ctx sdk.Context, accounts []simtypes.Account) types.Validator {
commission0 := types.NewCommission(sdk.ZeroDec(), sdk.OneDec(), sdk.OneDec())
commission0 := types.NewCommission(math.LegacyZeroDec(), math.LegacyOneDec(), math.LegacyOneDec())
return getTestingValidator(t, app, ctx, accounts, commission0, 0)
}
func getTestingValidator1(t *testing.T, app *simapp.SimApp, ctx sdk.Context, accounts []simtypes.Account) types.Validator {
commission1 := types.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
commission1 := types.NewCommission(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())
return getTestingValidator(t, app, ctx, accounts, commission1, 1)
}
@@ -368,7 +369,7 @@ func getTestingValidator(t *testing.T, app *simapp.SimApp, ctx sdk.Context, acco
validator, err := validator.SetInitialCommission(commission)
require.NoError(t, err)
validator.DelegatorShares = sdk.NewDec(100)
validator.DelegatorShares = math.LegacyNewDec(100)
validator.Tokens = app.StakingKeeper.TokensFromConsensusPower(ctx, 100)
app.StakingKeeper.SetValidator(ctx, validator)
@@ -377,7 +378,7 @@ func getTestingValidator(t *testing.T, app *simapp.SimApp, ctx sdk.Context, acco
}
func setupValidatorRewards(app *simapp.SimApp, ctx sdk.Context, valAddress sdk.ValAddress) {
decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.OneDec())}
decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyOneDec())}
historicalRewards := distrtypes.NewValidatorHistoricalRewards(decCoins, 2)
app.DistrKeeper.SetValidatorHistoricalRewards(ctx, valAddress, 2, historicalRewards)
// setup current revards