Update merge-fee-bot config, refactor validators (#17118)

This commit is contained in:
Daniel 2022-01-07 16:02:59 +03:00 committed by GitHub
parent e7f9efcd2c
commit bd78bf44db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 41 deletions

View File

@ -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

View File

@ -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:

View File

@ -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))
}
}