diff --git a/cmd/plugchaind/cmd/root.go b/cmd/plugchaind/cmd/root.go index 69098de8f..57d8be6db 100644 --- a/cmd/plugchaind/cmd/root.go +++ b/cmd/plugchaind/cmd/root.go @@ -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" @@ -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) - } -} diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go deleted file mode 100644 index c0c62f72c..000000000 --- a/x/nft/keeper/keeper_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package keeper - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - // "github.com/cosmos/cosmos-sdk/codec" - // codectypes "github.com/cosmos/cosmos-sdk/codec/types" - // "github.com/cosmos/cosmos-sdk/store" - // "github.com/oracleNetworkProtocol/plugchain/x/nft/types" - // "github.com/stretchr/testify/require" - // "github.com/tendermint/tendermint/libs/log" - // tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - // tmdb "github.com/tendermint/tm-db" -) - -func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { - // storeKey := sdk.NewKVStoreKey(types.StoreKey) - - // db := tmdb.NewMemDB() - // stateStore := store.NewCommitMultiStore(db) - // stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db) - // require.NoError(t, stateStore.LoadLatestVersion()) - - // registry := codectypes.NewInterfaceRegistry() - // keeper := NewKeeper(codec.NewProtoCodec(registry), storeKey,) - - // ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - // return keeper, ctx - return nil, sdk.Context{} -} diff --git a/x/nft/keeper/msg_server_test.go b/x/nft/keeper/msg_server_test.go deleted file mode 100644 index be3ec69bd..000000000 --- a/x/nft/keeper/msg_server_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package keeper - -import ( - "context" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/oracleNetworkProtocol/plugchain/x/nft/types" -) - -func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { - keeper, ctx := setupKeeper(t) - return NewMsgServerImpl(*keeper), sdk.WrapSDKContext(ctx) -} diff --git a/x/nft/types/validation.go b/x/nft/types/validation.go index 2b833aa72..c4068441e 100644 --- a/x/nft/types/validation.go +++ b/x/nft/types/validation.go @@ -11,18 +11,17 @@ 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) @@ -30,31 +29,17 @@ var ( ) // 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 } diff --git a/x/token/client/cli/tx.go b/x/token/client/cli/tx.go index 2b4674ad3..154d178e4 100644 --- a/x/token/client/cli/tx.go +++ b/x/token/client/cli/tx.go @@ -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 @@ -167,7 +167,7 @@ func GetCmdMintToken() *cobra.Command { cmd.Flags().AddFlagSet(FsMintToken) - cmd.MarkFlagRequired(FlagAmount) + _ = cmd.MarkFlagRequired(FlagAmount) flags.AddTxFlagsToCmd(cmd) @@ -269,7 +269,7 @@ func GetCmdBurnToken() *cobra.Command { }, } cmd.Flags().AddFlagSet(FsMintToken) - cmd.MarkFlagRequired(FlagAmount) + _ = cmd.MarkFlagRequired(FlagAmount) flags.AddTxFlagsToCmd(cmd) @@ -319,7 +319,7 @@ func GetCmdTransferOwnerToken() *cobra.Command { } cmd.Flags().AddFlagSet(FsTransferOwnerToken) - cmd.MarkFlagRequired(FlagTo) + _ = cmd.MarkFlagRequired(FlagTo) flags.AddTxFlagsToCmd(cmd) return cmd diff --git a/x/token/keeper/keeper.go b/x/token/keeper/keeper.go index 4f81a4c39..353e42b00 100644 --- a/x/token/keeper/keeper.go +++ b/x/token/keeper/keeper.go @@ -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 { diff --git a/x/token/keeper/keeper_test.go b/x/token/keeper/keeper_test.go deleted file mode 100644 index faa17eba9..000000000 --- a/x/token/keeper/keeper_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package keeper - -import ( - "testing" - - // "github.com/cosmos/cosmos-sdk/codec" - // codectypes "github.com/cosmos/cosmos-sdk/codec/types" - // "github.com/cosmos/cosmos-sdk/store" - // storetypes "github.com/cosmos/cosmos-sdk/store/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - // "github.com/stretchr/testify/require" - // "github.com/tendermint/tendermint/libs/log" - // tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - // tmdb "github.com/tendermint/tm-db" - // "github.com/oracleNetworkProtocol/plugchain/x/token/types" -) - -func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { - // storeKey := sdk.NewKVStoreKey(types.StoreKey) - // memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) - - // db := tmdb.NewMemDB() - // stateStore := store.NewCommitMultiStore(db) - // stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db) - // stateStore.MountStoreWithDB(memStoreKey, sdk.StoreTypeMemory, nil) - // require.NoError(t, stateStore.LoadLatestVersion()) - - // registry := codectypes.NewInterfaceRegistry() - // keeper := NewKeeper(codec.NewProtoCodec(registry), storeKey,nil) - - // ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - // return keeper, ctx - return nil, sdk.Context{} -} diff --git a/x/token/keeper/msg_server_test.go b/x/token/keeper/msg_server_test.go deleted file mode 100644 index eb503fb54..000000000 --- a/x/token/keeper/msg_server_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package keeper - -import ( - "context" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/oracleNetworkProtocol/plugchain/x/token/types" -) - -func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) { - keeper, ctx := setupKeeper(t) - return NewMsgServerImpl(*keeper), sdk.WrapSDKContext(ctx) -}