Skip to content

Commit

Permalink
tests: authority tokens factory
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Aug 30, 2023
1 parent 9d05c3b commit e58aa1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion x/tokenfactory/keeper/before_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ func (s *KeeperTestSuite) TestInfiniteTrackBeforeSend() {

// set beforesend hook to the new denom
// we register infinite loop contract here to test if we are gas metering properly
_, err = s.msgServer.SetBeforeSendHook(sdk.WrapSDKContext(s.Ctx), types.NewMsgSetBeforeSendHook(s.TestAccs[0].String(), factoryDenom, cosmwasmAddress.String()))
msg := types.NewMsgSetBeforeSendHook(s.TestAccs[0].String(), factoryDenom, cosmwasmAddress.String())
err = msg.ValidateBasic()
s.Require().NoError(err, "test: %v", tc.name)
_, err = s.msgServer.SetBeforeSendHook(sdk.WrapSDKContext(s.Ctx), msg)
s.Require().NoError(err, "test: %v", tc.name)

// track before send suppresses in any case, thus we expect no error
Expand Down
15 changes: 13 additions & 2 deletions x/tokenfactory/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,29 @@ func (s *KeeperTestSuite) TestMintDenomMsg() {
mintDenom: defaultDenom,
admin: s.TestAccs[0].String(),
valid: true,
expectedMessageEvents: 1,
expectedMessageEvents: 2,
},
} {
s.Run(fmt.Sprintf("Case %s", tc.desc), func() {
ctx := s.Ctx.WithEventManager(sdk.NewEventManager())
s.Require().Equal(0, len(ctx.EventManager().Events()))
// Test mint message
_, err := s.msgServer.Mint(sdk.WrapSDKContext(ctx), types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10)))
mint := types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10))
err := mint.ValidateBasic()
s.Require().NoError(err)
_, err = s.msgServer.Mint(sdk.WrapSDKContext(ctx), mint)

mintTo := types.NewMsgMintTo(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10), tc.admin)
err2 := mintTo.ValidateBasic()
s.Require().NoError(err2)
_, err2 = s.msgServer.Mint(sdk.WrapSDKContext(ctx), mintTo)

if tc.valid {
s.Require().NoError(err)
s.Require().NoError(err2)
} else {
s.Require().Error(err)
s.Require().Error(err2)
}
// Ensure current number and type of event is emitted
s.AssertEventEmitted(ctx, types.TypeMsgMint, tc.expectedMessageEvents)
Expand Down
17 changes: 17 additions & 0 deletions x/tokenfactory/types/authorityMetadata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/terra-money/core/v2/x/tokenfactory/types"
)

func TestAuthorityMetadata(t *testing.T) {
data := types.DenomAuthorityMetadata{
Admin: "satoshi",
}

require.Error(t, data.Validate())
}

0 comments on commit e58aa1d

Please sign in to comment.