Skip to content

Commit

Permalink
add check for no slashes in creator address
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed Apr 23, 2022
1 parent 4e49003 commit b119d48
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions x/tokenfactory/keeper/createdenom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ func (suite *KeeperTestSuite) TestMsgCreateDenom() {
res, err = msgServer.CreateDenom(sdk.WrapSDKContext(suite.ctx), types.NewMsgCreateDenom(addr2.String(), "bitcoin"))
suite.Require().NoError(err)
suite.Require().NotEmpty(res.GetNewTokenDenom())

// Make sure that an address with a "/" in it can't create denoms
res, err = msgServer.CreateDenom(sdk.WrapSDKContext(suite.ctx), types.NewMsgCreateDenom("osmosis.eth/creator", "bitcoin"))
suite.Require().Error(err)
}
3 changes: 3 additions & 0 deletions x/tokenfactory/types/denoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const (
)

func GetTokenDenom(creator, nonce string) (string, error) {
if strings.Contains(creator, "/") {
return "", ErrInvalidCreator
}
denom := strings.Join([]string{ModuleDenomPrefix, creator, nonce}, "/")
return denom, sdk.ValidateDenom(denom)
}
Expand Down
5 changes: 3 additions & 2 deletions x/tokenfactory/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var (
ErrDenomExists = sdkerrors.Register(ModuleName, 1, "denom already exists")
ErrUnauthorized = sdkerrors.Register(ModuleName, 2, "unauthorized account")
ErrInvalidDenom = sdkerrors.Register(ModuleName, 3, "invalid denom")
ErrInvalidAuthorityMetadata = sdkerrors.Register(ModuleName, 4, "invalid authority metadata")
ErrInvalidGenesis = sdkerrors.Register(ModuleName, 5, "invalid genesis")
ErrInvalidCreator = sdkerrors.Register(ModuleName, 4, "invalid creator")
ErrInvalidAuthorityMetadata = sdkerrors.Register(ModuleName, 5, "invalid authority metadata")
ErrInvalidGenesis = sdkerrors.Register(ModuleName, 6, "invalid genesis")
)

0 comments on commit b119d48

Please sign in to comment.