chainsvrwsresults_test.go raw
1 package btcjson_test
2
3 import (
4 "encoding/json"
5 "testing"
6
7 "github.com/p9c/p9/pkg/btcjson"
8 )
9
10 // TestChainSvrWsResults ensures any results that have custom marshalling work as intended.
11 func TestChainSvrWsResults(t *testing.T) {
12 t.Parallel()
13 tests := []struct {
14 name string
15 result interface{}
16 expected string
17 }{
18 {
19 name: "RescannedBlock",
20 result: &btcjson.RescannedBlock{
21 Hash: "blockhash",
22 Transactions: []string{"serializedtx"},
23 },
24 expected: `{"hash":"blockhash","transactions":["serializedtx"]}`,
25 },
26 }
27 t.Logf("Running %d tests", len(tests))
28 for i, test := range tests {
29 marshalled, e := json.Marshal(test.result)
30 if e != nil {
31 t.Errorf("Test #%d (%s) unexpected error: %v", i,
32 test.name, e,
33 )
34 continue
35 }
36 if string(marshalled) != test.expected {
37 t.Errorf("Test #%d (%s) unexpected marhsalled data - "+
38 "got %s, want %s", i, test.name, marshalled,
39 test.expected,
40 )
41 continue
42 }
43 }
44 }
45