refactor(math)!: remove aliases in math (#16040)
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
stakingapi "cosmossdk.io/api/cosmos/staking/v1beta1"
|
||||
txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
|
||||
vestingapi "cosmossdk.io/api/cosmos/vesting/v1beta1"
|
||||
"cosmossdk.io/math"
|
||||
"cosmossdk.io/x/evidence"
|
||||
feegrantmodule "cosmossdk.io/x/feegrant/module"
|
||||
"cosmossdk.io/x/tx/signing/aminojson"
|
||||
@@ -200,7 +201,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
|
||||
genericAuthPulsar := newAny(t, &authzapi.GenericAuthorization{Msg: "foo"})
|
||||
pubkeyAny, _ := codectypes.NewAnyWithValue(&secp256k1types.PubKey{Key: []byte("foo")})
|
||||
pubkeyAnyPulsar := newAny(t, &secp256k1.PubKey{Key: []byte("foo")})
|
||||
dec10bz, _ := types.NewDec(10).Marshal()
|
||||
dec10bz, _ := math.LegacyNewDec(10).Marshal()
|
||||
int123bz, _ := types.NewInt(123).Marshal()
|
||||
|
||||
cases := map[string]struct {
|
||||
@@ -251,7 +252,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
|
||||
pulsar: &distapi.DelegatorStartingInfo{},
|
||||
},
|
||||
"distribution/delegator_starting_info/non_zero_dec": {
|
||||
gogo: &disttypes.DelegatorStartingInfo{Stake: types.NewDec(10)},
|
||||
gogo: &disttypes.DelegatorStartingInfo{Stake: math.LegacyNewDec(10)},
|
||||
pulsar: &distapi.DelegatorStartingInfo{Stake: "10.000000000000000000"},
|
||||
protoUnmarshalFails: true,
|
||||
},
|
||||
@@ -331,7 +332,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
|
||||
"slashing/params/dec": {
|
||||
gogo: &slashingtypes.Params{
|
||||
DowntimeJailDuration: 1e9 + 7,
|
||||
MinSignedPerWindow: types.NewDec(10),
|
||||
MinSignedPerWindow: math.LegacyNewDec(10),
|
||||
},
|
||||
pulsar: &slashingapi.Params{
|
||||
DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7},
|
||||
|
||||
@@ -46,8 +46,8 @@ func TestGRPCParams(t *testing.T) {
|
||||
malleate: func() {
|
||||
params = types.Params{
|
||||
CommunityTax: sdk.NewDecWithPrec(3, 1),
|
||||
BaseProposerReward: sdk.ZeroDec(),
|
||||
BonusProposerReward: sdk.ZeroDec(),
|
||||
BaseProposerReward: math.LegacyZeroDec(),
|
||||
BonusProposerReward: math.LegacyZeroDec(),
|
||||
WithdrawAddrEnabled: true,
|
||||
}
|
||||
|
||||
|
||||
@@ -656,8 +656,8 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
Params: distrtypes.Params{
|
||||
CommunityTax: sdk.NewDecWithPrec(2, 0),
|
||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
||||
BaseProposerReward: sdk.ZeroDec(),
|
||||
BonusProposerReward: sdk.ZeroDec(),
|
||||
BaseProposerReward: math.LegacyZeroDec(),
|
||||
BonusProposerReward: math.LegacyZeroDec(),
|
||||
},
|
||||
},
|
||||
expErr: true,
|
||||
@@ -670,8 +670,8 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
Params: distrtypes.Params{
|
||||
CommunityTax: sdk.NewDecWithPrec(2, 0),
|
||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
||||
BaseProposerReward: sdk.ZeroDec(),
|
||||
BonusProposerReward: sdk.ZeroDec(),
|
||||
BaseProposerReward: math.LegacyZeroDec(),
|
||||
BonusProposerReward: math.LegacyZeroDec(),
|
||||
},
|
||||
},
|
||||
expErr: true,
|
||||
@@ -684,8 +684,8 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
Params: distrtypes.Params{
|
||||
CommunityTax: sdk.NewDecWithPrec(-2, 1),
|
||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
||||
BaseProposerReward: sdk.ZeroDec(),
|
||||
BonusProposerReward: sdk.ZeroDec(),
|
||||
BaseProposerReward: math.LegacyZeroDec(),
|
||||
BonusProposerReward: math.LegacyZeroDec(),
|
||||
},
|
||||
},
|
||||
expErr: true,
|
||||
@@ -698,7 +698,7 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
Params: distrtypes.Params{
|
||||
CommunityTax: communityTax,
|
||||
BaseProposerReward: sdk.NewDecWithPrec(1, 2),
|
||||
BonusProposerReward: sdk.ZeroDec(),
|
||||
BonusProposerReward: math.LegacyZeroDec(),
|
||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
||||
},
|
||||
},
|
||||
@@ -711,7 +711,7 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
Authority: f.distrKeeper.GetAuthority(),
|
||||
Params: distrtypes.Params{
|
||||
CommunityTax: communityTax,
|
||||
BaseProposerReward: sdk.ZeroDec(),
|
||||
BaseProposerReward: math.LegacyZeroDec(),
|
||||
BonusProposerReward: sdk.NewDecWithPrec(1, 2),
|
||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
||||
},
|
||||
@@ -725,8 +725,8 @@ func TestMsgUpdateParams(t *testing.T) {
|
||||
Authority: f.distrKeeper.GetAuthority(),
|
||||
Params: distrtypes.Params{
|
||||
CommunityTax: communityTax,
|
||||
BaseProposerReward: sdk.ZeroDec(),
|
||||
BonusProposerReward: sdk.ZeroDec(),
|
||||
BaseProposerReward: math.LegacyZeroDec(),
|
||||
BonusProposerReward: math.LegacyZeroDec(),
|
||||
WithdrawAddrEnabled: withdrawAddrEnabled,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"gotest.tools/v3/assert"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -255,10 +256,10 @@ func TestLegacyGRPCQueryTally(t *testing.T) {
|
||||
}
|
||||
|
||||
func v1TallyToV1Beta1Tally(t v1.TallyResult) v1beta1.TallyResult {
|
||||
yes, _ := sdk.NewIntFromString(t.YesCount)
|
||||
no, _ := sdk.NewIntFromString(t.NoCount)
|
||||
noWithVeto, _ := sdk.NewIntFromString(t.NoWithVetoCount)
|
||||
abstain, _ := sdk.NewIntFromString(t.AbstainCount)
|
||||
yes, _ := math.NewIntFromString(t.YesCount)
|
||||
no, _ := math.NewIntFromString(t.NoCount)
|
||||
noWithVeto, _ := math.NewIntFromString(t.NoWithVetoCount)
|
||||
abstain, _ := math.NewIntFromString(t.AbstainCount)
|
||||
return v1beta1.TallyResult{
|
||||
Yes: yes,
|
||||
No: no,
|
||||
|
||||
@@ -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