Skip to content

Commit

Permalink
add test case for floatString.UnmarshalJSON
Browse files Browse the repository at this point in the history
- remove unused type ntfn in btc/electrum/jsonrpcs.go

Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Jun 27, 2024
1 parent af5a590 commit 9977d4b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion client/asset/btc/electrum/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type response struct {
Error *RPCError `json:"error"`
}

type ntfn = request // weird but true
type ntfnData struct {
Params json.RawMessage `json:"params"`
}
Expand Down
41 changes: 41 additions & 0 deletions client/asset/btc/electrum/jsonrpc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package electrum

import (
"fmt"
"testing"
)

func Test_floatString_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
arg []byte
wantErr bool
}{
{
name: "float64",
arg: []byte{49, 50, 46, 50, 51}, // 12.23
},
{
name: "string float64",
arg: []byte{34, 49, 50, 46, 50, 51, 34}, // "12.23"
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var fs floatString
if err := fs.UnmarshalJSON(tt.arg); (err != nil) != tt.wantErr {
t.Errorf("%s: error = %v, wantErr %v", tt.name, err, tt.wantErr)
}

fsStr := fmt.Sprint(fs)
fsByte := []byte(fsStr)
if string(fsByte) != fsStr {
t.Errorf("%s: expected %v got %v", tt.name, string(fsByte), fsStr)
}
})
}
}

0 comments on commit 9977d4b

Please sign in to comment.