Skip to content

Commit

Permalink
chore: use sdkmath alias for cosmossdk.io/math (cosmos#3772)
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Jun 7, 2023
1 parent 1297551 commit 3491550
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 84 deletions.
4 changes: 2 additions & 2 deletions e2e/tests/transfer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() {
actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom)
s.Require().NoError(err)

expectedTotalEscrow := sdk.NewCoin(chainADenom, math.NewInt(testvalues.IBCTransferAmount))
expectedTotalEscrow := sdk.NewCoin(chainADenom, sdkmath.NewInt(testvalues.IBCTransferAmount))
s.Require().Equal(expectedTotalEscrow, actualTotalEscrow)
}
})
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/upgrades/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand Down Expand Up @@ -668,7 +668,7 @@ func (s *UpgradeTestSuite) TestV7ToV7_1ChainUpgrade() {
actualTotalEscrow, err := s.QueryTotalEscrowForDenom(ctx, chainA, chainADenom)
s.Require().NoError(err)

expectedTotalEscrow := sdk.NewCoin(chainADenom, math.NewInt(testvalues.IBCTransferAmount))
expectedTotalEscrow := sdk.NewCoin(chainADenom, sdkmath.NewInt(testvalues.IBCTransferAmount))
s.Require().Equal(expectedTotalEscrow, actualTotalEscrow) // migration has run and total escrow amount has been set
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"math/rand"
"testing"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
Expand Down Expand Up @@ -34,7 +34,7 @@ func TestRandomizedGenState(t *testing.T) {
Rand: r,
NumBonded: 3,
Accounts: simtypes.RandomAccounts(r, 3),
InitialStake: math.NewInt(1000),
InitialStake: sdkmath.NewInt(1000),
GenState: make(map[string]json.RawMessage),
}

Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper_test
import (
"fmt"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand Down Expand Up @@ -38,7 +38,7 @@ func (suite *KeeperTestSuite) TestGenesis() {
suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), denomTrace)

denom := denomTrace.IBCDenom()
amount, ok := math.NewIntFromString(pathAndEscrowAmount.escrow)
amount, ok := sdkmath.NewIntFromString(pathAndEscrowAmount.escrow)
suite.Require().True(ok)
escrows = append(sdk.NewCoins(sdk.NewCoin(denom, amount)), escrows...)
suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(denom, amount))
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper_test
import (
"fmt"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"

Expand Down Expand Up @@ -266,7 +266,7 @@ func (suite *KeeperTestSuite) TestEscrowAddress() {
func (suite *KeeperTestSuite) TestTotalEscrowForDenom() {
var (
req *types.QueryTotalEscrowForDenomRequest
expEscrowAmount math.Int
expEscrowAmount sdkmath.Int
)

testCases := []struct {
Expand All @@ -281,7 +281,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() {
Denom: sdk.DefaultBondDenom,
}

expEscrowAmount = math.NewInt(100)
expEscrowAmount = sdkmath.NewInt(100)
suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, expEscrowAmount))
},
true,
Expand All @@ -295,7 +295,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() {
}

suite.chainA.GetSimApp().TransferKeeper.SetDenomTrace(suite.chainA.GetContext(), denomTrace)
expEscrowAmount, ok := math.NewIntFromString("100000000000000000000")
expEscrowAmount, ok := sdkmath.NewIntFromString("100000000000000000000")
suite.Require().True(ok)
suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, expEscrowAmount))

Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/invariants_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package keeper_test

import (
"cosmossdk.io/math"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
)
Expand All @@ -23,7 +23,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowPerDenomInvariant() {
"fails with broken invariant",
func() {
// set amount for denom higher than actual value in escrow
amount := math.NewInt(200)
amount := sdkmath.NewInt(200)
suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(suite.chainA.GetContext(), sdk.NewCoin(sdk.DefaultBondDenom, amount))
},
false,
Expand All @@ -38,7 +38,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowPerDenomInvariant() {
path := NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

amount := math.NewInt(100)
amount := sdkmath.NewInt(100)

// send coins from chain A to chain B so that we have them in escrow
coin := sdk.NewCoin(sdk.DefaultBondDenom, amount)
Expand Down
26 changes: 13 additions & 13 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestKeeperTestSuite(t *testing.T) {

func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() {
const denom = "atom"
var expAmount math.Int
var expAmount sdkmath.Int

testCases := []struct {
name string
Expand All @@ -67,21 +67,21 @@ func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() {
{
"success: with escrow amount > 2^63",
func() {
expAmount, _ = math.NewIntFromString("100000000000000000000")
expAmount, _ = sdkmath.NewIntFromString("100000000000000000000")
},
true,
},
{
"success: escrow amount 0 is not stored",
func() {
expAmount = math.ZeroInt()
expAmount = sdkmath.ZeroInt()
},
true,
},
{
"failure: setter panics with negative escrow amount",
func() {
expAmount = math.NewInt(-1)
expAmount = sdkmath.NewInt(-1)
},
false,
},
Expand All @@ -92,7 +92,7 @@ func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() {

suite.Run(tc.name, func() {
suite.SetupTest() // reset
expAmount = math.NewInt(100)
expAmount = sdkmath.NewInt(100)
ctx := suite.chainA.GetContext()

tc.malleate()
Expand All @@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() {
suite.chainA.GetSimApp().TransferKeeper.SetTotalEscrowForDenom(ctx, sdk.NewCoin(denom, expAmount))
})
total := suite.chainA.GetSimApp().TransferKeeper.GetTotalEscrowForDenom(ctx, denom)
suite.Require().Equal(math.ZeroInt(), total.Amount)
suite.Require().Equal(sdkmath.ZeroInt(), total.Amount)
}
})
}
Expand All @@ -137,7 +137,7 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
"success",
func() {
denom := "uatom"
amount := math.NewInt(100)
amount := sdkmath.NewInt(100)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
Expand All @@ -149,14 +149,14 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
"success: multiple denoms",
func() {
denom := "uatom"
amount := math.NewInt(100)
amount := sdkmath.NewInt(100)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
store.Set(types.TotalEscrowForDenomKey(denom), bz)

denom = "bar/foo"
amount = math.NewInt(50)
amount = sdkmath.NewInt(50)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz = cdc.MustMarshal(&sdk.IntProto{Int: amount})
Expand All @@ -168,7 +168,7 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
"success: denom with non-alphanumeric characters",
func() {
denom := "ibc/123-456"
amount := math.NewInt(100)
amount := sdkmath.NewInt(100)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
Expand All @@ -180,7 +180,7 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
"failure: empty denom",
func() {
denom := ""
amount := math.ZeroInt()
amount := sdkmath.ZeroInt()

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
store.Set(types.TotalEscrowForDenomKey(denom), bz)
Expand All @@ -191,7 +191,7 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
"failure: wrong prefix key",
func() {
denom := "uatom"
amount := math.ZeroInt()
amount := sdkmath.ZeroInt()

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
store.Set([]byte(fmt.Sprintf("wrong-prefix/%s", denom)), bz)
Expand Down
10 changes: 5 additions & 5 deletions modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/cometbft/cometbft/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -88,7 +88,7 @@ type Balance struct {
ID string
Address string
Denom string
Amount math.Int
Amount sdkmath.Int
}

func AddressFromString(address string) string {
Expand Down Expand Up @@ -168,12 +168,12 @@ func OnRecvPacketTestCaseFromTla(tc TlaOnRecvPacketTestCase) OnRecvPacketTestCas
var addressMap = make(map[string]string)

type Bank struct {
balances map[OwnedCoin]math.Int
balances map[OwnedCoin]sdkmath.Int
}

// Make an empty bank
func MakeBank() Bank {
return Bank{balances: make(map[OwnedCoin]math.Int)}
return Bank{balances: make(map[OwnedCoin]sdkmath.Int)}
}

// Subtract other bank from this bank
Expand All @@ -196,7 +196,7 @@ func (bank *Bank) Sub(other *Bank) Bank {
}

// Set specific bank balance
func (bank *Bank) SetBalance(address string, denom string, amount math.Int) {
func (bank *Bank) SetBalance(address string, denom string, amount sdkmath.Int) {
bank.balances[OwnedCoin{address, denom}] = amount
}

Expand Down
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper_test
import (
"fmt"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"

Expand Down Expand Up @@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() {
testCases := []struct {
msg string
malleate func()
expectedEscrowAmt math.Int
expectedEscrowAmt sdkmath.Int
}{
{
"success: one native denom escrowed in one channel",
Expand All @@ -179,7 +179,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() {
// funds the escrow account to have balance
suite.Require().NoError(banktestutil.FundAccount(suite.chainA.GetSimApp().BankKeeper, suite.chainA.GetContext(), escrowAddress, sdk.NewCoins(coin)))
},
math.NewInt(100),
sdkmath.NewInt(100),
},
{
"success: one native denom escrowed in two channels",
Expand All @@ -197,7 +197,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() {
suite.Require().NoError(banktestutil.FundAccount(suite.chainA.GetSimApp().BankKeeper, suite.chainA.GetContext(), escrowAddress1, sdk.NewCoins(coin1)))
suite.Require().NoError(banktestutil.FundAccount(suite.chainA.GetSimApp().BankKeeper, suite.chainA.GetContext(), escrowAddress2, sdk.NewCoins(coin2)))
},
math.NewInt(200),
sdkmath.NewInt(200),
},
{
"success: valid ibc denom escrowed in one channel",
Expand Down
Loading

0 comments on commit 3491550

Please sign in to comment.