From ddaaadd69d8461a4aa70c8a135e66d94983fef29 Mon Sep 17 00:00:00 2001 From: worryFree56 Date: Tue, 1 Mar 2022 11:31:57 +0800 Subject: [PATCH 1/4] add workflows to lint.yml --- .github/workflows/lint.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..7eb46e576 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint +# Lint runs golangci-lint over the entire plugchain repository This workflow is +# run on every pull request and push to main The `golangci` will pass without +# running if no *.{go, mod, sum} files have been changed. +on: + pull_request: + push: + branches: + - main +jobs: + golangci: + name: Run golangci-lint + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v2.4.0 + - uses: technote-space/get-diff-action@v6.0.1 + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - uses: golangci/golangci-lint-action@v3 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.42 + args: --timeout 10m + github-token: ${{ secrets.github_token }} + # Check only if there are differences in the source code + if: "env.GIT_DIFF" \ No newline at end of file From e49347427100641dc7300d51c6add04a3c637a01 Mon Sep 17 00:00:00 2001 From: worryFree56 Date: Tue, 1 Mar 2022 14:21:07 +0800 Subject: [PATCH 2/4] modify the classID of nft, the definition rules of nftID --- x/nft/types/validation.go | 43 +++++++++++++-------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) 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 } From 91b01b00bd5b88a806df7cf6dda7b247efa04251 Mon Sep 17 00:00:00 2001 From: worryFree56 Date: Tue, 1 Mar 2022 14:21:54 +0800 Subject: [PATCH 3/4] handling golangci detection --- cmd/plugchaind/cmd/root.go | 17 --------------- x/nft/keeper/keeper_test.go | 31 --------------------------- x/nft/keeper/msg_server_test.go | 14 ------------- x/token/client/cli/tx.go | 16 +++++++------- x/token/keeper/keeper.go | 2 +- x/token/keeper/keeper_test.go | 35 ------------------------------- x/token/keeper/msg_server_test.go | 14 ------------- 7 files changed, 9 insertions(+), 120 deletions(-) delete mode 100644 x/nft/keeper/keeper_test.go delete mode 100644 x/nft/keeper/msg_server_test.go delete mode 100644 x/token/keeper/keeper_test.go delete mode 100644 x/token/keeper/msg_server_test.go 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/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) -} From e1f31bb017edaa12e2a094b49e7b1f2a541b915a Mon Sep 17 00:00:00 2001 From: worryFree56 Date: Tue, 1 Mar 2022 14:22:27 +0800 Subject: [PATCH 4/4] del lint.yml --- .github/workflows/lint.yml | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 7eb46e576..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Lint -# Lint runs golangci-lint over the entire plugchain repository This workflow is -# run on every pull request and push to main The `golangci` will pass without -# running if no *.{go, mod, sum} files have been changed. -on: - pull_request: - push: - branches: - - main -jobs: - golangci: - name: Run golangci-lint - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v2.4.0 - - uses: technote-space/get-diff-action@v6.0.1 - with: - SUFFIX_FILTER: | - .go - .mod - .sum - - uses: golangci/golangci-lint-action@v3 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.42 - args: --timeout 10m - github-token: ${{ secrets.github_token }} - # Check only if there are differences in the source code - if: "env.GIT_DIFF" \ No newline at end of file