Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: backport fix: only allow upper tickers (#716) #854

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions pkg/types/currency_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func ValidateDefiAssetString(asset string) error {
return fmt.Errorf("token field %q is invalid: %w", token, err)
}

if strings.ToUpper(asset) != asset {
return fmt.Errorf("incorrectly formatted asset string, expected: %q got: %q", strings.ToUpper(asset), asset)
}

return nil
}

Expand Down Expand Up @@ -204,19 +208,7 @@ func CurrencyPairFromString(s string) (CurrencyPair, error) {
}

func sanitizeAssetString(s string) (string, error) {
if IsLegacyAssetString(s) {
s = strings.ToUpper(s)
} else {
token, address, chainID, err := SplitDefiAssetString(s)
if err != nil {
return "", fmt.Errorf("incorrectly formatted asset: %q: %w", s, err)
}

token = strings.ToUpper(token)
s = strings.Join([]string{token, address, chainID}, fieldSeparator)
}

return s, nil
return strings.ToUpper(s), nil
}

// LegacyDecimals returns the number of decimals that the quote will be reported to. If the quote is Ethereum, then
Expand Down
40 changes: 32 additions & 8 deletions pkg/types/currency_pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,51 @@ func TestValidateBasic(t *testing.T) {
true,
},
{
"if Base formatted correctly as defi, Quote standard - pass",
"if Base formatted incorrectly as defi, Quote standard but rest lowercase - fail",
slinkytypes.CurrencyPair{
Base: "BB,testAddress,testChain",
Quote: "AA",
},
true,
false,
},
{
"if Quote formatted correctly as Base, Quote standard - pass",
"if Quote formatted incorrectly as Base, Quote standard but rest lowercase - fail",
slinkytypes.CurrencyPair{
Base: "BB",
Quote: "AA,testAddress,testChain",
},
true,
false,
},
{
"if both Quote + Base are formatted correctly as defi - pass",
"if both Quote + Base are formatted correctly as defi but rest lowercase - fail",
slinkytypes.CurrencyPair{
Base: "BB,testAddress,testChain",
Quote: "AA,testAddress,testChain",
},
false,
},
{
"if Base formatted incorrectly as defi, Quote standard - pass",
slinkytypes.CurrencyPair{
Base: "BB,TESTADDRESS,TESTCHAIN",
Quote: "AA",
},
true,
},
{
"if Quote formatted incorrectly as Base, Quote standard - pass",
slinkytypes.CurrencyPair{
Base: "BB",
Quote: "AA,TESTADDRESS,TESTCHAIN",
},
true,
},
{
"if both Quote + Base are formatted correctly as defi - pass",
slinkytypes.CurrencyPair{
Base: "BB,TESTADDRESS,TESTCHAIN",
Quote: "AA,TESTADDRESS,TESTCHAIN",
},
true,
},
}
Expand Down Expand Up @@ -237,19 +261,19 @@ func TestToFromString(t *testing.T) {
{
"if the string is not formatted upper-case (defi), return the original CurrencyPair",
"a,testAddress,testChain/B",
slinkytypes.CurrencyPair{Base: "A,testAddress,testChain", Quote: "B"},
slinkytypes.CurrencyPair{Base: "A,TESTADDRESS,TESTCHAIN", Quote: "B"},
true,
},
{
"if the string is not formatted upper-case (defi), return the original CurrencyPair",
"a/b,testAddress,testChain",
slinkytypes.CurrencyPair{Base: "A", Quote: "B,testAddress,testChain"},
slinkytypes.CurrencyPair{Base: "A", Quote: "B,TESTADDRESS,TESTCHAIN"},
true,
},
{
"if the string is not formatted upper-case (defi), return the original CurrencyPair",
"A,testAddress,testChain/B,testAddress,testChain",
slinkytypes.CurrencyPair{Base: "A,testAddress,testChain", Quote: "B,testAddress,testChain"},
slinkytypes.CurrencyPair{Base: "A,TESTADDRESS,TESTCHAIN", Quote: "B,TESTADDRESS,TESTCHAIN"},
true,
},
}
Expand Down
Loading