From bd78bf44dbf28a5ca093e88fae763ddbd1e35286 Mon Sep 17 00:00:00 2001 From: Daniel <24758309+leedaniil@users.noreply.github.com> Date: Fri, 7 Jan 2022 16:02:59 +0300 Subject: [PATCH] Update merge-fee-bot config, refactor validators (#17118) --- .github/merge-fee-bot.config.yml | 13 +++++-- internal/processor/service.go | 9 ++++- internal/processor/validators.go | 63 ++++++++++++++------------------ 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/.github/merge-fee-bot.config.yml b/.github/merge-fee-bot.config.yml index c66e4815d..d6f6689a4 100644 --- a/.github/merge-fee-bot.config.yml +++ b/.github/merge-fee-bot.config.yml @@ -44,7 +44,11 @@ message: * One PR should be for a single project; PR's with more than 10 logos will be rejected.\n * Payment evaluation happens automatically, but with a few minutes delay. When payment is detected, an Accept Review is automatically placed on the PR, which is a condition for merge.\n * Evaluating the PR is done manually, and it is merged only if all conditions are satisfied.\n - * TWT-BEP2 is supported (Binance Chain), TWT-BEP20 version on Smart Chain is not." + * TWT-BEP2 is supported (Binance Chain), TWT-BEP20 version on Smart Chain is not.\n\n + There will be a fee to process this request. None of it goes to the developers.\n + Before paying the fee, make sure new tokens fulfill the minimum circulation and other acceptance criteria.\n + If you are paying TWT for the submission, this will be burned automatically. There will be no refunds." + not_received: "Fee has not been received yet (or not fully).\n\n" received: "Fee is PAID, fantastic! Thanks!\n\n The PR will be evaluated soon by a maintainer, and if merged, the new logos should be visible in Trust Wallet.\n @@ -59,6 +63,7 @@ message: See the [Pull Request Fee FAQ](https://developer.trustwallet.com/add_new_asset/pr-fee)." closing_old_pr: "This PR is being closed due to inactivity. If you wish to continue, please have us reopen the PR before sending your payment, or just create a new one.\n Do NOT send payments for closed PR, as the fee may by lost!" + burned: "$PAID_AMOUNT $PAID_SYMBOL have been successfully [burned]($BURN_EXPLORER_LINK)" label: requested: 'Payment Status: Requested' @@ -70,9 +75,9 @@ user: moderators: Iamdeadlyz,Cryptocool1,cryptomanz timeout: - max_age_close_hours: 48 - max_idle_remind_hours: 22 - bg_check_delay_sec: 300 + max_age_close: 48h + max_idle_remind: 22h + background_check: 1m limitations: pr_files: 20 diff --git a/internal/processor/service.go b/internal/processor/service.go index 8356b2705..151ba882d 100644 --- a/internal/processor/service.go +++ b/internal/processor/service.go @@ -13,6 +13,8 @@ func NewService(fileProvider *file.Service) *Service { } func (s *Service) GetValidator(f *file.AssetFile) []Validator { + jsonValidator := Validator{Name: "JSON validation", Run: s.ValidateJSON} + switch f.Type() { case file.TypeRootFolder: return []Validator{ @@ -36,18 +38,21 @@ func (s *Service) GetValidator(f *file.AssetFile) []Validator { } case file.TypeAssetInfoFile: return []Validator{ - {Name: "Asset info (is valid json, fields)", Run: s.ValidateAssetInfoFile}, + jsonValidator, + {Name: "Asset info", Run: s.ValidateAssetInfoFile}, } case file.TypeChainInfoFile: return []Validator{ - {Name: "Chain Info (is valid json, fields)", Run: s.ValidateChainInfoFile}, + {Name: "Chain Info", Run: s.ValidateChainInfoFile}, } case file.TypeValidatorsListFile: return []Validator{ + jsonValidator, {Name: "Validators list file", Run: s.ValidateValidatorsListFile}, } case file.TypeTokenListFile: return []Validator{ + jsonValidator, {Name: "Token list (if assets from list present in chain)", Run: s.ValidateTokenListFile}, } case file.TypeChainInfoFolder: diff --git a/internal/processor/validators.go b/internal/processor/validators.go index 55dd67a8e..ddd7d4e4c 100644 --- a/internal/processor/validators.go +++ b/internal/processor/validators.go @@ -17,6 +17,27 @@ import ( "github.com/trustwallet/go-primitives/types" ) +func (s *Service) ValidateJSON(f *file.AssetFile) error { + file, err := os.Open(f.Path()) + if err != nil { + return err + } + defer file.Close() + + buf := bytes.NewBuffer(nil) + _, err = buf.ReadFrom(file) + if err != nil { + return err + } + + err = validation.ValidateJson(buf.Bytes()) + if err != nil { + return err + } + + return nil +} + func (s *Service) ValidateRootFolder(f *file.AssetFile) error { file, err := os.Open(f.Path()) if err != nil { @@ -82,7 +103,7 @@ func (s *Service) ValidateImage(f *file.AssetFile) error { } // TODO: Replace it with validation.ValidatePngImageDimension when "assets" repo is fixed. - // Read comments inValidatePngImageDimensionForCI. + // Read comments in ValidatePngImageDimensionForCI. err = validation.ValidatePngImageDimensionForCI(f.Path()) if err != nil { compErr.Append(err) @@ -202,11 +223,6 @@ func (s *Service) ValidateChainInfoFile(f *file.AssetFile) error { return err } - err = validation.ValidateJson(buf.Bytes()) - if err != nil { - return err - } - _, err = file.Seek(0, io.SeekStart) if err != nil { return fmt.Errorf("%w: failed to seek reader", validation.ErrInvalidJson) @@ -243,11 +259,6 @@ func (s *Service) ValidateAssetInfoFile(f *file.AssetFile) error { return err } - err = validation.ValidateJson(buf.Bytes()) - if err != nil { - return err - } - _, err = file.Seek(0, io.SeekStart) if err != nil { return fmt.Errorf("%w: failed to seek reader", validation.ErrInvalidJson) @@ -283,11 +294,6 @@ func (s *Service) ValidateValidatorsListFile(f *file.AssetFile) error { return err } - err = validation.ValidateJson(buf.Bytes()) - if err != nil { - return err - } - var model []list.Model err = json.Unmarshal(buf.Bytes(), &model) if err != nil { @@ -336,6 +342,7 @@ func isStackingChain(c coin.Coin) bool { return false } +// nolint:funlen func (s *Service) ValidateTokenListFile(f *file.AssetFile) error { file, err := os.Open(f.Path()) if err != nil { @@ -348,34 +355,20 @@ func (s *Service) ValidateTokenListFile(f *file.AssetFile) error { return err } - err = validation.ValidateJson(buf.Bytes()) - if err != nil { - return err - } - var model TokenList err = json.Unmarshal(buf.Bytes(), &model) if err != nil { return err } - err = compareTokenlistWithAssets(model.Tokens, f.Chain().Handle) - if err != nil { - return err - } - - return nil -} - -func compareTokenlistWithAssets(tokens []TokenItem, chain string) error { compErr := validation.NewErrComposite() - for _, token := range tokens { + for _, token := range model.Tokens { if token.Type == types.Coin { continue } - assetPath := path.GetAssetInfoPath(chain, token.Address) + assetPath := path.GetAssetInfoPath(f.Chain().Handle, token.Address) infoFile, err := os.Open(assetPath) if err != nil { @@ -396,15 +389,15 @@ func compareTokenlistWithAssets(tokens []TokenItem, chain string) error { } if string(token.Type) != *infoAsset.Type { - compErr.Append(fmt.Errorf("field type differs from %s", assetPath)) + compErr.Append(fmt.Errorf("field 'type' differs from %s", assetPath)) } if token.Symbol != *infoAsset.Symbol { - compErr.Append(fmt.Errorf("field symbol differs from %s", assetPath)) + compErr.Append(fmt.Errorf("field 'symbol' differs from %s", assetPath)) } if token.Decimals != uint(*infoAsset.Decimals) { - compErr.Append(fmt.Errorf("field decimals differs from %s", assetPath)) + compErr.Append(fmt.Errorf("field 'decimals' differs from %s", assetPath)) } }