refactor(math)!: remove aliases in math (#16040)
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
@@ -45,7 +46,7 @@ type fixture struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
sdk.DefaultPowerReduction = math.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
}
|
||||
|
||||
// intended to be used with require/assert: require.True(ValEq(...))
|
||||
|
||||
@@ -97,7 +97,7 @@ func doUnbondingDelegation(
|
||||
notBondedAmt1 := bankKeeper.GetBalance(ctx, stakingKeeper.GetNotBondedPool(ctx).GetAddress(), bondDenom).Amount
|
||||
|
||||
var err error
|
||||
undelegateAmount := sdk.NewDec(1)
|
||||
undelegateAmount := math.LegacyNewDec(1)
|
||||
completionTime, undelegatedAmount, err := stakingKeeper.Undelegate(ctx, addrDels[0], addrVals[0], undelegateAmount)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, undelegateAmount.Equal(math.LegacyNewDecFromInt(undelegatedAmount)))
|
||||
@@ -128,13 +128,13 @@ func doRedelegation(
|
||||
hookCalled *bool,
|
||||
) (completionTime time.Time) {
|
||||
var err error
|
||||
completionTime, err = stakingKeeper.BeginRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1], sdk.NewDec(1))
|
||||
completionTime, err = stakingKeeper.BeginRedelegation(ctx, addrDels[0], addrVals[0], addrVals[1], math.LegacyNewDec(1))
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Check that the redelegation happened- we look up the entry and see that it has the correct number of shares
|
||||
redelegations := stakingKeeper.GetRedelegationsFromSrcValidator(ctx, addrVals[0])
|
||||
assert.Equal(t, 1, len(redelegations))
|
||||
assert.DeepEqual(t, sdk.NewDec(1), redelegations[0].Entries[0].SharesDst)
|
||||
assert.DeepEqual(t, math.LegacyNewDec(1), redelegations[0].Entries[0].SharesDst)
|
||||
|
||||
// check that our hook was called
|
||||
assert.Assert(t, *hookCalled)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -58,7 +59,7 @@ func BenchmarkGetValidatorDelegations(b *testing.B) {
|
||||
delegator := sdk.AccAddress(fmt.Sprintf("address%d", i))
|
||||
banktestutil.FundAccount(f.sdkCtx, f.bankKeeper, delegator,
|
||||
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(i)))))
|
||||
NewDel := types.NewDelegation(delegator, val, sdk.NewDec(int64(i)))
|
||||
NewDel := types.NewDelegation(delegator, val, math.LegacyNewDec(int64(i)))
|
||||
f.stakingKeeper.SetDelegation(f.sdkCtx, NewDel)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +92,7 @@ func BenchmarkGetValidatorDelegationsLegacy(b *testing.B) {
|
||||
delegator := sdk.AccAddress(fmt.Sprintf("address%d", i))
|
||||
banktestutil.FundAccount(f.sdkCtx, f.bankKeeper, delegator,
|
||||
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(i)))))
|
||||
NewDel := types.NewDelegation(delegator, val, sdk.NewDec(int64(i)))
|
||||
NewDel := types.NewDelegation(delegator, val, math.LegacyNewDec(int64(i)))
|
||||
f.stakingKeeper.SetDelegation(f.sdkCtx, NewDel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []math.Int{
|
||||
sdk.NewIntFromUint64(0),
|
||||
math.NewIntFromUint64(0),
|
||||
f.stakingKeeper.PowerReduction(f.sdkCtx).MulRaw(100),
|
||||
f.stakingKeeper.PowerReduction(f.sdkCtx),
|
||||
f.stakingKeeper.PowerReduction(f.sdkCtx).MulRaw(400),
|
||||
@@ -245,7 +245,7 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
||||
|
||||
// initialize some validators into the state
|
||||
amts := []math.Int{
|
||||
sdk.NewIntFromUint64(0),
|
||||
math.NewIntFromUint64(0),
|
||||
f.stakingKeeper.PowerReduction(f.sdkCtx).MulRaw(100),
|
||||
f.stakingKeeper.PowerReduction(f.sdkCtx),
|
||||
f.stakingKeeper.PowerReduction(f.sdkCtx).MulRaw(400),
|
||||
|
||||
Reference in New Issue
Block a user