How to use IsEmpty method of asset Package

Best Syzkaller code snippet using asset.IsEmpty

fields_validators.go

Source:fields_validators.go Github

copy

Full Screen

1package info2import (3 "fmt"4 "strings"5 str "github.com/trustwallet/assets-go-libs/strings"6 "github.com/trustwallet/assets-go-libs/validation"7 "github.com/trustwallet/go-primitives/coin"8 "github.com/trustwallet/go-primitives/types"9)10// Asset info specific validators.11func ValidateAssetRequiredKeys(a AssetModel) error {12 var fields []string13 if a.Name != nil && !isEmpty(*a.Name) {14 fields = append(fields, "name")15 }16 if a.Symbol != nil && !isEmpty(*a.Symbol) {17 fields = append(fields, "symbol")18 }19 if a.Type != nil && !isEmpty(*a.Type) {20 fields = append(fields, "type")21 }22 if a.Decimals != nil {23 fields = append(fields, "decimals")24 }25 if a.Description != nil && !isEmpty(*a.Description) {26 fields = append(fields, "description")27 }28 if a.Website != nil {29 fields = append(fields, "website")30 }31 if a.Explorer != nil && !isEmpty(*a.Explorer) {32 fields = append(fields, "explorer")33 }34 if a.Status != nil && !isEmpty(*a.Status) {35 fields = append(fields, "status")36 }37 if a.ID != nil && !isEmpty(*a.ID) {38 fields = append(fields, "id")39 }40 if len(fields) != len(requiredAssetFields) {41 return fmt.Errorf("%w: %s", validation.ErrMissingField,42 strings.Join(str.Difference(requiredAssetFields, fields), ", "))43 }44 return nil45}46func ValidateAssetType(assetType string, chain coin.Coin) error {47 chainFromType, err := types.GetChainFromAssetType(assetType)48 if err != nil {49 return fmt.Errorf("failed to get chain from asset type: %w", err)50 }51 if chainFromType != chain {52 return fmt.Errorf("%w: asset type field", validation.ErrInvalidField)53 }54 if strings.ToUpper(assetType) != assetType {55 return fmt.Errorf("%w: asset type should be ALLCAPS", validation.ErrInvalidField)56 }57 return nil58}59func ValidateAssetID(id, address string) error {60 if id != address {61 if !strings.EqualFold(id, address) {62 return fmt.Errorf("%w: invalid id field", validation.ErrInvalidField)63 }64 return fmt.Errorf("%w: invalid case for id field", validation.ErrInvalidField)65 }66 return nil67}68func ValidateAssetDecimalsAccordingType(assetType string, decimals int) error {69 if assetType == "BEP2" && decimals != 8 {70 return fmt.Errorf("%w: invalid decimals field, BEP2 tokens have 8 decimals", validation.ErrInvalidField)71 }72 return nil73}74// CoinModel info specific validators.75func ValidateCoinRequiredKeys(c CoinModel) error {76 var fields []string77 if c.Name != nil && !isEmpty(*c.Name) {78 fields = append(fields, "name")79 }80 if c.Symbol != nil && !isEmpty(*c.Symbol) {81 fields = append(fields, "symbol")82 }83 if c.Type != nil && !isEmpty(*c.Type) {84 fields = append(fields, "type")85 }86 if c.Decimals != nil {87 fields = append(fields, "decimals")88 }89 if c.Description != nil && !isEmpty(*c.Description) {90 fields = append(fields, "description")91 }92 if c.Website != nil && !isEmpty(*c.Website) {93 fields = append(fields, "website")94 }95 if c.Explorer != nil && !isEmpty(*c.Explorer) {96 fields = append(fields, "explorer")97 }98 if c.Status != nil && !isEmpty(*c.Status) {99 fields = append(fields, "status")100 }101 if len(fields) != len(requiredCoinFields) {102 return fmt.Errorf("%w: %s", validation.ErrMissingField,103 strings.Join(str.Difference(requiredCoinFields, fields), ", "))104 }105 return nil106}107func ValidateLinks(links []Link) error {108 if len(links) < 2 {109 return nil110 }111 for _, l := range links {112 if l.Name == nil || l.URL == nil {113 return fmt.Errorf("%w: missing required fields links.url and links.name", validation.ErrMissingField)114 }115 if !linkNameAllowed(*l.Name) {116 return fmt.Errorf("invalid value for links.name filed, allowed only: %s",117 strings.Join(supportedLinkNames(), ", "))118 }119 prefix := allowedLinkKeys[*l.Name]120 if prefix != "" {121 if !strings.HasPrefix(*l.URL, prefix) {122 return fmt.Errorf("invalid value '%s' for %s link url, allowed only with prefix: %s",123 *l.URL, *l.Name, prefix)124 }125 }126 if !strings.HasPrefix(*l.URL, "https://") {127 return fmt.Errorf("invalid value for links.url field, allowed only with https:// prefix")128 }129 if *l.Name == "medium" {130 if !strings.Contains(*l.URL, "medium.com") {131 return fmt.Errorf("invalid value for links.url field, should contain medium.com")132 }133 }134 }135 return nil136}137func ValidateCoinType(assetType string) error {138 if assetType != "coin" {139 return fmt.Errorf("%w: only \"coin\" type allowed for coin field", validation.ErrInvalidField)140 }141 return nil142}143func ValidateTags(tags, allowedTags []string) error {144 for _, t := range tags {145 if !str.Contains(t, allowedTags) {146 return fmt.Errorf("%w: tag '%s' not allowed", validation.ErrInvalidField, t)147 }148 }149 return nil150}151// Both infos can be validated by this validators.152func ValidateDecimals(decimals int) error {153 if decimals > 30 || decimals < 0 {154 return fmt.Errorf("%w: decimals field", validation.ErrInvalidField)155 }156 return nil157}158func ValidateStatus(status string) error {159 for _, f := range allowedStatusValues {160 if f == status {161 return nil162 }163 }164 return fmt.Errorf("%w: allowed status field values: %s", validation.ErrInvalidField,165 strings.Join(allowedStatusValues, ", "))166}167func ValidateDescription(description string) error {168 if len(description) > 600 {169 return fmt.Errorf("%w: invalid length for description field", validation.ErrInvalidField)170 }171 for _, ch := range whiteSpaceCharacters {172 if strings.Contains(description, ch) {173 return fmt.Errorf("%w: description contains not allowed characters (new line, double space)",174 validation.ErrInvalidField)175 }176 }177 return nil178}179func ValidateDescriptionWebsite(description, website string) error {180 if description != "-" && website == "" {181 return fmt.Errorf("%w: website field", validation.ErrMissingField)182 }183 return nil184}185func ValidateExplorer(explorer, name string, chain coin.Coin, addr, tokenType string) error {186 explorerExpected, err := coin.GetCoinExploreURL(chain, addr, tokenType)187 if err != nil {188 explorerExpected = ""189 }190 explorerActual := explorer191 if !strings.EqualFold(explorerActual, explorerExpected) {192 explorerAlt := explorerURLAlternatives(chain.Handle, name)193 if len(explorerAlt) == 0 {194 return nil195 }196 var matchCount int197 for _, e := range explorerAlt {198 if strings.EqualFold(e, explorerActual) {199 matchCount++200 }201 }202 if matchCount == 0 {203 return fmt.Errorf("invalid value for explorer field, %s insted of %s", explorerActual, explorerExpected)204 }205 }206 return nil207}208func isEmpty(field string) bool {209 return field == ""210}...

Full Screen

Full Screen

msg_add_liquidity.go

Source:msg_add_liquidity.go Github

copy

Full Screen

...27func (m *MsgAddLiquidity) ValidateBasic() error {28 if m.Signer.Empty() {29 return cosmos.ErrInvalidAddress(m.Signer.String())30 }31 if m.Asset.IsEmpty() {32 return cosmos.ErrUnknownRequest("add liquidity asset cannot be empty")33 }34 if err := m.Tx.Valid(); err != nil {35 return cosmos.ErrUnknownRequest(err.Error())36 }37 // There is no dedicate pool for RUNE, because every pool will have RUNE, that's by design38 if m.Asset.IsRune() {39 return cosmos.ErrUnknownRequest("asset cannot be rune")40 }41 // test scenario we get two coins, but none are rune, invalid liquidity provider42 if len(m.Tx.Coins) == 2 && (m.AssetAmount.IsZero() || m.RuneAmount.IsZero()) {43 return cosmos.ErrUnknownRequest("did not find both coins")44 }45 if len(m.Tx.Coins) > 2 {46 return cosmos.ErrUnknownRequest("not expecting more than two coins in adding liquidity")47 }48 if m.RuneAmount.IsZero() && m.AssetAmount.IsZero() {49 return cosmos.ErrUnknownRequest("rune and asset amounts cannot both be empty")50 }51 if m.RuneAddress.IsEmpty() && m.AssetAddress.IsEmpty() {52 return cosmos.ErrUnknownRequest("rune address and asset address cannot be empty")53 }54 if m.AffiliateAddress.IsEmpty() && !m.AffiliateBasisPoints.IsZero() {55 return cosmos.ErrUnknownRequest("affiliate address is empty while affiliate basis points is non-zero")56 }57 if !m.AffiliateAddress.IsEmpty() && !m.AffiliateAddress.IsChain(common.THORChain) {58 return cosmos.ErrUnknownRequest("affiliate address must be a THOR address")59 }60 return nil61}62// ValidateBasicV63 runs stateless checks on the message63func (m *MsgAddLiquidity) ValidateBasicV63() error {64 if m.Signer.Empty() {65 return cosmos.ErrInvalidAddress(m.Signer.String())66 }67 if m.Asset.IsEmpty() {68 return cosmos.ErrUnknownRequest("add liquidity asset cannot be empty")69 }70 if err := m.Tx.Valid(); err != nil {71 return cosmos.ErrUnknownRequest(err.Error())72 }73 // There is no dedicate pool for RUNE, because every pool will have RUNE, that's by design74 if m.Asset.IsRune() {75 return cosmos.ErrUnknownRequest("asset cannot be rune")76 }77 // test scenario we get two coins, but none are rune, invalid liquidity provider78 if len(m.Tx.Coins) == 2 && (m.AssetAmount.IsZero() || m.RuneAmount.IsZero()) {79 return cosmos.ErrUnknownRequest("did not find both coins")80 }81 if len(m.Tx.Coins) > 2 {82 return cosmos.ErrUnknownRequest("not expecting more than two coins in adding liquidity")83 }84 if m.RuneAmount.IsZero() && m.AssetAmount.IsZero() {85 return cosmos.ErrUnknownRequest("rune and asset amounts cannot both be empty")86 }87 if m.RuneAddress.IsEmpty() && m.AssetAddress.IsEmpty() {88 return cosmos.ErrUnknownRequest("rune address and asset address cannot be empty")89 }90 if m.AffiliateAddress.IsEmpty() && !m.AffiliateBasisPoints.IsZero() {91 return cosmos.ErrUnknownRequest("affiliate address is empty while affiliate basis points is non-zero")92 }93 if !m.AffiliateBasisPoints.IsZero() && m.AffiliateBasisPoints.GT(cosmos.NewUint(MaxAffiliateFeeBasisPoints)) {94 return cosmos.ErrUnknownRequest(fmt.Sprintf("affiliate fee basis points can't be more than %d", MaxAffiliateFeeBasisPoints))95 }96 if !m.AffiliateAddress.IsEmpty() && !m.AffiliateAddress.IsChain(common.THORChain) {97 return cosmos.ErrUnknownRequest("affiliate address must be a THOR address")98 }99 return nil100}101// GetSignBytes encodes the message for signing102func (m *MsgAddLiquidity) GetSignBytes() []byte {103 return cosmos.MustSortJSON(ModuleCdc.MustMarshalJSON(m))104}105// GetSigners defines whose signature is required106func (m *MsgAddLiquidity) GetSigners() []cosmos.AccAddress {107 return []cosmos.AccAddress{m.Signer}108}...

Full Screen

Full Screen

asset_test.go

Source:asset_test.go Github

copy

Full Screen

...8 asset, err := NewAsset("thor.rune")9 c.Assert(err, IsNil)10 c.Check(asset.Equals(RuneNative), Equals, true)11 c.Check(asset.IsRune(), Equals, true)12 c.Check(asset.IsEmpty(), Equals, false)13 c.Check(asset.Synth, Equals, false)14 c.Check(asset.String(), Equals, "THOR.RUNE")15 asset, err = NewAsset("thor/rune")16 c.Assert(err, IsNil)17 c.Check(asset.Equals(RuneNative), Equals, false)18 c.Check(asset.IsRune(), Equals, false)19 c.Check(asset.IsEmpty(), Equals, false)20 c.Check(asset.Synth, Equals, true)21 c.Check(asset.String(), Equals, "THOR/RUNE")22 c.Check(asset.Chain.Equals(THORChain), Equals, true)23 c.Check(asset.Symbol.Equals(Symbol("RUNE")), Equals, true)24 c.Check(asset.Ticker.Equals(Ticker("RUNE")), Equals, true)25 asset, err = NewAsset("BNB.SWIPE.B-DC0")26 c.Assert(err, IsNil)27 c.Check(asset.String(), Equals, "BNB.SWIPE.B-DC0")28 c.Check(asset.Chain.Equals(BNBChain), Equals, true)29 c.Check(asset.Symbol.Equals(Symbol("SWIPE.B-DC0")), Equals, true)30 c.Check(asset.Ticker.Equals(Ticker("SWIPE.B")), Equals, true)31 // parse without chain32 asset, err = NewAsset("rune")33 c.Assert(err, IsNil)34 c.Check(asset.Equals(RuneNative), Equals, true)35 // ETH test36 asset, err = NewAsset("eth.knc")37 c.Assert(err, IsNil)38 c.Check(asset.Chain.Equals(ETHChain), Equals, true)39 c.Check(asset.Symbol.Equals(Symbol("KNC")), Equals, true)40 c.Check(asset.Ticker.Equals(Ticker("KNC")), Equals, true)41 asset, err = NewAsset("ETH.RUNE-0x3155ba85d5f96b2d030a4966af206230e46849cb")42 c.Assert(err, IsNil)43 // DOGE test44 asset, err = NewAsset("doge.doge")45 c.Assert(err, IsNil)46 c.Check(asset.Chain.Equals(DOGEChain), Equals, true)47 c.Check(asset.Equals(DOGEAsset), Equals, true)48 c.Check(asset.IsRune(), Equals, false)49 c.Check(asset.IsEmpty(), Equals, false)50 c.Check(asset.String(), Equals, "DOGE.DOGE")51 // BCH test52 asset, err = NewAsset("bch.bch")53 c.Assert(err, IsNil)54 c.Check(asset.Chain.Equals(BCHChain), Equals, true)55 c.Check(asset.Equals(BCHAsset), Equals, true)56 c.Check(asset.IsRune(), Equals, false)57 c.Check(asset.IsEmpty(), Equals, false)58 c.Check(asset.String(), Equals, "BCH.BCH")59 // LTC test60 asset, err = NewAsset("ltc.ltc")61 c.Assert(err, IsNil)62 c.Check(asset.Chain.Equals(LTCChain), Equals, true)63 c.Check(asset.Equals(LTCAsset), Equals, true)64 c.Check(asset.IsRune(), Equals, false)65 c.Check(asset.IsEmpty(), Equals, false)66 c.Check(asset.String(), Equals, "LTC.LTC")67 // btc/btc68 asset, err = NewAsset("btc/btc")69 c.Check(err, IsNil)70 c.Check(asset.Chain.Equals(BTCChain), Equals, true)71 c.Check(asset.Equals(BTCAsset), Equals, false)72 c.Check(asset.IsEmpty(), Equals, false)73 c.Check(asset.String(), Equals, "BTC/BTC")74}...

Full Screen

Full Screen

IsEmpty

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Asset struct {3}4func (a *Asset) IsEmpty() bool {5}6func main() {7 fmt.Println(a.IsEmpty())8}9import "fmt"10type Asset struct {11}12func (a Asset) IsEmpty() bool {13}14func main() {15 fmt.Println(a.IsEmpty())16}

Full Screen

Full Screen

IsEmpty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(a.IsEmpty())4 fmt.Println(a.IsEmpty())5}6The IsEmpty() method will check if the name of the asset is empty or not. If the name is empty, it will return true otherwise it will return false. The IsEmpty() method will have the receiver type as Asset. This means that we can call this method by using the Asset type. This method will return a boolean value. This method will have the following signature:7func (a Asset) IsEmpty() bool8The IsEmpty() method will check if the name of the asset is empty or not. If the name is empty, it will return true otherwise it will return false. The IsEmpty() method will have the receiver type as Asset. This means that we can call this method by using the Asset type. This method will return a boolean value. This method will have the following signature:9func (a Asset) IsEmpty() bool {10 if a.Name == "" {11 }12}13In this tutorial, we have learned how to create a method in Go. We have created a method called IsEmpty() in the Asset class. This method will return true if the name of the asset is empty otherwise it will return false. We have called this

Full Screen

Full Screen

IsEmpty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a := asset.Asset{}4 if a.IsEmpty() {5 fmt.Println("Asset is empty")6 }7}8GoLang: How to use the “import” statement

Full Screen

Full Screen

IsEmpty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 asset1 := asset.Asset{4 }5 isEmpty := asset1.IsEmpty()6 fmt.Println(isEmpty)7}

Full Screen

Full Screen

IsEmpty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a := asset.NewAsset("USD", 100)4 b := asset.NewAsset("USD", 0)5 fmt.Println("a is empty:", a.IsEmpty())6 fmt.Println("b is empty:", b.IsEmpty())7}

Full Screen

Full Screen

IsEmpty

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(a.IsEmpty())4 fmt.Println(a.IsEmpty())5}6import (7func main() {8 fmt.Println(a.IsEmpty())9 fmt.Println(a.IsEmpty())10}11import (12func main() {13 fmt.Println(a.IsEmpty())14 fmt.Println(a.IsEmpty())15}16import (17func main() {18 fmt.Println(a.IsEmpty())19 fmt.Println(a.IsEmpty())20}21import (22func main() {23 fmt.Println(a.IsEmpty())24 fmt.Println(a.IsEmpty())25}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful