ftx: fix null currency.Pair UnmarshalJSON (#1049)

* fix ftx unmarshal

* add tests

* fix ineffectual assignment to err

* Update currency/pair_test.go

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

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
E Sequeira
2022-09-29 01:01:18 +01:00
committed by GitHub
parent 71a10b055c
commit 625020c6e8
2 changed files with 21 additions and 0 deletions

View File

@@ -34,6 +34,11 @@ func (p *Pair) UnmarshalJSON(d []byte) error {
return err
}
if pair == "" {
*p = EMPTYPAIR
return nil
}
newPair, err := NewPairFromString(pair)
if err != nil {
return err

View File

@@ -70,6 +70,22 @@ func TestPairUnmarshalJSON(t *testing.T) {
t.Errorf("Pairs UnmarshalJSON() error expected %s but received %s",
configPair, unmarshalHere)
}
encoded, err = json.Marshal(EMPTYPAIR)
if err != nil {
t.Fatal(err)
}
err = json.Unmarshal(encoded, &unmarshalHere)
if err != nil {
t.Fatal("Pair UnmarshalJSON() error", err)
}
err = json.Unmarshal([]byte("null"), &unmarshalHere)
if err != nil {
t.Fatal("Pair UnmarshalJSON() error", err)
}
if unmarshalHere != EMPTYPAIR {
t.Fatalf("Expected EMPTYPAIR got: %s", unmarshalHere)
}
}
func TestPairMarshalJSON(t *testing.T) {