From 625020c6e820ade39859c8d842e9cc80bf8e9372 Mon Sep 17 00:00:00 2001 From: E Sequeira Date: Thu, 29 Sep 2022 01:01:18 +0100 Subject: [PATCH] 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 Co-authored-by: Adrian Gallagher --- currency/pair_methods.go | 5 +++++ currency/pair_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/currency/pair_methods.go b/currency/pair_methods.go index 841c219f..6ec9a5ea 100644 --- a/currency/pair_methods.go +++ b/currency/pair_methods.go @@ -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 diff --git a/currency/pair_test.go b/currency/pair_test.go index afa40bfe..001df884 100644 --- a/currency/pair_test.go +++ b/currency/pair_test.go @@ -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) {