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