From e58aa1dfd9b1423a50e64af4d52c4fa9020d2a6a Mon Sep 17 00:00:00 2001 From: emidev98 Date: Wed, 30 Aug 2023 18:50:49 +0300 Subject: [PATCH] tests: authority tokens factory --- x/tokenfactory/keeper/before_send_test.go | 5 ++++- x/tokenfactory/keeper/msg_server_test.go | 15 +++++++++++++-- x/tokenfactory/types/authorityMetadata_test.go | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 x/tokenfactory/types/authorityMetadata_test.go diff --git a/x/tokenfactory/keeper/before_send_test.go b/x/tokenfactory/keeper/before_send_test.go index a70c9ff4..adf97c02 100644 --- a/x/tokenfactory/keeper/before_send_test.go +++ b/x/tokenfactory/keeper/before_send_test.go @@ -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 diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index 45ffb6e5..fcf6fd92 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -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) diff --git a/x/tokenfactory/types/authorityMetadata_test.go b/x/tokenfactory/types/authorityMetadata_test.go new file mode 100644 index 00000000..093774ba --- /dev/null +++ b/x/tokenfactory/types/authorityMetadata_test.go @@ -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()) +}