Skip to content

Commit

Permalink
still work
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Jul 4, 2022
1 parent b33920a commit ea0464b
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 44 deletions.
7 changes: 2 additions & 5 deletions app/upgrades/v8/msg_filter_ante_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v8_test

import (
"github.com/osmosis-labs/osmosis/v7/osmoutils"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -67,11 +68,7 @@ func TestMsgFilterDecorator(t *testing.T) {
require.NoError(t, txBuilder.SetMsgs(tc.msgs...))

_, err := handler.AnteHandle(tc.ctx, txBuilder.GetTx(), false, noOpAnteDecorator())
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
osmoutils.ConditionalError(t, tc.expectErr, err))
})
}
}
6 changes: 1 addition & 5 deletions app/upgrades/v9/msg_filter_ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ func TestMsgFilterDecorator(t *testing.T) {
require.NoError(t, txBuilder.SetMsgs(tc.msgs...))

_, err := handler.AnteHandle(tc.ctx, txBuilder.GetTx(), false, noOpAnteDecorator())
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
osmoutils.ConditionalError(t, tc.expectErr, err))
})
}
}
8 changes: 2 additions & 6 deletions osmoutils/binary_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ func TestBinarySearch(t *testing.T) {

for _, tc := range tests {
actualSolvedInput, err := BinarySearch(tc.f, tc.lowerbound, tc.upperbound, tc.targetOutput, tc.errTolerance, tc.maxIterations)
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.True(sdk.IntEq(t, tc.expectedSolvedInput, actualSolvedInput))
}
ConditionalError(t, tc.expectErr, err)
require.True(sdk.IntEq(t, tc.expectedSolvedInput, actualSolvedInput))
}
}

Expand Down
26 changes: 26 additions & 0 deletions osmoutils/cli_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"fmt"
"strconv"
"strings"
"testing"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

func DefaultFeeString(cfg network.Config) string {
Expand All @@ -20,6 +23,8 @@ const (
bitlen = 64
)

type PanicTestFunc func()

func ParseUint64SliceFromString(s string, separator string) ([]uint64, error) {
var parsedInts []uint64
for _, s := range strings.Split(s, separator) {
Expand Down Expand Up @@ -47,3 +52,24 @@ func ParseSdkIntFromString(s string, separator string) ([]sdk.Int, error) {
}
return parsedInts, nil
}

func ConditionalPanics(s suite.Suite, expPanic bool, fn PanicTestFunc) {
if expPanic {
s.Panics(func() {
fn()
})
}

s.NotPanics(func() {
fn()
})
}

func ConditionalError(t *testing.T, expError bool, err error, msgs ...interface{}) {
if expError {
require.Error(t, err)
return
}

require.NoError(t, err, msgs)
}
19 changes: 9 additions & 10 deletions wasmbinding/test/custom_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/osmosis-labs/osmosis/v7/osmoutils"
"github.com/osmosis-labs/osmosis/v7/x/tokenfactory/types"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -561,16 +562,14 @@ func TestSwapMsg(t *testing.T) {

msg := bindings.OsmosisMsg{Swap: tc.msg(state)}
err := executeCustom(t, ctx, osmosis, reflect, trader, msg, tc.initFunds)
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
balances := osmosis.BankKeeper.GetAllBalances(ctx, reflect)
// uncomment these to debug any confusing results (show balances, not (*big.Int)(0x140005e51e0))
// fmt.Printf("Expected: %s\n", tc.finalFunds)
// fmt.Printf("Got: %s\n", balances)
require.EqualValues(t, tc.finalFunds, balances)
}
osmoutils.ConditionalError(t, tc.expectErr, err)

balances := osmosis.BankKeeper.GetAllBalances(ctx, reflect)
// uncomment these to debug any confusing results (show balances, not (*big.Int)(0x140005e51e0))
// fmt.Printf("Expected: %s\n", tc.finalFunds)
// fmt.Printf("Got: %s\n", balances)
require.EqualValues(t, tc.finalFunds, balances)

})
}
}
Expand Down
14 changes: 7 additions & 7 deletions wasmbinding/test/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v7/osmoutils"
"github.com/osmosis-labs/osmosis/v7/wasmbinding"
"github.com/osmosis-labs/osmosis/v7/wasmbinding/bindings"
)
Expand Down Expand Up @@ -104,13 +105,12 @@ func TestDenomAdmin(t *testing.T) {

t.Run(tc.name, func(t *testing.T) {
resp, err := queryPlugin.GetDenomAdmin(ctx, tc.denom)
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, tc.expectAdmin, resp.Admin)
}

osmoutils.ConditionalError(t, tc.expectErr, err)

require.NotNil(t, resp)
require.Equal(t, tc.expectAdmin, resp.Admin)

})
}
}
Expand Down
1 change: 1 addition & 0 deletions x/epochs/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (s *IntegrationTestSuite) TestGetCmdCurrentEpoch() {
}

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)

if tc.expectErr {
s.Require().Error(err)
} else {
Expand Down
23 changes: 13 additions & 10 deletions x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -111,16 +112,18 @@ func (suite *KeeperTestSuite) TestMintInitGenesis() {
originalVestingCoins := bankKeeper.GetBalance(ctx, developerAccount, tc.mintDenom)

// Test.
if tc.expectPanic {
suite.Panics(func() {
mintKeeper.InitGenesis(ctx, tc.mintGenesis)
})
return
}

suite.NotPanics(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)
// })

osmoutils.ConditionalPanics(suite, tc.expectPanic, mintKeeper.InitGenesis(ctx, tc.mintGenesis))

// Assertions.

Expand Down
2 changes: 1 addition & 1 deletion x/mint/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (suite *KeeperTestSuite) TestSetInitialSupplyOffsetDuringMigration() {
isDeveloperModuleAccountCreated: true,
},
"dev vesting module account does not exist": {
blockHeight: 1,
blockHeight: 1,
expectedError: keeper.ErrDevVestingModuleAccountNotCreated,
},
}
Expand Down

0 comments on commit ea0464b

Please sign in to comment.