Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Nov 21, 2023
1 parent 49585b9 commit 29daa38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
32 changes: 11 additions & 21 deletions x/incentive/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
"gotest.tools/v3/assert"

"github.com/umee-network/umee/v6/util/coin"
Expand Down Expand Up @@ -57,33 +58,22 @@ func TestMsgs(t *testing.T) {
}
}

// functions required in msgs.go which are not part of sdk.Msg
type sdkmsg interface {
Route() string
Type() string
GetSignBytes() []byte
}

func TestRoutes(t *testing.T) {
func TestLegacyMsg(t *testing.T) {
t.Parallel()

msgs := []sdkmsg{
*incentive.NewMsgBond(testAddr, uToken),
*incentive.NewMsgBeginUnbonding(testAddr, uToken),
*incentive.NewMsgEmergencyUnbond(testAddr, uToken),
*incentive.NewMsgClaim(testAddr),
*incentive.NewMsgSponsor(testAddr, 3),
*incentive.NewMsgGovCreatePrograms(govAddr, []incentive.IncentiveProgram{program}),
*incentive.NewMsgGovSetParams(govAddr, incentive.DefaultParams()),
msgs := []legacytx.LegacyMsg{
incentive.NewMsgBond(testAddr, uToken),
incentive.NewMsgBeginUnbonding(testAddr, uToken),
incentive.NewMsgEmergencyUnbond(testAddr, uToken),
incentive.NewMsgClaim(testAddr),
incentive.NewMsgSponsor(testAddr, 3),
incentive.NewMsgGovCreatePrograms(govAddr, []incentive.IncentiveProgram{program}),
incentive.NewMsgGovSetParams(govAddr, incentive.DefaultParams()),
}

for _, msg := range msgs {
// check for non-empty returns for now
assert.Assert(t, len(msg.GetSignBytes()) != 0)
// exact match required
assert.Equal(t,
// example: "/umee.incentive.v1.MsgBond"
// with %T returning "incentive.MsgBond"
addV1ToType(fmt.Sprintf("/umee.%T", msg)),
msg.Type(),
)
Expand All @@ -92,5 +82,5 @@ func TestRoutes(t *testing.T) {

// addV1ToType replaces "incentive." with "incentive.v1."
func addV1ToType(s string) string {
return strings.Replace(s, "incentive", "incentive.v1", 1)
return strings.Replace(s, "*incentive", "incentive.v1", 1)
}
23 changes: 3 additions & 20 deletions x/leverage/types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gotest.tools/v3/assert"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

const (
Expand Down Expand Up @@ -47,15 +48,8 @@ func TestTxs(t *testing.T) {
}
}

// functions required in msgs.go which are not part of sdk.Msg
type sdkmsg interface {
Route() string
Type() string
GetSignBytes() []byte
}

func TestRoutes(t *testing.T) {
txs := []sdkmsg{
func TestLegacyMsg(t *testing.T) {
txs := []legacytx.LegacyMsg{
types.NewMsgSupply(testAddr, token),
types.NewMsgWithdraw(testAddr, uToken),
types.NewMsgMaxWithdraw(testAddr, denom),
Expand All @@ -70,25 +64,14 @@ func TestRoutes(t *testing.T) {
}

for _, tx := range txs {
assert.Equal(t,
// example: "/umee.leverage.v1.MsgSupply"
// with %T returning "*types.MsgSupply"
addV1ToType(fmt.Sprintf("/umee.%T", tx)),
tx.Route(),
)
// check for non-empty returns for now
assert.Assert(t, len(tx.GetSignBytes()) != 0)
// exact match required
assert.Equal(t,
// example: "/umee.leverage.v1.MsgSupply"
// with %T returning "*types.MsgSupply"
addV1ToType(fmt.Sprintf("/umee.%T", tx)),
tx.Type(),
)
}
}

// addV1ToType replaces "*types" with "leverage.v1"
func addV1ToType(s string) string {
return strings.Replace(s, "*types", "leverage.v1", 1)
}

0 comments on commit 29daa38

Please sign in to comment.