OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / btcjson / walletsvrcmds_test.go
1 // Copyright (c) 2014 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
4
5 package btcjson_test
6
7 import (
8         "bytes"
9         "encoding/json"
10         "fmt"
11         "reflect"
12         "testing"
13
14         "github.com/btcsuite/btcd/btcjson"
15 )
16
17 // TestWalletSvrCmds tests all of the wallet server commands marshal and
18 // unmarshal into valid results include handling of optional fields being
19 // omitted in the marshalled command, while optional fields with defaults have
20 // the default assigned on unmarshalled commands.
21 func TestWalletSvrCmds(t *testing.T) {
22         t.Parallel()
23
24         testID := int(1)
25         tests := []struct {
26                 name         string
27                 newCmd       func() (interface{}, error)
28                 staticCmd    func() interface{}
29                 marshalled   string
30                 unmarshalled interface{}
31         }{
32                 {
33                         name: "addmultisigaddress",
34                         newCmd: func() (interface{}, error) {
35                                 return btcjson.NewCmd("addmultisigaddress", 2, []string{"031234", "035678"})
36                         },
37                         staticCmd: func() interface{} {
38                                 keys := []string{"031234", "035678"}
39                                 return btcjson.NewAddMultisigAddressCmd(2, keys, nil)
40                         },
41                         marshalled: `{"jsonrpc":"1.0","method":"addmultisigaddress","params":[2,["031234","035678"]],"id":1}`,
42                         unmarshalled: &btcjson.AddMultisigAddressCmd{
43                                 NRequired: 2,
44                                 Keys:      []string{"031234", "035678"},
45                                 Account:   nil,
46                         },
47                 },
48                 {
49                         name: "addmultisigaddress optional",
50                         newCmd: func() (interface{}, error) {
51                                 return btcjson.NewCmd("addmultisigaddress", 2, []string{"031234", "035678"}, "test")
52                         },
53                         staticCmd: func() interface{} {
54                                 keys := []string{"031234", "035678"}
55                                 return btcjson.NewAddMultisigAddressCmd(2, keys, btcjson.String("test"))
56                         },
57                         marshalled: `{"jsonrpc":"1.0","method":"addmultisigaddress","params":[2,["031234","035678"],"test"],"id":1}`,
58                         unmarshalled: &btcjson.AddMultisigAddressCmd{
59                                 NRequired: 2,
60                                 Keys:      []string{"031234", "035678"},
61                                 Account:   btcjson.String("test"),
62                         },
63                 },
64                 {
65                         name: "createmultisig",
66                         newCmd: func() (interface{}, error) {
67                                 return btcjson.NewCmd("createmultisig", 2, []string{"031234", "035678"})
68                         },
69                         staticCmd: func() interface{} {
70                                 keys := []string{"031234", "035678"}
71                                 return btcjson.NewCreateMultisigCmd(2, keys)
72                         },
73                         marshalled: `{"jsonrpc":"1.0","method":"createmultisig","params":[2,["031234","035678"]],"id":1}`,
74                         unmarshalled: &btcjson.CreateMultisigCmd{
75                                 NRequired: 2,
76                                 Keys:      []string{"031234", "035678"},
77                         },
78                 },
79                 {
80                         name: "dumpprivkey",
81                         newCmd: func() (interface{}, error) {
82                                 return btcjson.NewCmd("dumpprivkey", "1Address")
83                         },
84                         staticCmd: func() interface{} {
85                                 return btcjson.NewDumpPrivKeyCmd("1Address")
86                         },
87                         marshalled: `{"jsonrpc":"1.0","method":"dumpprivkey","params":["1Address"],"id":1}`,
88                         unmarshalled: &btcjson.DumpPrivKeyCmd{
89                                 Address: "1Address",
90                         },
91                 },
92                 {
93                         name: "encryptwallet",
94                         newCmd: func() (interface{}, error) {
95                                 return btcjson.NewCmd("encryptwallet", "pass")
96                         },
97                         staticCmd: func() interface{} {
98                                 return btcjson.NewEncryptWalletCmd("pass")
99                         },
100                         marshalled: `{"jsonrpc":"1.0","method":"encryptwallet","params":["pass"],"id":1}`,
101                         unmarshalled: &btcjson.EncryptWalletCmd{
102                                 Passphrase: "pass",
103                         },
104                 },
105                 {
106                         name: "estimatefee",
107                         newCmd: func() (interface{}, error) {
108                                 return btcjson.NewCmd("estimatefee", 6)
109                         },
110                         staticCmd: func() interface{} {
111                                 return btcjson.NewEstimateFeeCmd(6)
112                         },
113                         marshalled: `{"jsonrpc":"1.0","method":"estimatefee","params":[6],"id":1}`,
114                         unmarshalled: &btcjson.EstimateFeeCmd{
115                                 NumBlocks: 6,
116                         },
117                 },
118                 {
119                         name: "estimatepriority",
120                         newCmd: func() (interface{}, error) {
121                                 return btcjson.NewCmd("estimatepriority", 6)
122                         },
123                         staticCmd: func() interface{} {
124                                 return btcjson.NewEstimatePriorityCmd(6)
125                         },
126                         marshalled: `{"jsonrpc":"1.0","method":"estimatepriority","params":[6],"id":1}`,
127                         unmarshalled: &btcjson.EstimatePriorityCmd{
128                                 NumBlocks: 6,
129                         },
130                 },
131                 {
132                         name: "getaccount",
133                         newCmd: func() (interface{}, error) {
134                                 return btcjson.NewCmd("getaccount", "1Address")
135                         },
136                         staticCmd: func() interface{} {
137                                 return btcjson.NewGetAccountCmd("1Address")
138                         },
139                         marshalled: `{"jsonrpc":"1.0","method":"getaccount","params":["1Address"],"id":1}`,
140                         unmarshalled: &btcjson.GetAccountCmd{
141                                 Address: "1Address",
142                         },
143                 },
144                 {
145                         name: "getaccountaddress",
146                         newCmd: func() (interface{}, error) {
147                                 return btcjson.NewCmd("getaccountaddress", "acct")
148                         },
149                         staticCmd: func() interface{} {
150                                 return btcjson.NewGetAccountAddressCmd("acct")
151                         },
152                         marshalled: `{"jsonrpc":"1.0","method":"getaccountaddress","params":["acct"],"id":1}`,
153                         unmarshalled: &btcjson.GetAccountAddressCmd{
154                                 Account: "acct",
155                         },
156                 },
157                 {
158                         name: "getaddressesbyaccount",
159                         newCmd: func() (interface{}, error) {
160                                 return btcjson.NewCmd("getaddressesbyaccount", "acct")
161                         },
162                         staticCmd: func() interface{} {
163                                 return btcjson.NewGetAddressesByAccountCmd("acct")
164                         },
165                         marshalled: `{"jsonrpc":"1.0","method":"getaddressesbyaccount","params":["acct"],"id":1}`,
166                         unmarshalled: &btcjson.GetAddressesByAccountCmd{
167                                 Account: "acct",
168                         },
169                 },
170                 {
171                         name: "getbalance",
172                         newCmd: func() (interface{}, error) {
173                                 return btcjson.NewCmd("getbalance")
174                         },
175                         staticCmd: func() interface{} {
176                                 return btcjson.NewGetBalanceCmd(nil, nil)
177                         },
178                         marshalled: `{"jsonrpc":"1.0","method":"getbalance","params":[],"id":1}`,
179                         unmarshalled: &btcjson.GetBalanceCmd{
180                                 Account: nil,
181                                 MinConf: btcjson.Int(1),
182                         },
183                 },
184                 {
185                         name: "getbalance optional1",
186                         newCmd: func() (interface{}, error) {
187                                 return btcjson.NewCmd("getbalance", "acct")
188                         },
189                         staticCmd: func() interface{} {
190                                 return btcjson.NewGetBalanceCmd(btcjson.String("acct"), nil)
191                         },
192                         marshalled: `{"jsonrpc":"1.0","method":"getbalance","params":["acct"],"id":1}`,
193                         unmarshalled: &btcjson.GetBalanceCmd{
194                                 Account: btcjson.String("acct"),
195                                 MinConf: btcjson.Int(1),
196                         },
197                 },
198                 {
199                         name: "getbalance optional2",
200                         newCmd: func() (interface{}, error) {
201                                 return btcjson.NewCmd("getbalance", "acct", 6)
202                         },
203                         staticCmd: func() interface{} {
204                                 return btcjson.NewGetBalanceCmd(btcjson.String("acct"), btcjson.Int(6))
205                         },
206                         marshalled: `{"jsonrpc":"1.0","method":"getbalance","params":["acct",6],"id":1}`,
207                         unmarshalled: &btcjson.GetBalanceCmd{
208                                 Account: btcjson.String("acct"),
209                                 MinConf: btcjson.Int(6),
210                         },
211                 },
212                 {
213                         name: "getnewaddress",
214                         newCmd: func() (interface{}, error) {
215                                 return btcjson.NewCmd("getnewaddress")
216                         },
217                         staticCmd: func() interface{} {
218                                 return btcjson.NewGetNewAddressCmd(nil)
219                         },
220                         marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":[],"id":1}`,
221                         unmarshalled: &btcjson.GetNewAddressCmd{
222                                 Account: nil,
223                         },
224                 },
225                 {
226                         name: "getnewaddress optional",
227                         newCmd: func() (interface{}, error) {
228                                 return btcjson.NewCmd("getnewaddress", "acct")
229                         },
230                         staticCmd: func() interface{} {
231                                 return btcjson.NewGetNewAddressCmd(btcjson.String("acct"))
232                         },
233                         marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct"],"id":1}`,
234                         unmarshalled: &btcjson.GetNewAddressCmd{
235                                 Account: btcjson.String("acct"),
236                         },
237                 },
238                 {
239                         name: "getrawchangeaddress",
240                         newCmd: func() (interface{}, error) {
241                                 return btcjson.NewCmd("getrawchangeaddress")
242                         },
243                         staticCmd: func() interface{} {
244                                 return btcjson.NewGetRawChangeAddressCmd(nil)
245                         },
246                         marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":[],"id":1}`,
247                         unmarshalled: &btcjson.GetRawChangeAddressCmd{
248                                 Account: nil,
249                         },
250                 },
251                 {
252                         name: "getrawchangeaddress optional",
253                         newCmd: func() (interface{}, error) {
254                                 return btcjson.NewCmd("getrawchangeaddress", "acct")
255                         },
256                         staticCmd: func() interface{} {
257                                 return btcjson.NewGetRawChangeAddressCmd(btcjson.String("acct"))
258                         },
259                         marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":["acct"],"id":1}`,
260                         unmarshalled: &btcjson.GetRawChangeAddressCmd{
261                                 Account: btcjson.String("acct"),
262                         },
263                 },
264                 {
265                         name: "getreceivedbyaccount",
266                         newCmd: func() (interface{}, error) {
267                                 return btcjson.NewCmd("getreceivedbyaccount", "acct")
268                         },
269                         staticCmd: func() interface{} {
270                                 return btcjson.NewGetReceivedByAccountCmd("acct", nil)
271                         },
272                         marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaccount","params":["acct"],"id":1}`,
273                         unmarshalled: &btcjson.GetReceivedByAccountCmd{
274                                 Account: "acct",
275                                 MinConf: btcjson.Int(1),
276                         },
277                 },
278                 {
279                         name: "getreceivedbyaccount optional",
280                         newCmd: func() (interface{}, error) {
281                                 return btcjson.NewCmd("getreceivedbyaccount", "acct", 6)
282                         },
283                         staticCmd: func() interface{} {
284                                 return btcjson.NewGetReceivedByAccountCmd("acct", btcjson.Int(6))
285                         },
286                         marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaccount","params":["acct",6],"id":1}`,
287                         unmarshalled: &btcjson.GetReceivedByAccountCmd{
288                                 Account: "acct",
289                                 MinConf: btcjson.Int(6),
290                         },
291                 },
292                 {
293                         name: "getreceivedbyaddress",
294                         newCmd: func() (interface{}, error) {
295                                 return btcjson.NewCmd("getreceivedbyaddress", "1Address")
296                         },
297                         staticCmd: func() interface{} {
298                                 return btcjson.NewGetReceivedByAddressCmd("1Address", nil)
299                         },
300                         marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaddress","params":["1Address"],"id":1}`,
301                         unmarshalled: &btcjson.GetReceivedByAddressCmd{
302                                 Address: "1Address",
303                                 MinConf: btcjson.Int(1),
304                         },
305                 },
306                 {
307                         name: "getreceivedbyaddress optional",
308                         newCmd: func() (interface{}, error) {
309                                 return btcjson.NewCmd("getreceivedbyaddress", "1Address", 6)
310                         },
311                         staticCmd: func() interface{} {
312                                 return btcjson.NewGetReceivedByAddressCmd("1Address", btcjson.Int(6))
313                         },
314                         marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaddress","params":["1Address",6],"id":1}`,
315                         unmarshalled: &btcjson.GetReceivedByAddressCmd{
316                                 Address: "1Address",
317                                 MinConf: btcjson.Int(6),
318                         },
319                 },
320                 {
321                         name: "gettransaction",
322                         newCmd: func() (interface{}, error) {
323                                 return btcjson.NewCmd("gettransaction", "123")
324                         },
325                         staticCmd: func() interface{} {
326                                 return btcjson.NewGetTransactionCmd("123", nil)
327                         },
328                         marshalled: `{"jsonrpc":"1.0","method":"gettransaction","params":["123"],"id":1}`,
329                         unmarshalled: &btcjson.GetTransactionCmd{
330                                 Txid:             "123",
331                                 IncludeWatchOnly: btcjson.Bool(false),
332                         },
333                 },
334                 {
335                         name: "gettransaction optional",
336                         newCmd: func() (interface{}, error) {
337                                 return btcjson.NewCmd("gettransaction", "123", true)
338                         },
339                         staticCmd: func() interface{} {
340                                 return btcjson.NewGetTransactionCmd("123", btcjson.Bool(true))
341                         },
342                         marshalled: `{"jsonrpc":"1.0","method":"gettransaction","params":["123",true],"id":1}`,
343                         unmarshalled: &btcjson.GetTransactionCmd{
344                                 Txid:             "123",
345                                 IncludeWatchOnly: btcjson.Bool(true),
346                         },
347                 },
348                 {
349                         name: "getwalletinfo",
350                         newCmd: func() (interface{}, error) {
351                                 return btcjson.NewCmd("getwalletinfo")
352                         },
353                         staticCmd: func() interface{} {
354                                 return btcjson.NewGetWalletInfoCmd()
355                         },
356                         marshalled:   `{"jsonrpc":"1.0","method":"getwalletinfo","params":[],"id":1}`,
357                         unmarshalled: &btcjson.GetWalletInfoCmd{},
358                 },
359                 {
360                         name: "importprivkey",
361                         newCmd: func() (interface{}, error) {
362                                 return btcjson.NewCmd("importprivkey", "abc")
363                         },
364                         staticCmd: func() interface{} {
365                                 return btcjson.NewImportPrivKeyCmd("abc", nil, nil)
366                         },
367                         marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc"],"id":1}`,
368                         unmarshalled: &btcjson.ImportPrivKeyCmd{
369                                 PrivKey: "abc",
370                                 Label:   nil,
371                                 Rescan:  btcjson.Bool(true),
372                         },
373                 },
374                 {
375                         name: "importprivkey optional1",
376                         newCmd: func() (interface{}, error) {
377                                 return btcjson.NewCmd("importprivkey", "abc", "label")
378                         },
379                         staticCmd: func() interface{} {
380                                 return btcjson.NewImportPrivKeyCmd("abc", btcjson.String("label"), nil)
381                         },
382                         marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label"],"id":1}`,
383                         unmarshalled: &btcjson.ImportPrivKeyCmd{
384                                 PrivKey: "abc",
385                                 Label:   btcjson.String("label"),
386                                 Rescan:  btcjson.Bool(true),
387                         },
388                 },
389                 {
390                         name: "importprivkey optional2",
391                         newCmd: func() (interface{}, error) {
392                                 return btcjson.NewCmd("importprivkey", "abc", "label", false)
393                         },
394                         staticCmd: func() interface{} {
395                                 return btcjson.NewImportPrivKeyCmd("abc", btcjson.String("label"), btcjson.Bool(false))
396                         },
397                         marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label",false],"id":1}`,
398                         unmarshalled: &btcjson.ImportPrivKeyCmd{
399                                 PrivKey: "abc",
400                                 Label:   btcjson.String("label"),
401                                 Rescan:  btcjson.Bool(false),
402                         },
403                 },
404                 {
405                         name: "keypoolrefill",
406                         newCmd: func() (interface{}, error) {
407                                 return btcjson.NewCmd("keypoolrefill")
408                         },
409                         staticCmd: func() interface{} {
410                                 return btcjson.NewKeyPoolRefillCmd(nil)
411                         },
412                         marshalled: `{"jsonrpc":"1.0","method":"keypoolrefill","params":[],"id":1}`,
413                         unmarshalled: &btcjson.KeyPoolRefillCmd{
414                                 NewSize: btcjson.Uint(100),
415                         },
416                 },
417                 {
418                         name: "keypoolrefill optional",
419                         newCmd: func() (interface{}, error) {
420                                 return btcjson.NewCmd("keypoolrefill", 200)
421                         },
422                         staticCmd: func() interface{} {
423                                 return btcjson.NewKeyPoolRefillCmd(btcjson.Uint(200))
424                         },
425                         marshalled: `{"jsonrpc":"1.0","method":"keypoolrefill","params":[200],"id":1}`,
426                         unmarshalled: &btcjson.KeyPoolRefillCmd{
427                                 NewSize: btcjson.Uint(200),
428                         },
429                 },
430                 {
431                         name: "listaccounts",
432                         newCmd: func() (interface{}, error) {
433                                 return btcjson.NewCmd("listaccounts")
434                         },
435                         staticCmd: func() interface{} {
436                                 return btcjson.NewListAccountsCmd(nil)
437                         },
438                         marshalled: `{"jsonrpc":"1.0","method":"listaccounts","params":[],"id":1}`,
439                         unmarshalled: &btcjson.ListAccountsCmd{
440                                 MinConf: btcjson.Int(1),
441                         },
442                 },
443                 {
444                         name: "listaccounts optional",
445                         newCmd: func() (interface{}, error) {
446                                 return btcjson.NewCmd("listaccounts", 6)
447                         },
448                         staticCmd: func() interface{} {
449                                 return btcjson.NewListAccountsCmd(btcjson.Int(6))
450                         },
451                         marshalled: `{"jsonrpc":"1.0","method":"listaccounts","params":[6],"id":1}`,
452                         unmarshalled: &btcjson.ListAccountsCmd{
453                                 MinConf: btcjson.Int(6),
454                         },
455                 },
456                 {
457                         name: "listaddressgroupings",
458                         newCmd: func() (interface{}, error) {
459                                 return btcjson.NewCmd("listaddressgroupings")
460                         },
461                         staticCmd: func() interface{} {
462                                 return btcjson.NewListAddressGroupingsCmd()
463                         },
464                         marshalled:   `{"jsonrpc":"1.0","method":"listaddressgroupings","params":[],"id":1}`,
465                         unmarshalled: &btcjson.ListAddressGroupingsCmd{},
466                 },
467                 {
468                         name: "listlockunspent",
469                         newCmd: func() (interface{}, error) {
470                                 return btcjson.NewCmd("listlockunspent")
471                         },
472                         staticCmd: func() interface{} {
473                                 return btcjson.NewListLockUnspentCmd()
474                         },
475                         marshalled:   `{"jsonrpc":"1.0","method":"listlockunspent","params":[],"id":1}`,
476                         unmarshalled: &btcjson.ListLockUnspentCmd{},
477                 },
478                 {
479                         name: "listreceivedbyaccount",
480                         newCmd: func() (interface{}, error) {
481                                 return btcjson.NewCmd("listreceivedbyaccount")
482                         },
483                         staticCmd: func() interface{} {
484                                 return btcjson.NewListReceivedByAccountCmd(nil, nil, nil)
485                         },
486                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaccount","params":[],"id":1}`,
487                         unmarshalled: &btcjson.ListReceivedByAccountCmd{
488                                 MinConf:          btcjson.Int(1),
489                                 IncludeEmpty:     btcjson.Bool(false),
490                                 IncludeWatchOnly: btcjson.Bool(false),
491                         },
492                 },
493                 {
494                         name: "listreceivedbyaccount optional1",
495                         newCmd: func() (interface{}, error) {
496                                 return btcjson.NewCmd("listreceivedbyaccount", 6)
497                         },
498                         staticCmd: func() interface{} {
499                                 return btcjson.NewListReceivedByAccountCmd(btcjson.Int(6), nil, nil)
500                         },
501                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaccount","params":[6],"id":1}`,
502                         unmarshalled: &btcjson.ListReceivedByAccountCmd{
503                                 MinConf:          btcjson.Int(6),
504                                 IncludeEmpty:     btcjson.Bool(false),
505                                 IncludeWatchOnly: btcjson.Bool(false),
506                         },
507                 },
508                 {
509                         name: "listreceivedbyaccount optional2",
510                         newCmd: func() (interface{}, error) {
511                                 return btcjson.NewCmd("listreceivedbyaccount", 6, true)
512                         },
513                         staticCmd: func() interface{} {
514                                 return btcjson.NewListReceivedByAccountCmd(btcjson.Int(6), btcjson.Bool(true), nil)
515                         },
516                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaccount","params":[6,true],"id":1}`,
517                         unmarshalled: &btcjson.ListReceivedByAccountCmd{
518                                 MinConf:          btcjson.Int(6),
519                                 IncludeEmpty:     btcjson.Bool(true),
520                                 IncludeWatchOnly: btcjson.Bool(false),
521                         },
522                 },
523                 {
524                         name: "listreceivedbyaccount optional3",
525                         newCmd: func() (interface{}, error) {
526                                 return btcjson.NewCmd("listreceivedbyaccount", 6, true, false)
527                         },
528                         staticCmd: func() interface{} {
529                                 return btcjson.NewListReceivedByAccountCmd(btcjson.Int(6), btcjson.Bool(true), btcjson.Bool(false))
530                         },
531                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaccount","params":[6,true,false],"id":1}`,
532                         unmarshalled: &btcjson.ListReceivedByAccountCmd{
533                                 MinConf:          btcjson.Int(6),
534                                 IncludeEmpty:     btcjson.Bool(true),
535                                 IncludeWatchOnly: btcjson.Bool(false),
536                         },
537                 },
538                 {
539                         name: "listreceivedbyaddress",
540                         newCmd: func() (interface{}, error) {
541                                 return btcjson.NewCmd("listreceivedbyaddress")
542                         },
543                         staticCmd: func() interface{} {
544                                 return btcjson.NewListReceivedByAddressCmd(nil, nil, nil)
545                         },
546                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaddress","params":[],"id":1}`,
547                         unmarshalled: &btcjson.ListReceivedByAddressCmd{
548                                 MinConf:          btcjson.Int(1),
549                                 IncludeEmpty:     btcjson.Bool(false),
550                                 IncludeWatchOnly: btcjson.Bool(false),
551                         },
552                 },
553                 {
554                         name: "listreceivedbyaddress optional1",
555                         newCmd: func() (interface{}, error) {
556                                 return btcjson.NewCmd("listreceivedbyaddress", 6)
557                         },
558                         staticCmd: func() interface{} {
559                                 return btcjson.NewListReceivedByAddressCmd(btcjson.Int(6), nil, nil)
560                         },
561                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaddress","params":[6],"id":1}`,
562                         unmarshalled: &btcjson.ListReceivedByAddressCmd{
563                                 MinConf:          btcjson.Int(6),
564                                 IncludeEmpty:     btcjson.Bool(false),
565                                 IncludeWatchOnly: btcjson.Bool(false),
566                         },
567                 },
568                 {
569                         name: "listreceivedbyaddress optional2",
570                         newCmd: func() (interface{}, error) {
571                                 return btcjson.NewCmd("listreceivedbyaddress", 6, true)
572                         },
573                         staticCmd: func() interface{} {
574                                 return btcjson.NewListReceivedByAddressCmd(btcjson.Int(6), btcjson.Bool(true), nil)
575                         },
576                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaddress","params":[6,true],"id":1}`,
577                         unmarshalled: &btcjson.ListReceivedByAddressCmd{
578                                 MinConf:          btcjson.Int(6),
579                                 IncludeEmpty:     btcjson.Bool(true),
580                                 IncludeWatchOnly: btcjson.Bool(false),
581                         },
582                 },
583                 {
584                         name: "listreceivedbyaddress optional3",
585                         newCmd: func() (interface{}, error) {
586                                 return btcjson.NewCmd("listreceivedbyaddress", 6, true, false)
587                         },
588                         staticCmd: func() interface{} {
589                                 return btcjson.NewListReceivedByAddressCmd(btcjson.Int(6), btcjson.Bool(true), btcjson.Bool(false))
590                         },
591                         marshalled: `{"jsonrpc":"1.0","method":"listreceivedbyaddress","params":[6,true,false],"id":1}`,
592                         unmarshalled: &btcjson.ListReceivedByAddressCmd{
593                                 MinConf:          btcjson.Int(6),
594                                 IncludeEmpty:     btcjson.Bool(true),
595                                 IncludeWatchOnly: btcjson.Bool(false),
596                         },
597                 },
598                 {
599                         name: "listsinceblock",
600                         newCmd: func() (interface{}, error) {
601                                 return btcjson.NewCmd("listsinceblock")
602                         },
603                         staticCmd: func() interface{} {
604                                 return btcjson.NewListSinceBlockCmd(nil, nil, nil)
605                         },
606                         marshalled: `{"jsonrpc":"1.0","method":"listsinceblock","params":[],"id":1}`,
607                         unmarshalled: &btcjson.ListSinceBlockCmd{
608                                 BlockHash:           nil,
609                                 TargetConfirmations: btcjson.Int(1),
610                                 IncludeWatchOnly:    btcjson.Bool(false),
611                         },
612                 },
613                 {
614                         name: "listsinceblock optional1",
615                         newCmd: func() (interface{}, error) {
616                                 return btcjson.NewCmd("listsinceblock", "123")
617                         },
618                         staticCmd: func() interface{} {
619                                 return btcjson.NewListSinceBlockCmd(btcjson.String("123"), nil, nil)
620                         },
621                         marshalled: `{"jsonrpc":"1.0","method":"listsinceblock","params":["123"],"id":1}`,
622                         unmarshalled: &btcjson.ListSinceBlockCmd{
623                                 BlockHash:           btcjson.String("123"),
624                                 TargetConfirmations: btcjson.Int(1),
625                                 IncludeWatchOnly:    btcjson.Bool(false),
626                         },
627                 },
628                 {
629                         name: "listsinceblock optional2",
630                         newCmd: func() (interface{}, error) {
631                                 return btcjson.NewCmd("listsinceblock", "123", 6)
632                         },
633                         staticCmd: func() interface{} {
634                                 return btcjson.NewListSinceBlockCmd(btcjson.String("123"), btcjson.Int(6), nil)
635                         },
636                         marshalled: `{"jsonrpc":"1.0","method":"listsinceblock","params":["123",6],"id":1}`,
637                         unmarshalled: &btcjson.ListSinceBlockCmd{
638                                 BlockHash:           btcjson.String("123"),
639                                 TargetConfirmations: btcjson.Int(6),
640                                 IncludeWatchOnly:    btcjson.Bool(false),
641                         },
642                 },
643                 {
644                         name: "listsinceblock optional3",
645                         newCmd: func() (interface{}, error) {
646                                 return btcjson.NewCmd("listsinceblock", "123", 6, true)
647                         },
648                         staticCmd: func() interface{} {
649                                 return btcjson.NewListSinceBlockCmd(btcjson.String("123"), btcjson.Int(6), btcjson.Bool(true))
650                         },
651                         marshalled: `{"jsonrpc":"1.0","method":"listsinceblock","params":["123",6,true],"id":1}`,
652                         unmarshalled: &btcjson.ListSinceBlockCmd{
653                                 BlockHash:           btcjson.String("123"),
654                                 TargetConfirmations: btcjson.Int(6),
655                                 IncludeWatchOnly:    btcjson.Bool(true),
656                         },
657                 },
658                 {
659                         name: "listtransactions",
660                         newCmd: func() (interface{}, error) {
661                                 return btcjson.NewCmd("listtransactions")
662                         },
663                         staticCmd: func() interface{} {
664                                 return btcjson.NewListTransactionsCmd(nil, nil, nil, nil)
665                         },
666                         marshalled: `{"jsonrpc":"1.0","method":"listtransactions","params":[],"id":1}`,
667                         unmarshalled: &btcjson.ListTransactionsCmd{
668                                 Account:          nil,
669                                 Count:            btcjson.Int(10),
670                                 From:             btcjson.Int(0),
671                                 IncludeWatchOnly: btcjson.Bool(false),
672                         },
673                 },
674                 {
675                         name: "listtransactions optional1",
676                         newCmd: func() (interface{}, error) {
677                                 return btcjson.NewCmd("listtransactions", "acct")
678                         },
679                         staticCmd: func() interface{} {
680                                 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), nil, nil, nil)
681                         },
682                         marshalled: `{"jsonrpc":"1.0","method":"listtransactions","params":["acct"],"id":1}`,
683                         unmarshalled: &btcjson.ListTransactionsCmd{
684                                 Account:          btcjson.String("acct"),
685                                 Count:            btcjson.Int(10),
686                                 From:             btcjson.Int(0),
687                                 IncludeWatchOnly: btcjson.Bool(false),
688                         },
689                 },
690                 {
691                         name: "listtransactions optional2",
692                         newCmd: func() (interface{}, error) {
693                                 return btcjson.NewCmd("listtransactions", "acct", 20)
694                         },
695                         staticCmd: func() interface{} {
696                                 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), btcjson.Int(20), nil, nil)
697                         },
698                         marshalled: `{"jsonrpc":"1.0","method":"listtransactions","params":["acct",20],"id":1}`,
699                         unmarshalled: &btcjson.ListTransactionsCmd{
700                                 Account:          btcjson.String("acct"),
701                                 Count:            btcjson.Int(20),
702                                 From:             btcjson.Int(0),
703                                 IncludeWatchOnly: btcjson.Bool(false),
704                         },
705                 },
706                 {
707                         name: "listtransactions optional3",
708                         newCmd: func() (interface{}, error) {
709                                 return btcjson.NewCmd("listtransactions", "acct", 20, 1)
710                         },
711                         staticCmd: func() interface{} {
712                                 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), btcjson.Int(20),
713                                         btcjson.Int(1), nil)
714                         },
715                         marshalled: `{"jsonrpc":"1.0","method":"listtransactions","params":["acct",20,1],"id":1}`,
716                         unmarshalled: &btcjson.ListTransactionsCmd{
717                                 Account:          btcjson.String("acct"),
718                                 Count:            btcjson.Int(20),
719                                 From:             btcjson.Int(1),
720                                 IncludeWatchOnly: btcjson.Bool(false),
721                         },
722                 },
723                 {
724                         name: "listtransactions optional4",
725                         newCmd: func() (interface{}, error) {
726                                 return btcjson.NewCmd("listtransactions", "acct", 20, 1, true)
727                         },
728                         staticCmd: func() interface{} {
729                                 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), btcjson.Int(20),
730                                         btcjson.Int(1), btcjson.Bool(true))
731                         },
732                         marshalled: `{"jsonrpc":"1.0","method":"listtransactions","params":["acct",20,1,true],"id":1}`,
733                         unmarshalled: &btcjson.ListTransactionsCmd{
734                                 Account:          btcjson.String("acct"),
735                                 Count:            btcjson.Int(20),
736                                 From:             btcjson.Int(1),
737                                 IncludeWatchOnly: btcjson.Bool(true),
738                         },
739                 },
740                 {
741                         name: "listunspent",
742                         newCmd: func() (interface{}, error) {
743                                 return btcjson.NewCmd("listunspent")
744                         },
745                         staticCmd: func() interface{} {
746                                 return btcjson.NewListUnspentCmd(nil, nil, nil)
747                         },
748                         marshalled: `{"jsonrpc":"1.0","method":"listunspent","params":[],"id":1}`,
749                         unmarshalled: &btcjson.ListUnspentCmd{
750                                 MinConf:   btcjson.Int(1),
751                                 MaxConf:   btcjson.Int(9999999),
752                                 Addresses: nil,
753                         },
754                 },
755                 {
756                         name: "listunspent optional1",
757                         newCmd: func() (interface{}, error) {
758                                 return btcjson.NewCmd("listunspent", 6)
759                         },
760                         staticCmd: func() interface{} {
761                                 return btcjson.NewListUnspentCmd(btcjson.Int(6), nil, nil)
762                         },
763                         marshalled: `{"jsonrpc":"1.0","method":"listunspent","params":[6],"id":1}`,
764                         unmarshalled: &btcjson.ListUnspentCmd{
765                                 MinConf:   btcjson.Int(6),
766                                 MaxConf:   btcjson.Int(9999999),
767                                 Addresses: nil,
768                         },
769                 },
770                 {
771                         name: "listunspent optional2",
772                         newCmd: func() (interface{}, error) {
773                                 return btcjson.NewCmd("listunspent", 6, 100)
774                         },
775                         staticCmd: func() interface{} {
776                                 return btcjson.NewListUnspentCmd(btcjson.Int(6), btcjson.Int(100), nil)
777                         },
778                         marshalled: `{"jsonrpc":"1.0","method":"listunspent","params":[6,100],"id":1}`,
779                         unmarshalled: &btcjson.ListUnspentCmd{
780                                 MinConf:   btcjson.Int(6),
781                                 MaxConf:   btcjson.Int(100),
782                                 Addresses: nil,
783                         },
784                 },
785                 {
786                         name: "listunspent optional3",
787                         newCmd: func() (interface{}, error) {
788                                 return btcjson.NewCmd("listunspent", 6, 100, []string{"1Address", "1Address2"})
789                         },
790                         staticCmd: func() interface{} {
791                                 return btcjson.NewListUnspentCmd(btcjson.Int(6), btcjson.Int(100),
792                                         &[]string{"1Address", "1Address2"})
793                         },
794                         marshalled: `{"jsonrpc":"1.0","method":"listunspent","params":[6,100,["1Address","1Address2"]],"id":1}`,
795                         unmarshalled: &btcjson.ListUnspentCmd{
796                                 MinConf:   btcjson.Int(6),
797                                 MaxConf:   btcjson.Int(100),
798                                 Addresses: &[]string{"1Address", "1Address2"},
799                         },
800                 },
801                 {
802                         name: "lockunspent",
803                         newCmd: func() (interface{}, error) {
804                                 return btcjson.NewCmd("lockunspent", true, `[{"txid":"123","vout":1}]`)
805                         },
806                         staticCmd: func() interface{} {
807                                 txInputs := []btcjson.TransactionInput{
808                                         {Txid: "123", Vout: 1},
809                                 }
810                                 return btcjson.NewLockUnspentCmd(true, txInputs)
811                         },
812                         marshalled: `{"jsonrpc":"1.0","method":"lockunspent","params":[true,[{"txid":"123","vout":1}]],"id":1}`,
813                         unmarshalled: &btcjson.LockUnspentCmd{
814                                 Unlock: true,
815                                 Transactions: []btcjson.TransactionInput{
816                                         {Txid: "123", Vout: 1},
817                                 },
818                         },
819                 },
820                 {
821                         name: "move",
822                         newCmd: func() (interface{}, error) {
823                                 return btcjson.NewCmd("move", "from", "to", 0.5)
824                         },
825                         staticCmd: func() interface{} {
826                                 return btcjson.NewMoveCmd("from", "to", 0.5, nil, nil)
827                         },
828                         marshalled: `{"jsonrpc":"1.0","method":"move","params":["from","to",0.5],"id":1}`,
829                         unmarshalled: &btcjson.MoveCmd{
830                                 FromAccount: "from",
831                                 ToAccount:   "to",
832                                 Amount:      0.5,
833                                 MinConf:     btcjson.Int(1),
834                                 Comment:     nil,
835                         },
836                 },
837                 {
838                         name: "move optional1",
839                         newCmd: func() (interface{}, error) {
840                                 return btcjson.NewCmd("move", "from", "to", 0.5, 6)
841                         },
842                         staticCmd: func() interface{} {
843                                 return btcjson.NewMoveCmd("from", "to", 0.5, btcjson.Int(6), nil)
844                         },
845                         marshalled: `{"jsonrpc":"1.0","method":"move","params":["from","to",0.5,6],"id":1}`,
846                         unmarshalled: &btcjson.MoveCmd{
847                                 FromAccount: "from",
848                                 ToAccount:   "to",
849                                 Amount:      0.5,
850                                 MinConf:     btcjson.Int(6),
851                                 Comment:     nil,
852                         },
853                 },
854                 {
855                         name: "move optional2",
856                         newCmd: func() (interface{}, error) {
857                                 return btcjson.NewCmd("move", "from", "to", 0.5, 6, "comment")
858                         },
859                         staticCmd: func() interface{} {
860                                 return btcjson.NewMoveCmd("from", "to", 0.5, btcjson.Int(6), btcjson.String("comment"))
861                         },
862                         marshalled: `{"jsonrpc":"1.0","method":"move","params":["from","to",0.5,6,"comment"],"id":1}`,
863                         unmarshalled: &btcjson.MoveCmd{
864                                 FromAccount: "from",
865                                 ToAccount:   "to",
866                                 Amount:      0.5,
867                                 MinConf:     btcjson.Int(6),
868                                 Comment:     btcjson.String("comment"),
869                         },
870                 },
871                 {
872                         name: "sendfrom",
873                         newCmd: func() (interface{}, error) {
874                                 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5)
875                         },
876                         staticCmd: func() interface{} {
877                                 return btcjson.NewSendFromCmd("from", "1Address", 0.5, nil, nil, nil)
878                         },
879                         marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5],"id":1}`,
880                         unmarshalled: &btcjson.SendFromCmd{
881                                 FromAccount: "from",
882                                 ToAddress:   "1Address",
883                                 Amount:      0.5,
884                                 MinConf:     btcjson.Int(1),
885                                 Comment:     nil,
886                                 CommentTo:   nil,
887                         },
888                 },
889                 {
890                         name: "sendfrom optional1",
891                         newCmd: func() (interface{}, error) {
892                                 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5, 6)
893                         },
894                         staticCmd: func() interface{} {
895                                 return btcjson.NewSendFromCmd("from", "1Address", 0.5, btcjson.Int(6), nil, nil)
896                         },
897                         marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5,6],"id":1}`,
898                         unmarshalled: &btcjson.SendFromCmd{
899                                 FromAccount: "from",
900                                 ToAddress:   "1Address",
901                                 Amount:      0.5,
902                                 MinConf:     btcjson.Int(6),
903                                 Comment:     nil,
904                                 CommentTo:   nil,
905                         },
906                 },
907                 {
908                         name: "sendfrom optional2",
909                         newCmd: func() (interface{}, error) {
910                                 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5, 6, "comment")
911                         },
912                         staticCmd: func() interface{} {
913                                 return btcjson.NewSendFromCmd("from", "1Address", 0.5, btcjson.Int(6),
914                                         btcjson.String("comment"), nil)
915                         },
916                         marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5,6,"comment"],"id":1}`,
917                         unmarshalled: &btcjson.SendFromCmd{
918                                 FromAccount: "from",
919                                 ToAddress:   "1Address",
920                                 Amount:      0.5,
921                                 MinConf:     btcjson.Int(6),
922                                 Comment:     btcjson.String("comment"),
923                                 CommentTo:   nil,
924                         },
925                 },
926                 {
927                         name: "sendfrom optional3",
928                         newCmd: func() (interface{}, error) {
929                                 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5, 6, "comment", "commentto")
930                         },
931                         staticCmd: func() interface{} {
932                                 return btcjson.NewSendFromCmd("from", "1Address", 0.5, btcjson.Int(6),
933                                         btcjson.String("comment"), btcjson.String("commentto"))
934                         },
935                         marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5,6,"comment","commentto"],"id":1}`,
936                         unmarshalled: &btcjson.SendFromCmd{
937                                 FromAccount: "from",
938                                 ToAddress:   "1Address",
939                                 Amount:      0.5,
940                                 MinConf:     btcjson.Int(6),
941                                 Comment:     btcjson.String("comment"),
942                                 CommentTo:   btcjson.String("commentto"),
943                         },
944                 },
945                 {
946                         name: "sendmany",
947                         newCmd: func() (interface{}, error) {
948                                 return btcjson.NewCmd("sendmany", "from", `{"1Address":0.5}`)
949                         },
950                         staticCmd: func() interface{} {
951                                 amounts := map[string]float64{"1Address": 0.5}
952                                 return btcjson.NewSendManyCmd("from", amounts, nil, nil)
953                         },
954                         marshalled: `{"jsonrpc":"1.0","method":"sendmany","params":["from",{"1Address":0.5}],"id":1}`,
955                         unmarshalled: &btcjson.SendManyCmd{
956                                 FromAccount: "from",
957                                 Amounts:     map[string]float64{"1Address": 0.5},
958                                 MinConf:     btcjson.Int(1),
959                                 Comment:     nil,
960                         },
961                 },
962                 {
963                         name: "sendmany optional1",
964                         newCmd: func() (interface{}, error) {
965                                 return btcjson.NewCmd("sendmany", "from", `{"1Address":0.5}`, 6)
966                         },
967                         staticCmd: func() interface{} {
968                                 amounts := map[string]float64{"1Address": 0.5}
969                                 return btcjson.NewSendManyCmd("from", amounts, btcjson.Int(6), nil)
970                         },
971                         marshalled: `{"jsonrpc":"1.0","method":"sendmany","params":["from",{"1Address":0.5},6],"id":1}`,
972                         unmarshalled: &btcjson.SendManyCmd{
973                                 FromAccount: "from",
974                                 Amounts:     map[string]float64{"1Address": 0.5},
975                                 MinConf:     btcjson.Int(6),
976                                 Comment:     nil,
977                         },
978                 },
979                 {
980                         name: "sendmany optional2",
981                         newCmd: func() (interface{}, error) {
982                                 return btcjson.NewCmd("sendmany", "from", `{"1Address":0.5}`, 6, "comment")
983                         },
984                         staticCmd: func() interface{} {
985                                 amounts := map[string]float64{"1Address": 0.5}
986                                 return btcjson.NewSendManyCmd("from", amounts, btcjson.Int(6), btcjson.String("comment"))
987                         },
988                         marshalled: `{"jsonrpc":"1.0","method":"sendmany","params":["from",{"1Address":0.5},6,"comment"],"id":1}`,
989                         unmarshalled: &btcjson.SendManyCmd{
990                                 FromAccount: "from",
991                                 Amounts:     map[string]float64{"1Address": 0.5},
992                                 MinConf:     btcjson.Int(6),
993                                 Comment:     btcjson.String("comment"),
994                         },
995                 },
996                 {
997                         name: "sendtoaddress",
998                         newCmd: func() (interface{}, error) {
999                                 return btcjson.NewCmd("sendtoaddress", "1Address", 0.5)
1000                         },
1001                         staticCmd: func() interface{} {
1002                                 return btcjson.NewSendToAddressCmd("1Address", 0.5, nil, nil)
1003                         },
1004                         marshalled: `{"jsonrpc":"1.0","method":"sendtoaddress","params":["1Address",0.5],"id":1}`,
1005                         unmarshalled: &btcjson.SendToAddressCmd{
1006                                 Address:   "1Address",
1007                                 Amount:    0.5,
1008                                 Comment:   nil,
1009                                 CommentTo: nil,
1010                         },
1011                 },
1012                 {
1013                         name: "sendtoaddress optional1",
1014                         newCmd: func() (interface{}, error) {
1015                                 return btcjson.NewCmd("sendtoaddress", "1Address", 0.5, "comment", "commentto")
1016                         },
1017                         staticCmd: func() interface{} {
1018                                 return btcjson.NewSendToAddressCmd("1Address", 0.5, btcjson.String("comment"),
1019                                         btcjson.String("commentto"))
1020                         },
1021                         marshalled: `{"jsonrpc":"1.0","method":"sendtoaddress","params":["1Address",0.5,"comment","commentto"],"id":1}`,
1022                         unmarshalled: &btcjson.SendToAddressCmd{
1023                                 Address:   "1Address",
1024                                 Amount:    0.5,
1025                                 Comment:   btcjson.String("comment"),
1026                                 CommentTo: btcjson.String("commentto"),
1027                         },
1028                 },
1029                 {
1030                         name: "setaccount",
1031                         newCmd: func() (interface{}, error) {
1032                                 return btcjson.NewCmd("setaccount", "1Address", "acct")
1033                         },
1034                         staticCmd: func() interface{} {
1035                                 return btcjson.NewSetAccountCmd("1Address", "acct")
1036                         },
1037                         marshalled: `{"jsonrpc":"1.0","method":"setaccount","params":["1Address","acct"],"id":1}`,
1038                         unmarshalled: &btcjson.SetAccountCmd{
1039                                 Address: "1Address",
1040                                 Account: "acct",
1041                         },
1042                 },
1043                 {
1044                         name: "settxfee",
1045                         newCmd: func() (interface{}, error) {
1046                                 return btcjson.NewCmd("settxfee", 0.0001)
1047                         },
1048                         staticCmd: func() interface{} {
1049                                 return btcjson.NewSetTxFeeCmd(0.0001)
1050                         },
1051                         marshalled: `{"jsonrpc":"1.0","method":"settxfee","params":[0.0001],"id":1}`,
1052                         unmarshalled: &btcjson.SetTxFeeCmd{
1053                                 Amount: 0.0001,
1054                         },
1055                 },
1056                 {
1057                         name: "signmessage",
1058                         newCmd: func() (interface{}, error) {
1059                                 return btcjson.NewCmd("signmessage", "1Address", "message")
1060                         },
1061                         staticCmd: func() interface{} {
1062                                 return btcjson.NewSignMessageCmd("1Address", "message")
1063                         },
1064                         marshalled: `{"jsonrpc":"1.0","method":"signmessage","params":["1Address","message"],"id":1}`,
1065                         unmarshalled: &btcjson.SignMessageCmd{
1066                                 Address: "1Address",
1067                                 Message: "message",
1068                         },
1069                 },
1070                 {
1071                         name: "signrawtransaction",
1072                         newCmd: func() (interface{}, error) {
1073                                 return btcjson.NewCmd("signrawtransaction", "001122")
1074                         },
1075                         staticCmd: func() interface{} {
1076                                 return btcjson.NewSignRawTransactionCmd("001122", nil, nil, nil)
1077                         },
1078                         marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122"],"id":1}`,
1079                         unmarshalled: &btcjson.SignRawTransactionCmd{
1080                                 RawTx:    "001122",
1081                                 Inputs:   nil,
1082                                 PrivKeys: nil,
1083                                 Flags:    btcjson.String("ALL"),
1084                         },
1085                 },
1086                 {
1087                         name: "signrawtransaction optional1",
1088                         newCmd: func() (interface{}, error) {
1089                                 return btcjson.NewCmd("signrawtransaction", "001122", `[{"txid":"123","vout":1,"scriptPubKey":"00","redeemScript":"01"}]`)
1090                         },
1091                         staticCmd: func() interface{} {
1092                                 txInputs := []btcjson.RawTxInput{
1093                                         {
1094                                                 Txid:         "123",
1095                                                 Vout:         1,
1096                                                 ScriptPubKey: "00",
1097                                                 RedeemScript: "01",
1098                                         },
1099                                 }
1100
1101                                 return btcjson.NewSignRawTransactionCmd("001122", &txInputs, nil, nil)
1102                         },
1103                         marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122",[{"txid":"123","vout":1,"scriptPubKey":"00","redeemScript":"01"}]],"id":1}`,
1104                         unmarshalled: &btcjson.SignRawTransactionCmd{
1105                                 RawTx: "001122",
1106                                 Inputs: &[]btcjson.RawTxInput{
1107                                         {
1108                                                 Txid:         "123",
1109                                                 Vout:         1,
1110                                                 ScriptPubKey: "00",
1111                                                 RedeemScript: "01",
1112                                         },
1113                                 },
1114                                 PrivKeys: nil,
1115                                 Flags:    btcjson.String("ALL"),
1116                         },
1117                 },
1118                 {
1119                         name: "signrawtransaction optional2",
1120                         newCmd: func() (interface{}, error) {
1121                                 return btcjson.NewCmd("signrawtransaction", "001122", `[]`, `["abc"]`)
1122                         },
1123                         staticCmd: func() interface{} {
1124                                 txInputs := []btcjson.RawTxInput{}
1125                                 privKeys := []string{"abc"}
1126                                 return btcjson.NewSignRawTransactionCmd("001122", &txInputs, &privKeys, nil)
1127                         },
1128                         marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122",[],["abc"]],"id":1}`,
1129                         unmarshalled: &btcjson.SignRawTransactionCmd{
1130                                 RawTx:    "001122",
1131                                 Inputs:   &[]btcjson.RawTxInput{},
1132                                 PrivKeys: &[]string{"abc"},
1133                                 Flags:    btcjson.String("ALL"),
1134                         },
1135                 },
1136                 {
1137                         name: "signrawtransaction optional3",
1138                         newCmd: func() (interface{}, error) {
1139                                 return btcjson.NewCmd("signrawtransaction", "001122", `[]`, `[]`, "ALL")
1140                         },
1141                         staticCmd: func() interface{} {
1142                                 txInputs := []btcjson.RawTxInput{}
1143                                 privKeys := []string{}
1144                                 return btcjson.NewSignRawTransactionCmd("001122", &txInputs, &privKeys,
1145                                         btcjson.String("ALL"))
1146                         },
1147                         marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122",[],[],"ALL"],"id":1}`,
1148                         unmarshalled: &btcjson.SignRawTransactionCmd{
1149                                 RawTx:    "001122",
1150                                 Inputs:   &[]btcjson.RawTxInput{},
1151                                 PrivKeys: &[]string{},
1152                                 Flags:    btcjson.String("ALL"),
1153                         },
1154                 },
1155                 {
1156                         name: "walletlock",
1157                         newCmd: func() (interface{}, error) {
1158                                 return btcjson.NewCmd("walletlock")
1159                         },
1160                         staticCmd: func() interface{} {
1161                                 return btcjson.NewWalletLockCmd()
1162                         },
1163                         marshalled:   `{"jsonrpc":"1.0","method":"walletlock","params":[],"id":1}`,
1164                         unmarshalled: &btcjson.WalletLockCmd{},
1165                 },
1166                 {
1167                         name: "walletpassphrase",
1168                         newCmd: func() (interface{}, error) {
1169                                 return btcjson.NewCmd("walletpassphrase", "pass", 60)
1170                         },
1171                         staticCmd: func() interface{} {
1172                                 return btcjson.NewWalletPassphraseCmd("pass", 60)
1173                         },
1174                         marshalled: `{"jsonrpc":"1.0","method":"walletpassphrase","params":["pass",60],"id":1}`,
1175                         unmarshalled: &btcjson.WalletPassphraseCmd{
1176                                 Passphrase: "pass",
1177                                 Timeout:    60,
1178                         },
1179                 },
1180                 {
1181                         name: "walletpassphrasechange",
1182                         newCmd: func() (interface{}, error) {
1183                                 return btcjson.NewCmd("walletpassphrasechange", "old", "new")
1184                         },
1185                         staticCmd: func() interface{} {
1186                                 return btcjson.NewWalletPassphraseChangeCmd("old", "new")
1187                         },
1188                         marshalled: `{"jsonrpc":"1.0","method":"walletpassphrasechange","params":["old","new"],"id":1}`,
1189                         unmarshalled: &btcjson.WalletPassphraseChangeCmd{
1190                                 OldPassphrase: "old",
1191                                 NewPassphrase: "new",
1192                         },
1193                 },
1194         }
1195
1196         t.Logf("Running %d tests", len(tests))
1197         for i, test := range tests {
1198                 // Marshal the command as created by the new static command
1199                 // creation function.
1200                 marshalled, err := btcjson.MarshalCmd(testID, test.staticCmd())
1201                 if err != nil {
1202                         t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
1203                                 test.name, err)
1204                         continue
1205                 }
1206
1207                 if !bytes.Equal(marshalled, []byte(test.marshalled)) {
1208                         t.Errorf("Test #%d (%s) unexpected marshalled data - "+
1209                                 "got %s, want %s", i, test.name, marshalled,
1210                                 test.marshalled)
1211                         continue
1212                 }
1213
1214                 // Ensure the command is created without error via the generic
1215                 // new command creation function.
1216                 cmd, err := test.newCmd()
1217                 if err != nil {
1218                         t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
1219                                 i, test.name, err)
1220                 }
1221
1222                 // Marshal the command as created by the generic new command
1223                 // creation function.
1224                 marshalled, err = btcjson.MarshalCmd(testID, cmd)
1225                 if err != nil {
1226                         t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
1227                                 test.name, err)
1228                         continue
1229                 }
1230
1231                 if !bytes.Equal(marshalled, []byte(test.marshalled)) {
1232                         t.Errorf("Test #%d (%s) unexpected marshalled data - "+
1233                                 "got %s, want %s", i, test.name, marshalled,
1234                                 test.marshalled)
1235                         continue
1236                 }
1237
1238                 var request btcjson.Request
1239                 if err := json.Unmarshal(marshalled, &request); err != nil {
1240                         t.Errorf("Test #%d (%s) unexpected error while "+
1241                                 "unmarshalling JSON-RPC request: %v", i,
1242                                 test.name, err)
1243                         continue
1244                 }
1245
1246                 cmd, err = btcjson.UnmarshalCmd(&request)
1247                 if err != nil {
1248                         t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
1249                                 test.name, err)
1250                         continue
1251                 }
1252
1253                 if !reflect.DeepEqual(cmd, test.unmarshalled) {
1254                         t.Errorf("Test #%d (%s) unexpected unmarshalled command "+
1255                                 "- got %s, want %s", i, test.name,
1256                                 fmt.Sprintf("(%T) %+[1]v", cmd),
1257                                 fmt.Sprintf("(%T) %+[1]v\n", test.unmarshalled))
1258                         continue
1259                 }
1260         }
1261 }