This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for x/registry/keeper/msg_server_update_top_level_domain_reg…
…istration_policy_test.go
- Loading branch information
1 parent
76e422a
commit f969575
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
x/registry/keeper/msg_server_update_top_level_domain_registration_policy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
}) | ||
} | ||
} |