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

Commit

Permalink
Add SecondLevelDomain.GetRole()
Browse files Browse the repository at this point in the history
  • Loading branch information
foxytanuki committed Nov 17, 2023
1 parent 043ad2e commit ea52717
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion x/registry/keeper/query_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (k Keeper) Role(goCtx context.Context, req *types.QueryRoleRequest) (*types
if !found {
return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, "domain not found")
}
role = sld.AccessControl[req.Address]
role = sld.GetRole(req.Address)
default:
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid request: domain name")
}
Expand Down
5 changes: 5 additions & 0 deletions x/registry/types/secend_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@ func (secondLevelDomain SecondLevelDomain) IsRecordEditable(sender string) (isEd
isEditable = secondLevelDomain.AccessControl[sender] == DomainRole_EDITOR || secondLevelDomain.AccessControl[sender] == DomainRole_OWNER
return isEditable, err
}

func (secondLevelDomain *SecondLevelDomain) GetRole(address string) (role DomainRole) {
role = secondLevelDomain.AccessControl[address]
return role
}
59 changes: 59 additions & 0 deletions x/registry/types/second_level_domain_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package types

import (
fmt "fmt"
"testing"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/mycel-domain/mycel/testutil"
)

type DomainTest struct {
Expand Down Expand Up @@ -197,3 +200,59 @@ func TestDomainUpdateDnsRecord(t *testing.T) {
}
}
}

func TestGetRoleSLD(t *testing.T) {
testCases := []struct {
domain SecondLevelDomain
req string
exp DomainRole
}{
// Valid domains
{
domain: SecondLevelDomain{
Name: "myc",
AccessControl: map[string]DomainRole{testutil.Alice: DomainRole_NO_ROLE},
},
req: testutil.Alice,
exp: DomainRole_NO_ROLE,
},
{
domain: SecondLevelDomain{
Name: "myc",
AccessControl: map[string]DomainRole{testutil.Alice: DomainRole_OWNER},
},
req: testutil.Alice,
exp: DomainRole_OWNER,
},
{
domain: SecondLevelDomain{
Name: "myc",
AccessControl: map[string]DomainRole{testutil.Alice: DomainRole_EDITOR},
},
req: testutil.Alice,
exp: DomainRole_EDITOR,
},
{
domain: SecondLevelDomain{
Name: "myc",
AccessControl: map[string]DomainRole{testutil.Alice: DomainRole_OWNER},
},
req: testutil.Bob,
exp: DomainRole_NO_ROLE,
},
{
domain: SecondLevelDomain{
Name: "myc",
},
req: testutil.Alice,
exp: DomainRole_NO_ROLE,
},
}

for i, tc := range testCases {
t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) {
r := tc.domain.GetRole(tc.req)
require.Equal(t, tc.exp, r)
})
}
}
2 changes: 1 addition & 1 deletion x/registry/types/top_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestExtendExpirationDate(t *testing.T) {
}
}

func TestGetRole(t *testing.T) {
func TestGetRoleTLD(t *testing.T) {
testCases := []struct {
domain TopLevelDomain
req string
Expand Down

0 comments on commit ea52717

Please sign in to comment.