testing: bybit references, bybit mock testing, pair formatting, standards improvement (#1322)

* fixes tests

* pair formats and extra fixes

* quick change before shazbert sees

* sneaky lint

* adds bybit mock testing and fixes test

* whoops

* error response instead

* classic forgetting to lint

* bybit live test no longer auto-records results

* ty thrasher- Update exchanges/bybit/bybit_wrapper.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

---------

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Scott
2023-08-21 14:48:56 +10:00
committed by GitHub
parent 577817c46e
commit c7b3ace78c
16 changed files with 92170 additions and 120 deletions

View File

@@ -149,3 +149,14 @@ func MatchPairsWithNoDelimiter(currencyPair string, pairs Pairs, pairFmt PairFor
}
return EMPTYPAIR, fmt.Errorf("currency %v not found in supplied pairs", currencyPair)
}
// GetFormatting returns the formatting style of a pair
func (p Pair) GetFormatting() (PairFormat, error) {
if p.Base.UpperCase != p.Quote.UpperCase {
return PairFormat{}, fmt.Errorf("%w casing mismatch", errPairFormattingInconsistent)
}
return PairFormat{
Uppercase: p.Base.UpperCase,
Delimiter: p.Delimiter,
}, nil
}

View File

@@ -1067,3 +1067,30 @@ func TestIsAssociated(t *testing.T) {
})
}
}
func TestPair_GetFormatting(t *testing.T) {
t.Parallel()
p := NewPair(BTC, USDT)
pFmt, err := p.GetFormatting()
if err != nil {
t.Error(err)
}
if !pFmt.Uppercase || pFmt.Delimiter != "" {
t.Error("incorrect formatting")
}
p = NewPairWithDelimiter("eth", "usdt", "/")
pFmt, err = p.GetFormatting()
if err != nil {
t.Error(err)
}
if pFmt.Uppercase || pFmt.Delimiter != "/" {
t.Error("incorrect formatting")
}
p = NewPairWithDelimiter("eth", "USDT", "/")
_, err = p.GetFormatting()
if !errors.Is(err, errPairFormattingInconsistent) {
t.Error(err)
}
}

View File

@@ -11,9 +11,9 @@ import (
)
var (
errSymbolEmpty = errors.New("symbol is empty")
errPairsEmpty = errors.New("pairs are empty")
errNoDelimiter = errors.New("no delimiter was supplied")
errSymbolEmpty = errors.New("symbol is empty")
errNoDelimiter = errors.New("no delimiter was supplied")
errPairFormattingInconsistent = errors.New("pair formatting is inconsistent")
// ErrPairDuplication defines an error when there is multiple of the same
// currency pairs found.
@@ -136,7 +136,7 @@ func (p Pairs) Contains(check Pair, exact bool) bool {
// original pairs list.
func (p Pairs) ContainsAll(check Pairs, exact bool) error {
if len(check) == 0 {
return errPairsEmpty
return ErrCurrencyPairsEmpty
}
comparative := make(Pairs, len(p))
@@ -306,7 +306,7 @@ func (p Pairs) GetRandomPair() (Pair, error) {
// delimiter is supplied.
func (p Pairs) DeriveFrom(symbol string) (Pair, error) {
if len(p) == 0 {
return EMPTYPAIR, errPairsEmpty
return EMPTYPAIR, ErrCurrencyPairsEmpty
}
if symbol == "" {
return EMPTYPAIR, errSymbolEmpty
@@ -442,3 +442,18 @@ func (p Pairs) ValidateAndConform(pFmt PairFormat, bypassFormatting bool) (Pairs
}
return formatted, nil
}
// GetFormatting returns the formatting of a set of pairs
func (p Pairs) GetFormatting() (PairFormat, error) {
if len(p) == 0 {
return PairFormat{}, ErrCurrencyPairsEmpty
}
pFmt, err := p[0].GetFormatting()
if err != nil {
return PairFormat{}, err
}
if p.HasFormatDifference(pFmt) {
return PairFormat{}, errPairFormattingInconsistent
}
return pFmt, nil
}

View File

@@ -344,8 +344,8 @@ func TestContainsAll(t *testing.T) {
}
err := pairs.ContainsAll(nil, true)
if !errors.Is(err, errPairsEmpty) {
t.Fatalf("received: '%v' but expected: '%v'", err, errPairsEmpty)
if !errors.Is(err, ErrCurrencyPairsEmpty) {
t.Fatalf("received: '%v' but expected: '%v'", err, ErrCurrencyPairsEmpty)
}
err = pairs.ContainsAll(Pairs{NewPair(BTC, USD)}, true)
@@ -394,8 +394,8 @@ func TestContainsAll(t *testing.T) {
func TestDeriveFrom(t *testing.T) {
t.Parallel()
_, err := Pairs{}.DeriveFrom("")
if !errors.Is(err, errPairsEmpty) {
t.Fatalf("received: '%v' but expected: '%v'", err, errPairsEmpty)
if !errors.Is(err, ErrCurrencyPairsEmpty) {
t.Fatalf("received: '%v' but expected: '%v'", err, ErrCurrencyPairsEmpty)
}
var testCases = Pairs{
NewPair(BTC, USDT),
@@ -783,3 +783,36 @@ func TestValidateAndConform(t *testing.T) {
t.Fatalf("received: '%v' but expected '%v'", formatted.Join(), expected)
}
}
func TestPairs_GetFormatting(t *testing.T) {
t.Parallel()
p := Pairs{NewPair(BTC, USDT)}
pFmt, err := p.GetFormatting()
if err != nil {
t.Error(err)
}
if !pFmt.Uppercase || pFmt.Delimiter != "" {
t.Error("incorrect formatting")
}
p = Pairs{NewPairWithDelimiter("eth", "usdt", "/")}
pFmt, err = p.GetFormatting()
if err != nil {
t.Error(err)
}
if pFmt.Uppercase || pFmt.Delimiter != "/" {
t.Error("incorrect formatting")
}
p = Pairs{NewPair(BTC, USDT), NewPairWithDelimiter("eth", "usdt", "/")}
_, err = p.GetFormatting()
if !errors.Is(err, errPairFormattingInconsistent) {
t.Error(err)
}
p = Pairs{NewPairWithDelimiter("eth", "USDT", "/")}
_, err = p.GetFormatting()
if !errors.Is(err, errPairFormattingInconsistent) {
t.Error(err)
}
}