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

Commit

Permalink
Update registry/keeper/query_role_test
Browse files Browse the repository at this point in the history
  • Loading branch information
foxytanuki committed Nov 17, 2023
1 parent ca5376a commit e0cff80
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions x/registry/keeper/query_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package keeper_test
import (
"fmt"
"strconv"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mycel-domain/mycel/testutil"
keepertest "github.com/mycel-domain/mycel/testutil/keeper"
"github.com/mycel-domain/mycel/x/registry/keeper"
"github.com/mycel-domain/mycel/x/registry/types"
"google.golang.org/grpc/codes"
Expand All @@ -19,13 +17,13 @@ func registerNTopLevelDomain(k *keeper.Keeper, ctx sdk.Context, creator string,
items := make([]types.TopLevelDomain, n)
for i := range items {
creator := testutil.Alice
name := strconv.Itoa(i)
name := "cel" + strconv.Itoa(i)

tld, _, err := k.RegisterTopLevelDomain(ctx, creator, name, 1)
if err != nil {
return nil, err
}
items = append(items, tld)
items[i] = tld
}
return items, nil
}
Expand All @@ -43,7 +41,7 @@ func registerNSecondLevelDomain(k *keeper.Keeper, ctx sdk.Context, creator strin
}
sld := types.SecondLevelDomain{
Name: name,
Parent: name,
Parent: "cel" + name,
Owner: creator.String(),
ExpirationDate: time.Time{},
Records: nil,
Expand All @@ -53,19 +51,28 @@ func registerNSecondLevelDomain(k *keeper.Keeper, ctx sdk.Context, creator strin
if err := k.RegisterSecondLevelDomain(ctx, sld, creator, 1); err != nil {
return nil, err
}
items = append(items, sld)
items[i] = sld
}
return items, nil
}

func TestRole(t *testing.T) {
keeper, ctx := keepertest.RegistryKeeper(t)
// wctx := sdk.WrapSDKContext(ctx)
func (suite *KeeperTestSuite) TestRole() {
suite.SetupTest()
k := suite.app.RegistryKeeper
ctx := suite.ctx
creator := testutil.Alice
tlds, _ := registerNTopLevelDomain(keeper, ctx, creator, 1)
slds, _ := registerNSecondLevelDomain(keeper, ctx, creator, 1)

for _, tc := range []struct {
tlds, err := registerNTopLevelDomain(&k, ctx, creator, 1)
if err != nil {
suite.FailNow(fmt.Sprintf("%v", err))
}

slds, err := registerNSecondLevelDomain(&k, ctx, creator, 1)
if err != nil {
suite.FailNow(fmt.Sprintf("%v", err))
}

tcs := []struct {
desc string
request *types.QueryRoleRequest
response *types.QueryRoleResponse
Expand Down Expand Up @@ -105,7 +112,7 @@ func TestRole(t *testing.T) {
desc: "Not owner of SLD",
request: &types.QueryRoleRequest{
DomainName: fmt.Sprintf("%s.%s", slds[0].Name, tlds[0].Name),
Address: creator,
Address: testutil.Bob,
},
response: &types.QueryRoleResponse{
Role: types.DomainRole.String(0),
Expand All @@ -123,9 +130,20 @@ func TestRole(t *testing.T) {
desc: "InvalidRequest",
err: status.Error(codes.InvalidArgument, "invalid request"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
// TBD
}

for i, tc := range tcs {
suite.Run(fmt.Sprintf("Case %d", i), func() {

// Get valid domain
resp, err := k.Role(ctx, tc.request)
if tc.err == nil {
suite.Require().Nil(err)
suite.Require().Equal(tc.response, resp)
} else {
suite.Require().NotNil(err)
suite.Require().Equal(tc.err.Error(), err.Error())
}
})
}
}

0 comments on commit e0cff80

Please sign in to comment.