Skip to content

Commit

Permalink
use sdk.DefaultBondDenom for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Dec 28, 2023
1 parent 6740833 commit f63e6d8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
34 changes: 16 additions & 18 deletions x/opchild/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)

var baseDenom = sdk.DefaultBondDenom

type TestAnteKeeper struct {
minGasPrices sdk.DecCoins
}
Expand All @@ -27,7 +25,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {

// set price 0.5 base == 1 quote
fc := ante.NewMempoolFeeChecker(TestAnteKeeper{
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyZeroDec())),
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyZeroDec())),
})

// keys and addresses
Expand All @@ -36,7 +34,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {
// msg and signatures
// gas price 0.0005
msg := testdata.NewTestMsg(addr1)
feeAmount := sdk.NewCoins(sdk.NewCoin(baseDenom, math.NewInt(100)))
feeAmount := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100)))
gasLimit := uint64(200_000)

suite.Require().NoError(suite.txBuilder.SetMsgs(msg))
Expand All @@ -48,7 +46,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {
suite.Require().NoError(err)

// Set high gas price so standard test fee fails
basePrice := sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(200).Quo(math.LegacyNewDec(100000)))
basePrice := sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(200).Quo(math.LegacyNewDec(100000)))
highGasPrice := []sdk.DecCoin{basePrice}
suite.ctx = suite.ctx.WithMinGasPrices(highGasPrice)

Expand All @@ -70,7 +68,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {
suite.ctx = suite.ctx.WithIsCheckTx(true)

// gas price = 0.0005
basePrice = sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDecWithPrec(5, 4))
basePrice = sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDecWithPrec(5, 4))
lowGasPrice := []sdk.DecCoin{basePrice}
suite.ctx = suite.ctx.WithMinGasPrices(lowGasPrice)

Expand All @@ -79,7 +77,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {

// set high base_min_gas_price to test should be failed
fc = ante.NewMempoolFeeChecker(TestAnteKeeper{
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(200).Quo(math.LegacyNewDec(100000)))),
minGasPrices: sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(200).Quo(math.LegacyNewDec(100000)))),
})

suite.txBuilder.SetFeeAmount(feeAmount)
Expand All @@ -88,33 +86,33 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {
}

func (suite *AnteTestSuite) TestCombinedMinGasPrices() {
minGasPrices := sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(100)))
configMinGasPrices := sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(100)))
minGasPrices := sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(100)))
configMinGasPrices := sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(100)))

combined := ante.CombinedMinGasPrices(minGasPrices, configMinGasPrices)
suite.Require().Len(combined, 1)
suite.Require().True(combined.AmountOf(baseDenom).Equal(math.LegacyNewDec(100)))
suite.Require().True(combined.AmountOf(sdk.DefaultBondDenom).Equal(math.LegacyNewDec(100)))

configMinGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(150)))
configMinGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(150)))
combined = ante.CombinedMinGasPrices(minGasPrices, configMinGasPrices)
suite.Require().Len(combined, 1)
suite.Require().True(combined.AmountOf(baseDenom).Equal(math.LegacyNewDec(150)))
suite.Require().True(combined.AmountOf(sdk.DefaultBondDenom).Equal(math.LegacyNewDec(150)))

minGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(200)))
minGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(200)))
combined = ante.CombinedMinGasPrices(minGasPrices, configMinGasPrices)
suite.Require().Len(combined, 1)
suite.Require().True(combined.AmountOf(baseDenom).Equal(math.LegacyNewDec(200)))
suite.Require().True(combined.AmountOf(sdk.DefaultBondDenom).Equal(math.LegacyNewDec(200)))

configMinGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(100)), sdk.NewDecCoinFromDec("test", math.LegacyNewDec(100)))
configMinGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(100)), sdk.NewDecCoinFromDec("test", math.LegacyNewDec(100)))
combined = ante.CombinedMinGasPrices(minGasPrices, configMinGasPrices)
suite.Require().Len(combined, 2)
suite.Require().True(combined.AmountOf(baseDenom).Equal(math.LegacyNewDec(200)))
suite.Require().True(combined.AmountOf(sdk.DefaultBondDenom).Equal(math.LegacyNewDec(200)))
suite.Require().True(combined.AmountOf("test").Equal(math.LegacyNewDec(100)))

minGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(baseDenom, math.LegacyNewDec(100)), sdk.NewDecCoinFromDec("test2", math.LegacyNewDec(300)))
minGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDec(100)), sdk.NewDecCoinFromDec("test2", math.LegacyNewDec(300)))
combined = ante.CombinedMinGasPrices(minGasPrices, configMinGasPrices)
suite.Require().Len(combined, 3)
suite.Require().True(combined.AmountOf(baseDenom).Equal(math.LegacyNewDec(100)))
suite.Require().True(combined.AmountOf(sdk.DefaultBondDenom).Equal(math.LegacyNewDec(100)))
suite.Require().True(combined.AmountOf("test").Equal(math.LegacyNewDec(100)))
suite.Require().True(combined.AmountOf("test2").Equal(math.LegacyNewDec(300)))
}
4 changes: 1 addition & 3 deletions x/opchild/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ import (
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
)

const baseDenom = "umin"

var ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
bank.AppModuleBasic{},
Expand Down Expand Up @@ -145,7 +143,7 @@ func MakeEncodingConfig(_ testing.TB) EncodingConfig {
}

func initialTotalSupply() sdk.Coins {
faucetBalance := sdk.NewCoins(sdk.NewCoin(baseDenom, initiaSupply))
faucetBalance := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initiaSupply))
for _, testDenom := range testDenoms {
faucetBalance = faucetBalance.Add(sdk.NewCoin(testDenom, initiaSupply))
}
Expand Down
6 changes: 3 additions & 3 deletions x/opchild/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ func Test_MsgServer_SpendFeePool(t *testing.T) {
ms := keeper.NewMsgServerImpl(input.OPChildKeeper)

// fund fee pool
collectedFees := sdk.NewCoins(sdk.NewCoin(baseDenom, math.NewInt(100)))
collectedFees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100)))
input.Faucet.Fund(ctx, authtypes.NewModuleAddress(authtypes.FeeCollectorName), collectedFees...)

beforeAmount := input.BankKeeper.GetBalance(ctx, addrs[1], baseDenom).Amount
beforeAmount := input.BankKeeper.GetBalance(ctx, addrs[1], sdk.DefaultBondDenom).Amount

msg := types.NewMsgSpendFeePool(
authtypes.NewModuleAddress(types.ModuleName),
Expand All @@ -198,7 +198,7 @@ func Test_MsgServer_SpendFeePool(t *testing.T) {
_, err := ms.SpendFeePool(ctx, msg)
require.NoError(t, err)

afterAmount := input.BankKeeper.GetBalance(ctx, addrs[1], baseDenom).Amount
afterAmount := input.BankKeeper.GetBalance(ctx, addrs[1], sdk.DefaultBondDenom).Amount
require.Equal(t, beforeAmount.Add(math.NewInt(100)), afterAmount)
}

Expand Down
4 changes: 1 addition & 3 deletions x/ophost/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import (
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
)

const baseDenom = "umin"

var ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
bank.AppModuleBasic{},
Expand Down Expand Up @@ -130,7 +128,7 @@ func MakeEncodingConfig(_ testing.TB) EncodingConfig {
}

func initialTotalSupply() sdk.Coins {
faucetBalance := sdk.NewCoins(sdk.NewCoin(baseDenom, initiaSupply))
faucetBalance := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initiaSupply))
for _, testDenom := range testDenoms {
faucetBalance = faucetBalance.Add(sdk.NewCoin(testDenom, initiaSupply))
}
Expand Down
6 changes: 3 additions & 3 deletions x/ophost/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ func Test_InitiateTokenDeposit(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(1), createRes.BridgeId)

amount := sdk.NewCoin(baseDenom, math.NewInt(100))
amount := sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))
input.Faucet.Fund(ctx, addrs[1], amount)
_, err = ms.InitiateTokenDeposit(
ctx,
types.NewMsgInitiateTokenDeposit(addrsStr[1], 1, addrsStr[2], amount, []byte("messages")),
)
require.NoError(t, err)
require.True(t, input.BankKeeper.GetBalance(ctx, addrs[1], baseDenom).IsZero())
require.Equal(t, amount, input.BankKeeper.GetBalance(ctx, types.BridgeAddress(1), baseDenom))
require.True(t, input.BankKeeper.GetBalance(ctx, addrs[1], sdk.DefaultBondDenom).IsZero())
require.Equal(t, amount, input.BankKeeper.GetBalance(ctx, types.BridgeAddress(1), sdk.DefaultBondDenom))
}

func Test_FinalizeTokenWithdrawal(t *testing.T) {
Expand Down

0 comments on commit f63e6d8

Please sign in to comment.