Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workflows to lint.yml #21

Merged
merged 4 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions cmd/plugchaind/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
onptypes "github.com/oracleNetworkProtocol/plugchain/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -292,19 +291,3 @@ func (a appCreator) appExport(

return anApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
}

func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
set := func(s *pflag.FlagSet, key, val string) {
if f := s.Lookup(key); f != nil {
f.DefValue = val
f.Value.Set(val)
}
}
for key, val := range defaults {
set(c.Flags(), key, val)
set(c.PersistentFlags(), key, val)
}
for _, c := range c.Commands() {
overwriteFlagDefaults(c, defaults)
}
}
31 changes: 0 additions & 31 deletions x/nft/keeper/keeper_test.go

This file was deleted.

14 changes: 0 additions & 14 deletions x/nft/keeper/msg_server_test.go

This file was deleted.

43 changes: 14 additions & 29 deletions x/nft/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,35 @@ import (
const (
DefaultStringValue = "[do-not-modify]"

MinClassLen = 3
MaxClassLen = 64
MaxNFTURILen = 256
)

var (
RegexAlphaNumeric = regexp.MustCompile(`^[a-z0-9]+$`).MatchString
RegexAlphaTop = regexp.MustCompile(`^[a-z].*`).MatchString

keyWords = strings.Join([]string{"ibc", "plug"}, "|")
regexpKeywordFmt = fmt.Sprintf("^(%s).*", keyWords)
regexpKeyword = regexp.MustCompile(regexpKeywordFmt).MatchString
// reClassIDString can be 3 ~ 100 characters long and support letters, followed by either
// a letter, a number or a slash ('/') or a colon (':') or ('-').
reClassIDString = `[a-zA-Z][a-zA-Z0-9/:-]{2,100}`
reClassID = regexp.MustCompile(fmt.Sprintf(`^%s$`, reClassIDString))
// reNFTIDString can be 3 ~ 100 characters long and support letters, followed by either
// a letter, a number or a slash ('/') or a colon (':') or ('-').
reNFTID = reClassID

URIMatchWords = strings.Join([]string{"http://", "https://"}, "|")
regexURIFmt = fmt.Sprintf("^(%s).*", URIMatchWords)
regexpURI = regexp.MustCompile(regexURIFmt).MatchString
)

// ValidateClassID verifies whether the parameters are legal
func ValidateClassID(classID string) error {
if len(classID) < MinClassLen || len(classID) > MaxClassLen {
return sdkerrors.Wrapf(ErrInvalidClass, "the length of Class(%s) only accepts value [%d, %d]", classID, MinClassLen, MaxClassLen)
}
if !RegexAlphaNumeric(classID) || !RegexAlphaTop(classID) {
return sdkerrors.Wrapf(ErrInvalidClass, "the Class(%s) only accepts alphanumeric characters, and begin with an english letter", classID)
}
return ValidateKeywords(classID)
}

// ValidateKeywords checks if the given classID begins with `DenomKeywords`
func ValidateKeywords(classID string) error {
if regexpKeyword(classID) {
return sdkerrors.Wrapf(ErrInvalidClass, "invalid classID: %s, can not begin with keyword: (%s)", classID, keyWords)
func ValidateClassID(id string) error {
if !reClassID.MatchString(id) {
return sdkerrors.Wrapf(ErrInvalidClass, "invalid class id: %s", id)
}
return nil
}

//ValidateNFTID verify that the nftID is legal
func ValidateNFTID(nftID string) error {
if len(nftID) < MinClassLen || len(nftID) > MaxClassLen {
return sdkerrors.Wrapf(ErrInvalidNFTID, "the length of nft id(%s) only accepts value [%d, %d]", nftID, MinClassLen, MaxClassLen)
}
if !RegexAlphaNumeric(nftID) || !RegexAlphaTop(nftID) {
return sdkerrors.Wrapf(ErrInvalidNFTID, "nft id(%s) only accepts alphanumeric characters, and begin with an english letter", nftID)
// ValidateNFTID returns whether the nft id is valid
func ValidateNFTID(id string) error {
if !reNFTID.MatchString(id) {
return sdkerrors.Wrapf(ErrInvalidNFTID, "invalid nft id: %s", id)
}
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions x/token/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ func GetCmdIssueToken() *cobra.Command {
},
}
cmd.Flags().AddFlagSet(FsIssueToken)
cmd.MarkFlagRequired(FlagSymbol)
cmd.MarkFlagRequired(FlagName)
cmd.MarkFlagRequired(FlagInitialSupply)
cmd.MarkFlagRequired(FlagScale)
cmd.MarkFlagRequired(FlagMinUnit)
_ = cmd.MarkFlagRequired(FlagSymbol)
_ = cmd.MarkFlagRequired(FlagName)
_ = cmd.MarkFlagRequired(FlagInitialSupply)
_ = cmd.MarkFlagRequired(FlagScale)
_ = cmd.MarkFlagRequired(FlagMinUnit)
flags.AddTxFlagsToCmd(cmd)

return cmd
Expand Down Expand Up @@ -167,7 +167,7 @@ func GetCmdMintToken() *cobra.Command {

cmd.Flags().AddFlagSet(FsMintToken)

cmd.MarkFlagRequired(FlagAmount)
_ = cmd.MarkFlagRequired(FlagAmount)

flags.AddTxFlagsToCmd(cmd)

Expand Down Expand Up @@ -269,7 +269,7 @@ func GetCmdBurnToken() *cobra.Command {
},
}
cmd.Flags().AddFlagSet(FsMintToken)
cmd.MarkFlagRequired(FlagAmount)
_ = cmd.MarkFlagRequired(FlagAmount)

flags.AddTxFlagsToCmd(cmd)

Expand Down Expand Up @@ -319,7 +319,7 @@ func GetCmdTransferOwnerToken() *cobra.Command {
}

cmd.Flags().AddFlagSet(FsTransferOwnerToken)
cmd.MarkFlagRequired(FlagTo)
_ = cmd.MarkFlagRequired(FlagTo)

flags.AddTxFlagsToCmd(cmd)
return cmd
Expand Down
2 changes: 1 addition & 1 deletion x/token/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (k Keeper) BurnToken(ctx sdk.Context, symbol string, amount uint64, owner s
addrTotal := k.bankKeeper.GetBalance(ctx, owner, symbol)

if !addrTotal.Amount.GT(burnCoin.Amount) {
return sdkerrors.Wrapf(types.ErrInvalidAmount, "the amount exceeds the account token amount; expected (0, %d], got %d", addrTotal.Amount.String(), burnCoin.Amount.String())
return sdkerrors.Wrapf(types.ErrInvalidAmount, "Insufficient account balance")
}

if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, owner, types.ModuleName, burnCoins); err != nil {
Expand Down
35 changes: 0 additions & 35 deletions x/token/keeper/keeper_test.go

This file was deleted.

14 changes: 0 additions & 14 deletions x/token/keeper/msg_server_test.go

This file was deleted.