diff --git a/osmoutils/test_helpers.go b/osmoutils/test_helpers.go new file mode 100644 index 00000000000..a331ce00c3a --- /dev/null +++ b/osmoutils/test_helpers.go @@ -0,0 +1,18 @@ +package osmoutils + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +// ConditionalPanic checks if expectPanic is true, asserts that sut (system under test) +// panics. If expectPanic is false, asserts that sut does not panic. +// returns true if sut panics and false it it does not +func ConditionalPanic(t *testing.T, expectPanic bool, sut func()) { + if expectPanic { + require.Panics(t, sut) + return + } + require.NotPanics(t, sut) +} diff --git a/x/gamm/pool-models/balancer/pool_suite_test.go b/x/gamm/pool-models/balancer/pool_suite_test.go index afd071d0acb..851aa185f0e 100644 --- a/x/gamm/pool-models/balancer/pool_suite_test.go +++ b/x/gamm/pool-models/balancer/pool_suite_test.go @@ -13,6 +13,7 @@ import ( "github.com/osmosis-labs/osmosis/v7/app/apptesting" v10 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v10" + "github.com/osmosis-labs/osmosis/v7/osmoutils" "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer" "github.com/osmosis-labs/osmosis/v7/x/gamm/types" ) @@ -720,7 +721,7 @@ func (suite *KeeperTestSuite) TestCalcJoinPoolShares() { require.True(t, ok) assertPoolStateNotModified(t, balancerPool, func() { - assertPanic(t, tc.expectPanic, sut) + osmoutils.ConditionalPanic(t, tc.expectPanic, sut) }) }) } diff --git a/x/gamm/pool-models/balancer/pool_test.go b/x/gamm/pool-models/balancer/pool_test.go index d4b3133672f..f02a6666d60 100644 --- a/x/gamm/pool-models/balancer/pool_test.go +++ b/x/gamm/pool-models/balancer/pool_test.go @@ -202,7 +202,7 @@ func TestCalcSingleAssetJoin(t *testing.T) { } assertPoolStateNotModified(t, balancerPool, func() { - assertPanic(t, tc.expectPanic, sut) + osmoutils.ConditionalPanic(t, tc.expectPanic, sut) }) }) } diff --git a/x/gamm/pool-models/balancer/util_test.go b/x/gamm/pool-models/balancer/util_test.go index 8a6f7f0afb2..c5e8405b696 100644 --- a/x/gamm/pool-models/balancer/util_test.go +++ b/x/gamm/pool-models/balancer/util_test.go @@ -76,13 +76,3 @@ func assertPoolStateNotModified(t *testing.T, pool *balancer.Pool, sut func()) { require.Equal(t, oldLiquidity, newLiquidity) require.Equal(t, oldShares, newShares) } - -// assertPanic if expectPanic is true, asserts that sut (system under test) -// panics. If expectPanic is false, asserts that sut does not panic. -func assertPanic(t *testing.T, expectPanic bool, sut func()) { - if expectPanic { - require.Panics(t, sut) - } else { - require.NotPanics(t, sut) - } -} diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index 7aa8ddcf01f..72a29ba8b9c 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -7,6 +7,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/suite" + "github.com/osmosis-labs/osmosis/v7/osmoutils" "github.com/osmosis-labs/osmosis/v7/x/mint/keeper" "github.com/osmosis-labs/osmosis/v7/x/mint/types" ) @@ -111,17 +112,11 @@ func (suite *KeeperTestSuite) TestMintInitGenesis() { originalVestingCoins := bankKeeper.GetBalance(ctx, developerAccount, tc.mintDenom) // Test. + osmoutils.ConditionalPanic(suite.T(), tc.expectPanic, func() { mintKeeper.InitGenesis(ctx, tc.mintGenesis) }) if tc.expectPanic { - suite.Panics(func() { - mintKeeper.InitGenesis(ctx, tc.mintGenesis) - }) return } - suite.NotPanics(func() { - mintKeeper.InitGenesis(ctx, tc.mintGenesis) - }) - // Assertions. // Module account was created. diff --git a/x/mint/keeper/keeper_test.go b/x/mint/keeper/keeper_test.go index 802cfd98268..a7c65186a10 100644 --- a/x/mint/keeper/keeper_test.go +++ b/x/mint/keeper/keeper_test.go @@ -268,7 +268,7 @@ func (suite *KeeperTestSuite) TestSetInitialSupplyOffsetDuringMigration() { isDeveloperModuleAccountCreated: true, }, "dev vesting module account does not exist": { - blockHeight: 1, + blockHeight: 1, expectedError: keeper.ErrDevVestingModuleAccountNotCreated, }, }