func TestMarshalResponse(t *testing.T) {
	t.Parallel()

	testID := 1
	tests := []struct {
		name     string
		result   interface{}
		jsonErr  *btcjson.RPCError
		expected []byte
	}{
		{
			name:     "ordinary bool result with no error",
			result:   true,
			jsonErr:  nil,
			expected: []byte(`{"result":true,"error":null,"id":1}`),
		},
		{
			name:   "result with error",
			result: nil,
			jsonErr: func() *btcjson.RPCError {
				return btcjson.NewRPCError(btcjson.ErrRPCBlockNotFound, "123 not found")
			}(),
			expected: []byte(`{"result":null,"error":{"code":-5,"message":"123 not found"},"id":1}`),
		},
	}

	t.Logf("Running %d tests", len(tests))
	for i, test := range tests {
		_, _ = i, test
		marshalled, err := btcjson.MarshalResponse(testID, test.result, test.jsonErr)
		if err != nil {
			t.Errorf("Test #%d (%s) unexpected error: %v", i,
				test.name, err)
			continue
		}

		if !reflect.DeepEqual(marshalled, test.expected) {
			t.Errorf("Test #%d (%s) mismatched result - got %s, "+
				"want %s", i, test.name, marshalled,
				test.expected)
		}
	}
}
// TestMarshalResponse ensures the MarshalResponse function works as expected.
TestMarshalResponse ensures the MarshalResponse function works as expected.
// TestMarshalResponse ensures the MarshalResponse function works as expected .
func TestMarshalResponse(t *testing.T) {
	t.Parallel()
	testID := 1
	tests := []struct {
		name     string
		result   interface{}
		jsonErr  *btcjson.RPCError
		expected []byte
	}{
		{
			name:     "ordinary bool result with no error",
			result:   true,
			jsonErr:  nil,
			expected: []byte(`{"result":true,"error":null,"id":1}`),
		},
		{
			name:   "result with error",
			result: nil,
			jsonErr: func() *btcjson.RPCError {
				return btcjson.NewRPCError(btcjson.ErrRPCBlockNotFound, "123 not found")
			}(),
			expected: []byte(`{"result":null,"error":{"code":-5,"message":"123 not found"},"id":1}`),
		},
	}
	t.Logf("Running %d tests", len(tests))
	for i, test := range tests {
		_, _ = i, test
		marshalled, err := btcjson.MarshalResponse(testID, test.result, test.jsonErr)
		if err != nil {
			t.Errorf("Test #%d (%s) unexpected error: %v", i,
				test.name, err)
			continue
		}
		if !reflect.DeepEqual(marshalled, test.expected) {
			t.Errorf("Test #%d (%s) mismatched result - got %s, "+
				"want %s", i, test.name, marshalled,
				test.expected)
		}
	}
}
func TestMarshalResponse ( t * testing . T ) { t . Parallel ( ) testID := 1 tests := [ ] struct { name string result interface { } jsonErr * btcjson . RPCError expected [ ] byte } { { name : " " , result : true , jsonErr : nil , expected : [ ] byte ( `{"result":true,"error":null,"id":1}` ) , } , { name : " " , result : nil , jsonErr : func ( ) * btcjson . RPCError { return btcjson . NewRPCError ( btcjson . ErrRPCBlockNotFound , " " ) } ( ) , expected : [ ] byte ( `{"result":null,"error":{"code":-5,"message":"123 not found"},"id":1}` ) , } , } t . Logf ( " " , len ( tests ) ) for i , test := range tests { _ , _ = i , test marshalled , err := btcjson . MarshalResponse ( testID , test . result , test . jsonErr ) if err != nil { t . Errorf ( " " , i , test . name , err ) continue } if ! reflect . DeepEqual ( marshalled , test . expected ) { t . Errorf ( " " + " " , i , test . name , marshalled , test . expected ) } } }
TestMarshalResponse ensures the MarshalResponse function works as expected.
TestMarshalResponse ensures the MarshalResponse function works as expected .