forked from gcash/bchd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchainsvrwsresults_test.go
50 lines (44 loc) · 1.14 KB
/
chainsvrwsresults_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2017 The btcsuite developers
// Copyright (c) 2017 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package btcjson_test
import (
"encoding/json"
"testing"
"github.com/gcash/bchd/btcjson"
)
// TestChainSvrWsResults ensures any results that have custom marshalling
// work as inteded.
func TestChainSvrWsResults(t *testing.T) {
t.Parallel()
tests := []struct {
name string
result interface{}
expected string
}{
{
name: "RescannedBlock",
result: &btcjson.RescannedBlock{
Hash: "blockhash",
Transactions: []string{"serializedtx"},
},
expected: `{"hash":"blockhash","transactions":["serializedtx"]}`,
},
}
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
marshalled, err := json.Marshal(test.result)
if err != nil {
t.Errorf("Test #%d (%s) unexpected error: %v", i,
test.name, err)
continue
}
if string(marshalled) != test.expected {
t.Errorf("Test #%d (%s) unexpected marhsalled data - "+
"got %s, want %s", i, test.name, marshalled,
test.expected)
continue
}
}
}