Skip to content

Commit

Permalink
ftx: fix null currency.Pair UnmarshalJSON (thrasher-corp#1049)
Browse files Browse the repository at this point in the history
* fix ftx unmarshal

* add tests

* fix ineffectual assignment to err

* Update currency/pair_test.go

Co-authored-by: Adrian Gallagher <[email protected]>

Co-authored-by: Adrian Gallagher <[email protected]>
  • Loading branch information
geseq and thrasher- authored Sep 29, 2022
1 parent 71a10b0 commit 625020c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions currency/pair_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions currency/pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 625020c

Please sign in to comment.