Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Add test for x/registry/keeper/msg_server_update_top_level_domain_reg…
Browse files Browse the repository at this point in the history
…istration_policy_test.go
  • Loading branch information
foxytanuki committed Dec 22, 2023
1 parent 76e422a commit f969575
Showing 1 changed file with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package keeper_test

import (
"fmt"

errorsmod "cosmossdk.io/errors"

"github.com/mycel-domain/mycel/testutil"
"github.com/mycel-domain/mycel/x/registry/types"
)

func (suite *KeeperTestSuite) TestUpdateTopLevelDomainRegistrationPolicy() {
testCases := []struct {
creator string
name string
registrationPolicy string
expErr error
fn func()
}{
{
creator: testutil.Alice,
name: "foo",
registrationPolicy: "PUBLIC",
expErr: nil,
fn: func() {},
},
{
creator: testutil.Alice,
name: "foo",
registrationPolicy: "PRIVATE",
expErr: nil,
fn: func() {},
},
{
creator: testutil.Alice,
name: "foo",
registrationPolicy: "INVALID",
expErr: errorsmod.Wrapf(types.ErrInvalidRegistrationPolicy, "INVALID"),
fn: func() {},
},
{
creator: testutil.Alice,
name: "invalid",
registrationPolicy: "PUBLIC",
expErr: errorsmod.Wrapf(types.ErrSecondLevelDomainNotFound, "invalid"),
fn: func() {},
},
{
creator: testutil.Bob,
name: "foo",
registrationPolicy: "PUBLIC",
expErr: errorsmod.Wrapf(types.ErrSecondLevelDomainNotEditable, "%s", testutil.Bob),
fn: func() {},
},
}
for i, tc := range testCases {
suite.Run(fmt.Sprintf("Case %d", i), func() {
suite.SetupTest()

// NOTE: cel TLD is registered by Alice by default

// Run test case function
tc.fn()

// Update dns record
msgUpdateTopLevelDomainRegistrationPolicy := &types.MsgUpdateTopLevelDomainRegistrationPolicy{
Creator: tc.creator,
Name: tc.name,
RegistrationPolicy: tc.registrationPolicy,
}

_, err := suite.msgServer.UpdateTopLevelDomainRegistrationPolicy(suite.ctx, msgUpdateTopLevelDomainRegistrationPolicy)

if tc.expErr == nil {
// Check if the record is updated
suite.Require().Nil(err)
res, _ := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, "cel")
suite.Require().Equal(tc.registrationPolicy, res.GetRegistrationPolicy())
// Evalute events
events, found := testutil.FindEventsByType(suite.ctx.EventManager().Events(), types.EventTypeUpdateTopLevelDomainRegistrationPolicy)
suite.Require().True(found)

for _, event := range events {
suite.Require().Equal(tc.name, event.Attributes[0].Value)
suite.Require().Equal(tc.registrationPolicy, event.Attributes[1].Value)
}
} else {
suite.Require().EqualError(err, tc.expErr.Error())
}
})
}
}

0 comments on commit f969575

Please sign in to comment.