diff --git a/osmotestutils/cli_helpers.go b/osmotestutils/cli_helpers.go new file mode 100644 index 00000000000..b1b511aa2ff --- /dev/null +++ b/osmotestutils/cli_helpers.go @@ -0,0 +1,14 @@ +package osmotestutils + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/testutil/network" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func DefaultFeeString(cfg network.Config) string { + feeCoins := sdk.NewCoins(sdk.NewCoin(cfg.BondDenom, sdk.NewInt(10))) + return fmt.Sprintf("--%s=%s", flags.FlagFees, feeCoins.String()) +} diff --git a/x/gamm/client/cli/cli_test.go b/x/gamm/client/cli/cli_test.go index a8c7cacae7a..f91668acc9c 100644 --- a/x/gamm/client/cli/cli_test.go +++ b/x/gamm/client/cli/cli_test.go @@ -16,6 +16,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" "github.com/osmosis-labs/osmosis/app" + "github.com/osmosis-labs/osmosis/osmotestutils" "github.com/osmosis-labs/osmosis/x/gamm/client/cli" gammtestutil "github.com/osmosis-labs/osmosis/x/gamm/client/testutil" "github.com/osmosis-labs/osmosis/x/gamm/types" @@ -78,7 +79,7 @@ func (s *IntegrationTestSuite) TestNewCreatePoolCmd() { newAddr, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 200000000), sdk.NewInt64Coin("node0token", 20000)), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) @@ -324,7 +325,7 @@ func (s *IntegrationTestSuite) TestNewCreatePoolCmd() { // common args fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), fmt.Sprintf("--%s=%s", flags.FlagGas, fmt.Sprint(300000)), } @@ -357,7 +358,7 @@ func (s IntegrationTestSuite) TestNewJoinPoolCmd() { newAddr, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 20000), sdk.NewInt64Coin("node0token", 20000)), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) @@ -495,7 +496,7 @@ func (s IntegrationTestSuite) TestNewSwapExactAmountOutCmd() { newAddr, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 20000), sdk.NewInt64Coin("node0token", 20000)), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) @@ -559,7 +560,7 @@ func (s IntegrationTestSuite) TestNewJoinSwapExternAmountInCmd() { newAddr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) @@ -667,7 +668,7 @@ func (s IntegrationTestSuite) TestNewJoinSwapShareAmountOutCmd() { newAddr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) @@ -1118,7 +1119,7 @@ func (s IntegrationTestSuite) TestNewSwapExactAmountInCmd() { newAddr, sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 20000), sdk.NewInt64Coin("node0token", 20000)), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) diff --git a/x/gamm/keeper/invariants.go b/x/gamm/keeper/invariants.go index e8168964da4..2d37f5fbfe5 100644 --- a/x/gamm/keeper/invariants.go +++ b/x/gamm/keeper/invariants.go @@ -43,7 +43,7 @@ func PoolAccountInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant { pools, err := keeper.GetPools(ctx) if err != nil { return sdk.FormatInvariant(types.ModuleName, poolBalanceInvariantName, - fmt.Sprintf("\tgamm pool retrieval failed")), true + "\tgamm pool retrieval failed"), true } for _, pool := range pools { @@ -57,7 +57,7 @@ func PoolAccountInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant { } return sdk.FormatInvariant(types.ModuleName, poolBalanceInvariantName, - fmt.Sprintf("\tgamm all pool asset coins and account coins match\n")), false + "\tgamm all pool asset coins and account coins match\n"), false } } @@ -68,7 +68,7 @@ func PoolTotalWeightInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant pools, err := keeper.GetPools(ctx) if err != nil { return sdk.FormatInvariant(types.ModuleName, "pool-total-weight", - fmt.Sprintf("\tgamm pool retrieval failed")), true + "\tgamm pool retrieval failed"), true } for _, pool := range pools { @@ -84,7 +84,7 @@ func PoolTotalWeightInvariant(keeper Keeper, bk types.BankKeeper) sdk.Invariant } return sdk.FormatInvariant(types.ModuleName, "pool-total-weight", - fmt.Sprintf("\tgamm all pool calculated and stored total weight match\n")), false + "\tgamm all pool calculated and stored total weight match\n"), false } } @@ -130,7 +130,7 @@ func PoolProductConstantInvariant(keeper Keeper) sdk.Invariant { newpools, err := keeper.GetPools(ctx) if err != nil { return sdk.FormatInvariant(types.ModuleName, "pool-product-constant", - fmt.Sprintf("\tgamm pool retrieval failed")), true + "\tgamm pool retrieval failed"), true } for _, pool := range newpools { @@ -150,6 +150,6 @@ func PoolProductConstantInvariant(keeper Keeper) sdk.Invariant { } return sdk.FormatInvariant(types.ModuleName, "pool-product-constant", - fmt.Sprintf("\tgamm all pool product constant preserved\n")), false + "\tgamm all pool product constant preserved\n"), false } } diff --git a/x/gamm/keeper/pool_service_test.go b/x/gamm/keeper/pool_service_test.go index a4f2412de09..f12814deeec 100644 --- a/x/gamm/keeper/pool_service_test.go +++ b/x/gamm/keeper/pool_service_test.go @@ -28,6 +28,12 @@ var ( Token: sdk.NewCoin("bar", sdk.NewInt(10000)), } defaultPoolAssets []types.PoolAsset = []types.PoolAsset{defaultFooAsset, defaultBarAsset} + defaultAcctFunds sdk.Coins = sdk.NewCoins( + sdk.NewCoin("uosmo", sdk.NewInt(10000000000)), + sdk.NewCoin("foo", sdk.NewInt(10000000)), + sdk.NewCoin("bar", sdk.NewInt(10000000)), + sdk.NewCoin("baz", sdk.NewInt(10000000)), + ) ) func (suite *KeeperTestSuite) TestCreatePool() { @@ -196,12 +202,7 @@ func (suite *KeeperTestSuite) TestCreatePool() { // Mint some assets to the accounts. for _, acc := range []sdk.AccAddress{acc1, acc2, acc3} { - err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, sdk.NewCoins( - sdk.NewCoin("uosmo", sdk.NewInt(10000000000)), - sdk.NewCoin("foo", sdk.NewInt(10000000)), - sdk.NewCoin("bar", sdk.NewInt(10000000)), - sdk.NewCoin("baz", sdk.NewInt(10000000)), - )) + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, defaultAcctFunds) if err != nil { panic(err) } @@ -280,12 +281,7 @@ func (suite *KeeperTestSuite) TestJoinPool() { // Mint some assets to the accounts. for _, acc := range []sdk.AccAddress{acc1, acc2, acc3} { - err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, sdk.NewCoins( - sdk.NewCoin("uosmo", sdk.NewInt(10000000000)), - sdk.NewCoin("foo", sdk.NewInt(10000000)), - sdk.NewCoin("bar", sdk.NewInt(10000000)), - sdk.NewCoin("baz", sdk.NewInt(10000000)), - )) + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, defaultAcctFunds) if err != nil { panic(err) } @@ -377,12 +373,7 @@ func (suite *KeeperTestSuite) TestExitPool() { // Mint some assets to the accounts. for _, acc := range []sdk.AccAddress{acc1, acc2, acc3} { - err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, sdk.NewCoins( - sdk.NewCoin("uosmo", sdk.NewInt(10000000000)), - sdk.NewCoin("foo", sdk.NewInt(10000000)), - sdk.NewCoin("bar", sdk.NewInt(10000000)), - sdk.NewCoin("baz", sdk.NewInt(10000000)), - )) + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, defaultAcctFunds) if err != nil { panic(err) } @@ -415,12 +406,7 @@ func (suite *KeeperTestSuite) TestActivePool() { // Mint some assets to the accounts. for _, acc := range []sdk.AccAddress{acc1, acc2, acc3} { - err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, sdk.NewCoins( - sdk.NewCoin("uosmo", sdk.NewInt(10000000000)), - sdk.NewCoin("foo", sdk.NewInt(10000000)), - sdk.NewCoin("bar", sdk.NewInt(10000000)), - sdk.NewCoin("baz", sdk.NewInt(10000000)), - )) + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, acc, defaultAcctFunds) if err != nil { panic(err) } diff --git a/x/lockup/client/cli/cli_test.go b/x/lockup/client/cli/cli_test.go index 331ab058de9..409496d6dd3 100644 --- a/x/lockup/client/cli/cli_test.go +++ b/x/lockup/client/cli/cli_test.go @@ -17,6 +17,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil" "github.com/osmosis-labs/osmosis/app" + "github.com/osmosis-labs/osmosis/osmotestutils" "github.com/osmosis-labs/osmosis/x/lockup/client/cli" lockuptestutil "github.com/osmosis-labs/osmosis/x/lockup/client/testutil" "github.com/osmosis-labs/osmosis/x/lockup/types" @@ -152,7 +153,7 @@ func (s *IntegrationTestSuite) TestBeginUnlockingCmd() { newAddr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) @@ -220,7 +221,7 @@ func (s *IntegrationTestSuite) TestNewBeginUnlockPeriodLockCmd() { newAddr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), + osmotestutils.DefaultFeeString(s.cfg), ) s.Require().NoError(err) diff --git a/x/lockup/keeper/gas_test.go b/x/lockup/keeper/gas_test.go index 37124816a9a..72bb4a6985d 100644 --- a/x/lockup/keeper/gas_test.go +++ b/x/lockup/keeper/gas_test.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -13,8 +14,13 @@ var ( ) func (suite *KeeperTestSuite) measureLockGas(addr sdk.AccAddress, coins sdk.Coins, dur time.Duration) uint64 { + // fundAccount outside of gas measurement + err := simapp.FundAccount(suite.app.BankKeeper, suite.ctx, addr, coins) + suite.Require().NoError(err) + // start measuring gas alreadySpent := suite.ctx.GasMeter().GasConsumed() - suite.LockTokens(addr, coins, dur) + _, err = suite.app.LockupKeeper.LockTokens(suite.ctx, addr, coins, dur) + suite.Require().NoError(err) newSpent := suite.ctx.GasMeter().GasConsumed() spentNow := newSpent - alreadySpent return spentNow @@ -50,15 +56,15 @@ func (suite *KeeperTestSuite) TestRepeatedLockTokensGas() { totalNumLocks := 10000 firstLockGasAmount := suite.measureLockGas(defaultAddr, defaultCoins, time.Second) - suite.Assert().Equal(93703, int(firstLockGasAmount)) + suite.Assert().Equal(70305, int(firstLockGasAmount)) for i := 1; i < startAveragingAt; i++ { suite.LockTokens(defaultAddr, defaultCoins, time.Second) } avgGas, maxGas := suite.measureAvgAndMaxLockGas(totalNumLocks-startAveragingAt, defaultAddr, coinsFn, durFn) fmt.Printf("test deets: total locks created %d, begin average at %d\n", totalNumLocks, startAveragingAt) - suite.Assert().Equal(75618, int(avgGas), "average gas / lock") - suite.Assert().Equal(75708, int(maxGas), "max gas / lock") + suite.Assert().Equal(59527, int(avgGas), "average gas / lock") + suite.Assert().Equal(59617, int(maxGas), "max gas / lock") } func (suite *KeeperTestSuite) TestRepeatedLockTokensDistinctDurationGas() { @@ -70,6 +76,6 @@ func (suite *KeeperTestSuite) TestRepeatedLockTokensDistinctDurationGas() { avgGas, maxGas := suite.measureAvgAndMaxLockGas(totalNumLocks, defaultAddr, coinsFn, durFn) fmt.Printf("test deets: total locks created %d\n", totalNumLocks) - suite.Assert().EqualValues(122316, int(avgGas), "average gas / lock") - suite.Assert().EqualValues(242903, int(maxGas), "max gas / lock") + suite.Assert().EqualValues(106225, int(avgGas), "average gas / lock") + suite.Assert().EqualValues(226812, int(maxGas), "max gas / lock") }