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.
14 "github.com/btcsuite/btcd/btcjson"
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) {
27 newCmd func() (interface{}, error)
28 staticCmd func() interface{}
30 unmarshalled interface{}
33 name: "addmultisigaddress",
34 newCmd: func() (interface{}, error) {
35 return btcjson.NewCmd("addmultisigaddress", 2, []string{"031234", "035678"})
37 staticCmd: func() interface{} {
38 keys := []string{"031234", "035678"}
39 return btcjson.NewAddMultisigAddressCmd(2, keys, nil)
41 marshalled: `{"jsonrpc":"1.0","method":"addmultisigaddress","params":[2,["031234","035678"]],"id":1}`,
42 unmarshalled: &btcjson.AddMultisigAddressCmd{
44 Keys: []string{"031234", "035678"},
49 name: "addmultisigaddress optional",
50 newCmd: func() (interface{}, error) {
51 return btcjson.NewCmd("addmultisigaddress", 2, []string{"031234", "035678"}, "test")
53 staticCmd: func() interface{} {
54 keys := []string{"031234", "035678"}
55 return btcjson.NewAddMultisigAddressCmd(2, keys, btcjson.String("test"))
57 marshalled: `{"jsonrpc":"1.0","method":"addmultisigaddress","params":[2,["031234","035678"],"test"],"id":1}`,
58 unmarshalled: &btcjson.AddMultisigAddressCmd{
60 Keys: []string{"031234", "035678"},
61 Account: btcjson.String("test"),
65 name: "createmultisig",
66 newCmd: func() (interface{}, error) {
67 return btcjson.NewCmd("createmultisig", 2, []string{"031234", "035678"})
69 staticCmd: func() interface{} {
70 keys := []string{"031234", "035678"}
71 return btcjson.NewCreateMultisigCmd(2, keys)
73 marshalled: `{"jsonrpc":"1.0","method":"createmultisig","params":[2,["031234","035678"]],"id":1}`,
74 unmarshalled: &btcjson.CreateMultisigCmd{
76 Keys: []string{"031234", "035678"},
81 newCmd: func() (interface{}, error) {
82 return btcjson.NewCmd("dumpprivkey", "1Address")
84 staticCmd: func() interface{} {
85 return btcjson.NewDumpPrivKeyCmd("1Address")
87 marshalled: `{"jsonrpc":"1.0","method":"dumpprivkey","params":["1Address"],"id":1}`,
88 unmarshalled: &btcjson.DumpPrivKeyCmd{
93 name: "encryptwallet",
94 newCmd: func() (interface{}, error) {
95 return btcjson.NewCmd("encryptwallet", "pass")
97 staticCmd: func() interface{} {
98 return btcjson.NewEncryptWalletCmd("pass")
100 marshalled: `{"jsonrpc":"1.0","method":"encryptwallet","params":["pass"],"id":1}`,
101 unmarshalled: &btcjson.EncryptWalletCmd{
107 newCmd: func() (interface{}, error) {
108 return btcjson.NewCmd("estimatefee", 6)
110 staticCmd: func() interface{} {
111 return btcjson.NewEstimateFeeCmd(6)
113 marshalled: `{"jsonrpc":"1.0","method":"estimatefee","params":[6],"id":1}`,
114 unmarshalled: &btcjson.EstimateFeeCmd{
119 name: "estimatepriority",
120 newCmd: func() (interface{}, error) {
121 return btcjson.NewCmd("estimatepriority", 6)
123 staticCmd: func() interface{} {
124 return btcjson.NewEstimatePriorityCmd(6)
126 marshalled: `{"jsonrpc":"1.0","method":"estimatepriority","params":[6],"id":1}`,
127 unmarshalled: &btcjson.EstimatePriorityCmd{
133 newCmd: func() (interface{}, error) {
134 return btcjson.NewCmd("getaccount", "1Address")
136 staticCmd: func() interface{} {
137 return btcjson.NewGetAccountCmd("1Address")
139 marshalled: `{"jsonrpc":"1.0","method":"getaccount","params":["1Address"],"id":1}`,
140 unmarshalled: &btcjson.GetAccountCmd{
145 name: "getaccountaddress",
146 newCmd: func() (interface{}, error) {
147 return btcjson.NewCmd("getaccountaddress", "acct")
149 staticCmd: func() interface{} {
150 return btcjson.NewGetAccountAddressCmd("acct")
152 marshalled: `{"jsonrpc":"1.0","method":"getaccountaddress","params":["acct"],"id":1}`,
153 unmarshalled: &btcjson.GetAccountAddressCmd{
158 name: "getaddressesbyaccount",
159 newCmd: func() (interface{}, error) {
160 return btcjson.NewCmd("getaddressesbyaccount", "acct")
162 staticCmd: func() interface{} {
163 return btcjson.NewGetAddressesByAccountCmd("acct")
165 marshalled: `{"jsonrpc":"1.0","method":"getaddressesbyaccount","params":["acct"],"id":1}`,
166 unmarshalled: &btcjson.GetAddressesByAccountCmd{
172 newCmd: func() (interface{}, error) {
173 return btcjson.NewCmd("getbalance")
175 staticCmd: func() interface{} {
176 return btcjson.NewGetBalanceCmd(nil, nil)
178 marshalled: `{"jsonrpc":"1.0","method":"getbalance","params":[],"id":1}`,
179 unmarshalled: &btcjson.GetBalanceCmd{
181 MinConf: btcjson.Int(1),
185 name: "getbalance optional1",
186 newCmd: func() (interface{}, error) {
187 return btcjson.NewCmd("getbalance", "acct")
189 staticCmd: func() interface{} {
190 return btcjson.NewGetBalanceCmd(btcjson.String("acct"), nil)
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),
199 name: "getbalance optional2",
200 newCmd: func() (interface{}, error) {
201 return btcjson.NewCmd("getbalance", "acct", 6)
203 staticCmd: func() interface{} {
204 return btcjson.NewGetBalanceCmd(btcjson.String("acct"), btcjson.Int(6))
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),
213 name: "getnewaddress",
214 newCmd: func() (interface{}, error) {
215 return btcjson.NewCmd("getnewaddress")
217 staticCmd: func() interface{} {
218 return btcjson.NewGetNewAddressCmd(nil)
220 marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":[],"id":1}`,
221 unmarshalled: &btcjson.GetNewAddressCmd{
226 name: "getnewaddress optional",
227 newCmd: func() (interface{}, error) {
228 return btcjson.NewCmd("getnewaddress", "acct")
230 staticCmd: func() interface{} {
231 return btcjson.NewGetNewAddressCmd(btcjson.String("acct"))
233 marshalled: `{"jsonrpc":"1.0","method":"getnewaddress","params":["acct"],"id":1}`,
234 unmarshalled: &btcjson.GetNewAddressCmd{
235 Account: btcjson.String("acct"),
239 name: "getrawchangeaddress",
240 newCmd: func() (interface{}, error) {
241 return btcjson.NewCmd("getrawchangeaddress")
243 staticCmd: func() interface{} {
244 return btcjson.NewGetRawChangeAddressCmd(nil)
246 marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":[],"id":1}`,
247 unmarshalled: &btcjson.GetRawChangeAddressCmd{
252 name: "getrawchangeaddress optional",
253 newCmd: func() (interface{}, error) {
254 return btcjson.NewCmd("getrawchangeaddress", "acct")
256 staticCmd: func() interface{} {
257 return btcjson.NewGetRawChangeAddressCmd(btcjson.String("acct"))
259 marshalled: `{"jsonrpc":"1.0","method":"getrawchangeaddress","params":["acct"],"id":1}`,
260 unmarshalled: &btcjson.GetRawChangeAddressCmd{
261 Account: btcjson.String("acct"),
265 name: "getreceivedbyaccount",
266 newCmd: func() (interface{}, error) {
267 return btcjson.NewCmd("getreceivedbyaccount", "acct")
269 staticCmd: func() interface{} {
270 return btcjson.NewGetReceivedByAccountCmd("acct", nil)
272 marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaccount","params":["acct"],"id":1}`,
273 unmarshalled: &btcjson.GetReceivedByAccountCmd{
275 MinConf: btcjson.Int(1),
279 name: "getreceivedbyaccount optional",
280 newCmd: func() (interface{}, error) {
281 return btcjson.NewCmd("getreceivedbyaccount", "acct", 6)
283 staticCmd: func() interface{} {
284 return btcjson.NewGetReceivedByAccountCmd("acct", btcjson.Int(6))
286 marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaccount","params":["acct",6],"id":1}`,
287 unmarshalled: &btcjson.GetReceivedByAccountCmd{
289 MinConf: btcjson.Int(6),
293 name: "getreceivedbyaddress",
294 newCmd: func() (interface{}, error) {
295 return btcjson.NewCmd("getreceivedbyaddress", "1Address")
297 staticCmd: func() interface{} {
298 return btcjson.NewGetReceivedByAddressCmd("1Address", nil)
300 marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaddress","params":["1Address"],"id":1}`,
301 unmarshalled: &btcjson.GetReceivedByAddressCmd{
303 MinConf: btcjson.Int(1),
307 name: "getreceivedbyaddress optional",
308 newCmd: func() (interface{}, error) {
309 return btcjson.NewCmd("getreceivedbyaddress", "1Address", 6)
311 staticCmd: func() interface{} {
312 return btcjson.NewGetReceivedByAddressCmd("1Address", btcjson.Int(6))
314 marshalled: `{"jsonrpc":"1.0","method":"getreceivedbyaddress","params":["1Address",6],"id":1}`,
315 unmarshalled: &btcjson.GetReceivedByAddressCmd{
317 MinConf: btcjson.Int(6),
321 name: "gettransaction",
322 newCmd: func() (interface{}, error) {
323 return btcjson.NewCmd("gettransaction", "123")
325 staticCmd: func() interface{} {
326 return btcjson.NewGetTransactionCmd("123", nil)
328 marshalled: `{"jsonrpc":"1.0","method":"gettransaction","params":["123"],"id":1}`,
329 unmarshalled: &btcjson.GetTransactionCmd{
331 IncludeWatchOnly: btcjson.Bool(false),
335 name: "gettransaction optional",
336 newCmd: func() (interface{}, error) {
337 return btcjson.NewCmd("gettransaction", "123", true)
339 staticCmd: func() interface{} {
340 return btcjson.NewGetTransactionCmd("123", btcjson.Bool(true))
342 marshalled: `{"jsonrpc":"1.0","method":"gettransaction","params":["123",true],"id":1}`,
343 unmarshalled: &btcjson.GetTransactionCmd{
345 IncludeWatchOnly: btcjson.Bool(true),
349 name: "getwalletinfo",
350 newCmd: func() (interface{}, error) {
351 return btcjson.NewCmd("getwalletinfo")
353 staticCmd: func() interface{} {
354 return btcjson.NewGetWalletInfoCmd()
356 marshalled: `{"jsonrpc":"1.0","method":"getwalletinfo","params":[],"id":1}`,
357 unmarshalled: &btcjson.GetWalletInfoCmd{},
360 name: "importprivkey",
361 newCmd: func() (interface{}, error) {
362 return btcjson.NewCmd("importprivkey", "abc")
364 staticCmd: func() interface{} {
365 return btcjson.NewImportPrivKeyCmd("abc", nil, nil)
367 marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc"],"id":1}`,
368 unmarshalled: &btcjson.ImportPrivKeyCmd{
371 Rescan: btcjson.Bool(true),
375 name: "importprivkey optional1",
376 newCmd: func() (interface{}, error) {
377 return btcjson.NewCmd("importprivkey", "abc", "label")
379 staticCmd: func() interface{} {
380 return btcjson.NewImportPrivKeyCmd("abc", btcjson.String("label"), nil)
382 marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label"],"id":1}`,
383 unmarshalled: &btcjson.ImportPrivKeyCmd{
385 Label: btcjson.String("label"),
386 Rescan: btcjson.Bool(true),
390 name: "importprivkey optional2",
391 newCmd: func() (interface{}, error) {
392 return btcjson.NewCmd("importprivkey", "abc", "label", false)
394 staticCmd: func() interface{} {
395 return btcjson.NewImportPrivKeyCmd("abc", btcjson.String("label"), btcjson.Bool(false))
397 marshalled: `{"jsonrpc":"1.0","method":"importprivkey","params":["abc","label",false],"id":1}`,
398 unmarshalled: &btcjson.ImportPrivKeyCmd{
400 Label: btcjson.String("label"),
401 Rescan: btcjson.Bool(false),
405 name: "keypoolrefill",
406 newCmd: func() (interface{}, error) {
407 return btcjson.NewCmd("keypoolrefill")
409 staticCmd: func() interface{} {
410 return btcjson.NewKeyPoolRefillCmd(nil)
412 marshalled: `{"jsonrpc":"1.0","method":"keypoolrefill","params":[],"id":1}`,
413 unmarshalled: &btcjson.KeyPoolRefillCmd{
414 NewSize: btcjson.Uint(100),
418 name: "keypoolrefill optional",
419 newCmd: func() (interface{}, error) {
420 return btcjson.NewCmd("keypoolrefill", 200)
422 staticCmd: func() interface{} {
423 return btcjson.NewKeyPoolRefillCmd(btcjson.Uint(200))
425 marshalled: `{"jsonrpc":"1.0","method":"keypoolrefill","params":[200],"id":1}`,
426 unmarshalled: &btcjson.KeyPoolRefillCmd{
427 NewSize: btcjson.Uint(200),
431 name: "listaccounts",
432 newCmd: func() (interface{}, error) {
433 return btcjson.NewCmd("listaccounts")
435 staticCmd: func() interface{} {
436 return btcjson.NewListAccountsCmd(nil)
438 marshalled: `{"jsonrpc":"1.0","method":"listaccounts","params":[],"id":1}`,
439 unmarshalled: &btcjson.ListAccountsCmd{
440 MinConf: btcjson.Int(1),
444 name: "listaccounts optional",
445 newCmd: func() (interface{}, error) {
446 return btcjson.NewCmd("listaccounts", 6)
448 staticCmd: func() interface{} {
449 return btcjson.NewListAccountsCmd(btcjson.Int(6))
451 marshalled: `{"jsonrpc":"1.0","method":"listaccounts","params":[6],"id":1}`,
452 unmarshalled: &btcjson.ListAccountsCmd{
453 MinConf: btcjson.Int(6),
457 name: "listaddressgroupings",
458 newCmd: func() (interface{}, error) {
459 return btcjson.NewCmd("listaddressgroupings")
461 staticCmd: func() interface{} {
462 return btcjson.NewListAddressGroupingsCmd()
464 marshalled: `{"jsonrpc":"1.0","method":"listaddressgroupings","params":[],"id":1}`,
465 unmarshalled: &btcjson.ListAddressGroupingsCmd{},
468 name: "listlockunspent",
469 newCmd: func() (interface{}, error) {
470 return btcjson.NewCmd("listlockunspent")
472 staticCmd: func() interface{} {
473 return btcjson.NewListLockUnspentCmd()
475 marshalled: `{"jsonrpc":"1.0","method":"listlockunspent","params":[],"id":1}`,
476 unmarshalled: &btcjson.ListLockUnspentCmd{},
479 name: "listreceivedbyaccount",
480 newCmd: func() (interface{}, error) {
481 return btcjson.NewCmd("listreceivedbyaccount")
483 staticCmd: func() interface{} {
484 return btcjson.NewListReceivedByAccountCmd(nil, nil, nil)
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),
494 name: "listreceivedbyaccount optional1",
495 newCmd: func() (interface{}, error) {
496 return btcjson.NewCmd("listreceivedbyaccount", 6)
498 staticCmd: func() interface{} {
499 return btcjson.NewListReceivedByAccountCmd(btcjson.Int(6), nil, nil)
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),
509 name: "listreceivedbyaccount optional2",
510 newCmd: func() (interface{}, error) {
511 return btcjson.NewCmd("listreceivedbyaccount", 6, true)
513 staticCmd: func() interface{} {
514 return btcjson.NewListReceivedByAccountCmd(btcjson.Int(6), btcjson.Bool(true), nil)
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),
524 name: "listreceivedbyaccount optional3",
525 newCmd: func() (interface{}, error) {
526 return btcjson.NewCmd("listreceivedbyaccount", 6, true, false)
528 staticCmd: func() interface{} {
529 return btcjson.NewListReceivedByAccountCmd(btcjson.Int(6), btcjson.Bool(true), btcjson.Bool(false))
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),
539 name: "listreceivedbyaddress",
540 newCmd: func() (interface{}, error) {
541 return btcjson.NewCmd("listreceivedbyaddress")
543 staticCmd: func() interface{} {
544 return btcjson.NewListReceivedByAddressCmd(nil, nil, nil)
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),
554 name: "listreceivedbyaddress optional1",
555 newCmd: func() (interface{}, error) {
556 return btcjson.NewCmd("listreceivedbyaddress", 6)
558 staticCmd: func() interface{} {
559 return btcjson.NewListReceivedByAddressCmd(btcjson.Int(6), nil, nil)
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),
569 name: "listreceivedbyaddress optional2",
570 newCmd: func() (interface{}, error) {
571 return btcjson.NewCmd("listreceivedbyaddress", 6, true)
573 staticCmd: func() interface{} {
574 return btcjson.NewListReceivedByAddressCmd(btcjson.Int(6), btcjson.Bool(true), nil)
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),
584 name: "listreceivedbyaddress optional3",
585 newCmd: func() (interface{}, error) {
586 return btcjson.NewCmd("listreceivedbyaddress", 6, true, false)
588 staticCmd: func() interface{} {
589 return btcjson.NewListReceivedByAddressCmd(btcjson.Int(6), btcjson.Bool(true), btcjson.Bool(false))
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),
599 name: "listsinceblock",
600 newCmd: func() (interface{}, error) {
601 return btcjson.NewCmd("listsinceblock")
603 staticCmd: func() interface{} {
604 return btcjson.NewListSinceBlockCmd(nil, nil, nil)
606 marshalled: `{"jsonrpc":"1.0","method":"listsinceblock","params":[],"id":1}`,
607 unmarshalled: &btcjson.ListSinceBlockCmd{
609 TargetConfirmations: btcjson.Int(1),
610 IncludeWatchOnly: btcjson.Bool(false),
614 name: "listsinceblock optional1",
615 newCmd: func() (interface{}, error) {
616 return btcjson.NewCmd("listsinceblock", "123")
618 staticCmd: func() interface{} {
619 return btcjson.NewListSinceBlockCmd(btcjson.String("123"), nil, nil)
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),
629 name: "listsinceblock optional2",
630 newCmd: func() (interface{}, error) {
631 return btcjson.NewCmd("listsinceblock", "123", 6)
633 staticCmd: func() interface{} {
634 return btcjson.NewListSinceBlockCmd(btcjson.String("123"), btcjson.Int(6), nil)
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),
644 name: "listsinceblock optional3",
645 newCmd: func() (interface{}, error) {
646 return btcjson.NewCmd("listsinceblock", "123", 6, true)
648 staticCmd: func() interface{} {
649 return btcjson.NewListSinceBlockCmd(btcjson.String("123"), btcjson.Int(6), btcjson.Bool(true))
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),
659 name: "listtransactions",
660 newCmd: func() (interface{}, error) {
661 return btcjson.NewCmd("listtransactions")
663 staticCmd: func() interface{} {
664 return btcjson.NewListTransactionsCmd(nil, nil, nil, nil)
666 marshalled: `{"jsonrpc":"1.0","method":"listtransactions","params":[],"id":1}`,
667 unmarshalled: &btcjson.ListTransactionsCmd{
669 Count: btcjson.Int(10),
670 From: btcjson.Int(0),
671 IncludeWatchOnly: btcjson.Bool(false),
675 name: "listtransactions optional1",
676 newCmd: func() (interface{}, error) {
677 return btcjson.NewCmd("listtransactions", "acct")
679 staticCmd: func() interface{} {
680 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), nil, nil, nil)
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),
691 name: "listtransactions optional2",
692 newCmd: func() (interface{}, error) {
693 return btcjson.NewCmd("listtransactions", "acct", 20)
695 staticCmd: func() interface{} {
696 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), btcjson.Int(20), nil, nil)
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),
707 name: "listtransactions optional3",
708 newCmd: func() (interface{}, error) {
709 return btcjson.NewCmd("listtransactions", "acct", 20, 1)
711 staticCmd: func() interface{} {
712 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), btcjson.Int(20),
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),
724 name: "listtransactions optional4",
725 newCmd: func() (interface{}, error) {
726 return btcjson.NewCmd("listtransactions", "acct", 20, 1, true)
728 staticCmd: func() interface{} {
729 return btcjson.NewListTransactionsCmd(btcjson.String("acct"), btcjson.Int(20),
730 btcjson.Int(1), btcjson.Bool(true))
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),
742 newCmd: func() (interface{}, error) {
743 return btcjson.NewCmd("listunspent")
745 staticCmd: func() interface{} {
746 return btcjson.NewListUnspentCmd(nil, nil, nil)
748 marshalled: `{"jsonrpc":"1.0","method":"listunspent","params":[],"id":1}`,
749 unmarshalled: &btcjson.ListUnspentCmd{
750 MinConf: btcjson.Int(1),
751 MaxConf: btcjson.Int(9999999),
756 name: "listunspent optional1",
757 newCmd: func() (interface{}, error) {
758 return btcjson.NewCmd("listunspent", 6)
760 staticCmd: func() interface{} {
761 return btcjson.NewListUnspentCmd(btcjson.Int(6), nil, nil)
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),
771 name: "listunspent optional2",
772 newCmd: func() (interface{}, error) {
773 return btcjson.NewCmd("listunspent", 6, 100)
775 staticCmd: func() interface{} {
776 return btcjson.NewListUnspentCmd(btcjson.Int(6), btcjson.Int(100), nil)
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),
786 name: "listunspent optional3",
787 newCmd: func() (interface{}, error) {
788 return btcjson.NewCmd("listunspent", 6, 100, []string{"1Address", "1Address2"})
790 staticCmd: func() interface{} {
791 return btcjson.NewListUnspentCmd(btcjson.Int(6), btcjson.Int(100),
792 &[]string{"1Address", "1Address2"})
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"},
803 newCmd: func() (interface{}, error) {
804 return btcjson.NewCmd("lockunspent", true, `[{"txid":"123","vout":1}]`)
806 staticCmd: func() interface{} {
807 txInputs := []btcjson.TransactionInput{
808 {Txid: "123", Vout: 1},
810 return btcjson.NewLockUnspentCmd(true, txInputs)
812 marshalled: `{"jsonrpc":"1.0","method":"lockunspent","params":[true,[{"txid":"123","vout":1}]],"id":1}`,
813 unmarshalled: &btcjson.LockUnspentCmd{
815 Transactions: []btcjson.TransactionInput{
816 {Txid: "123", Vout: 1},
822 newCmd: func() (interface{}, error) {
823 return btcjson.NewCmd("move", "from", "to", 0.5)
825 staticCmd: func() interface{} {
826 return btcjson.NewMoveCmd("from", "to", 0.5, nil, nil)
828 marshalled: `{"jsonrpc":"1.0","method":"move","params":["from","to",0.5],"id":1}`,
829 unmarshalled: &btcjson.MoveCmd{
833 MinConf: btcjson.Int(1),
838 name: "move optional1",
839 newCmd: func() (interface{}, error) {
840 return btcjson.NewCmd("move", "from", "to", 0.5, 6)
842 staticCmd: func() interface{} {
843 return btcjson.NewMoveCmd("from", "to", 0.5, btcjson.Int(6), nil)
845 marshalled: `{"jsonrpc":"1.0","method":"move","params":["from","to",0.5,6],"id":1}`,
846 unmarshalled: &btcjson.MoveCmd{
850 MinConf: btcjson.Int(6),
855 name: "move optional2",
856 newCmd: func() (interface{}, error) {
857 return btcjson.NewCmd("move", "from", "to", 0.5, 6, "comment")
859 staticCmd: func() interface{} {
860 return btcjson.NewMoveCmd("from", "to", 0.5, btcjson.Int(6), btcjson.String("comment"))
862 marshalled: `{"jsonrpc":"1.0","method":"move","params":["from","to",0.5,6,"comment"],"id":1}`,
863 unmarshalled: &btcjson.MoveCmd{
867 MinConf: btcjson.Int(6),
868 Comment: btcjson.String("comment"),
873 newCmd: func() (interface{}, error) {
874 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5)
876 staticCmd: func() interface{} {
877 return btcjson.NewSendFromCmd("from", "1Address", 0.5, nil, nil, nil)
879 marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5],"id":1}`,
880 unmarshalled: &btcjson.SendFromCmd{
882 ToAddress: "1Address",
884 MinConf: btcjson.Int(1),
890 name: "sendfrom optional1",
891 newCmd: func() (interface{}, error) {
892 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5, 6)
894 staticCmd: func() interface{} {
895 return btcjson.NewSendFromCmd("from", "1Address", 0.5, btcjson.Int(6), nil, nil)
897 marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5,6],"id":1}`,
898 unmarshalled: &btcjson.SendFromCmd{
900 ToAddress: "1Address",
902 MinConf: btcjson.Int(6),
908 name: "sendfrom optional2",
909 newCmd: func() (interface{}, error) {
910 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5, 6, "comment")
912 staticCmd: func() interface{} {
913 return btcjson.NewSendFromCmd("from", "1Address", 0.5, btcjson.Int(6),
914 btcjson.String("comment"), nil)
916 marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5,6,"comment"],"id":1}`,
917 unmarshalled: &btcjson.SendFromCmd{
919 ToAddress: "1Address",
921 MinConf: btcjson.Int(6),
922 Comment: btcjson.String("comment"),
927 name: "sendfrom optional3",
928 newCmd: func() (interface{}, error) {
929 return btcjson.NewCmd("sendfrom", "from", "1Address", 0.5, 6, "comment", "commentto")
931 staticCmd: func() interface{} {
932 return btcjson.NewSendFromCmd("from", "1Address", 0.5, btcjson.Int(6),
933 btcjson.String("comment"), btcjson.String("commentto"))
935 marshalled: `{"jsonrpc":"1.0","method":"sendfrom","params":["from","1Address",0.5,6,"comment","commentto"],"id":1}`,
936 unmarshalled: &btcjson.SendFromCmd{
938 ToAddress: "1Address",
940 MinConf: btcjson.Int(6),
941 Comment: btcjson.String("comment"),
942 CommentTo: btcjson.String("commentto"),
947 newCmd: func() (interface{}, error) {
948 return btcjson.NewCmd("sendmany", "from", `{"1Address":0.5}`)
950 staticCmd: func() interface{} {
951 amounts := map[string]float64{"1Address": 0.5}
952 return btcjson.NewSendManyCmd("from", amounts, nil, nil)
954 marshalled: `{"jsonrpc":"1.0","method":"sendmany","params":["from",{"1Address":0.5}],"id":1}`,
955 unmarshalled: &btcjson.SendManyCmd{
957 Amounts: map[string]float64{"1Address": 0.5},
958 MinConf: btcjson.Int(1),
963 name: "sendmany optional1",
964 newCmd: func() (interface{}, error) {
965 return btcjson.NewCmd("sendmany", "from", `{"1Address":0.5}`, 6)
967 staticCmd: func() interface{} {
968 amounts := map[string]float64{"1Address": 0.5}
969 return btcjson.NewSendManyCmd("from", amounts, btcjson.Int(6), nil)
971 marshalled: `{"jsonrpc":"1.0","method":"sendmany","params":["from",{"1Address":0.5},6],"id":1}`,
972 unmarshalled: &btcjson.SendManyCmd{
974 Amounts: map[string]float64{"1Address": 0.5},
975 MinConf: btcjson.Int(6),
980 name: "sendmany optional2",
981 newCmd: func() (interface{}, error) {
982 return btcjson.NewCmd("sendmany", "from", `{"1Address":0.5}`, 6, "comment")
984 staticCmd: func() interface{} {
985 amounts := map[string]float64{"1Address": 0.5}
986 return btcjson.NewSendManyCmd("from", amounts, btcjson.Int(6), btcjson.String("comment"))
988 marshalled: `{"jsonrpc":"1.0","method":"sendmany","params":["from",{"1Address":0.5},6,"comment"],"id":1}`,
989 unmarshalled: &btcjson.SendManyCmd{
991 Amounts: map[string]float64{"1Address": 0.5},
992 MinConf: btcjson.Int(6),
993 Comment: btcjson.String("comment"),
997 name: "sendtoaddress",
998 newCmd: func() (interface{}, error) {
999 return btcjson.NewCmd("sendtoaddress", "1Address", 0.5)
1001 staticCmd: func() interface{} {
1002 return btcjson.NewSendToAddressCmd("1Address", 0.5, nil, nil)
1004 marshalled: `{"jsonrpc":"1.0","method":"sendtoaddress","params":["1Address",0.5],"id":1}`,
1005 unmarshalled: &btcjson.SendToAddressCmd{
1006 Address: "1Address",
1013 name: "sendtoaddress optional1",
1014 newCmd: func() (interface{}, error) {
1015 return btcjson.NewCmd("sendtoaddress", "1Address", 0.5, "comment", "commentto")
1017 staticCmd: func() interface{} {
1018 return btcjson.NewSendToAddressCmd("1Address", 0.5, btcjson.String("comment"),
1019 btcjson.String("commentto"))
1021 marshalled: `{"jsonrpc":"1.0","method":"sendtoaddress","params":["1Address",0.5,"comment","commentto"],"id":1}`,
1022 unmarshalled: &btcjson.SendToAddressCmd{
1023 Address: "1Address",
1025 Comment: btcjson.String("comment"),
1026 CommentTo: btcjson.String("commentto"),
1031 newCmd: func() (interface{}, error) {
1032 return btcjson.NewCmd("setaccount", "1Address", "acct")
1034 staticCmd: func() interface{} {
1035 return btcjson.NewSetAccountCmd("1Address", "acct")
1037 marshalled: `{"jsonrpc":"1.0","method":"setaccount","params":["1Address","acct"],"id":1}`,
1038 unmarshalled: &btcjson.SetAccountCmd{
1039 Address: "1Address",
1045 newCmd: func() (interface{}, error) {
1046 return btcjson.NewCmd("settxfee", 0.0001)
1048 staticCmd: func() interface{} {
1049 return btcjson.NewSetTxFeeCmd(0.0001)
1051 marshalled: `{"jsonrpc":"1.0","method":"settxfee","params":[0.0001],"id":1}`,
1052 unmarshalled: &btcjson.SetTxFeeCmd{
1057 name: "signmessage",
1058 newCmd: func() (interface{}, error) {
1059 return btcjson.NewCmd("signmessage", "1Address", "message")
1061 staticCmd: func() interface{} {
1062 return btcjson.NewSignMessageCmd("1Address", "message")
1064 marshalled: `{"jsonrpc":"1.0","method":"signmessage","params":["1Address","message"],"id":1}`,
1065 unmarshalled: &btcjson.SignMessageCmd{
1066 Address: "1Address",
1071 name: "signrawtransaction",
1072 newCmd: func() (interface{}, error) {
1073 return btcjson.NewCmd("signrawtransaction", "001122")
1075 staticCmd: func() interface{} {
1076 return btcjson.NewSignRawTransactionCmd("001122", nil, nil, nil)
1078 marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122"],"id":1}`,
1079 unmarshalled: &btcjson.SignRawTransactionCmd{
1083 Flags: btcjson.String("ALL"),
1087 name: "signrawtransaction optional1",
1088 newCmd: func() (interface{}, error) {
1089 return btcjson.NewCmd("signrawtransaction", "001122", `[{"txid":"123","vout":1,"scriptPubKey":"00","redeemScript":"01"}]`)
1091 staticCmd: func() interface{} {
1092 txInputs := []btcjson.RawTxInput{
1101 return btcjson.NewSignRawTransactionCmd("001122", &txInputs, nil, nil)
1103 marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122",[{"txid":"123","vout":1,"scriptPubKey":"00","redeemScript":"01"}]],"id":1}`,
1104 unmarshalled: &btcjson.SignRawTransactionCmd{
1106 Inputs: &[]btcjson.RawTxInput{
1115 Flags: btcjson.String("ALL"),
1119 name: "signrawtransaction optional2",
1120 newCmd: func() (interface{}, error) {
1121 return btcjson.NewCmd("signrawtransaction", "001122", `[]`, `["abc"]`)
1123 staticCmd: func() interface{} {
1124 txInputs := []btcjson.RawTxInput{}
1125 privKeys := []string{"abc"}
1126 return btcjson.NewSignRawTransactionCmd("001122", &txInputs, &privKeys, nil)
1128 marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122",[],["abc"]],"id":1}`,
1129 unmarshalled: &btcjson.SignRawTransactionCmd{
1131 Inputs: &[]btcjson.RawTxInput{},
1132 PrivKeys: &[]string{"abc"},
1133 Flags: btcjson.String("ALL"),
1137 name: "signrawtransaction optional3",
1138 newCmd: func() (interface{}, error) {
1139 return btcjson.NewCmd("signrawtransaction", "001122", `[]`, `[]`, "ALL")
1141 staticCmd: func() interface{} {
1142 txInputs := []btcjson.RawTxInput{}
1143 privKeys := []string{}
1144 return btcjson.NewSignRawTransactionCmd("001122", &txInputs, &privKeys,
1145 btcjson.String("ALL"))
1147 marshalled: `{"jsonrpc":"1.0","method":"signrawtransaction","params":["001122",[],[],"ALL"],"id":1}`,
1148 unmarshalled: &btcjson.SignRawTransactionCmd{
1150 Inputs: &[]btcjson.RawTxInput{},
1151 PrivKeys: &[]string{},
1152 Flags: btcjson.String("ALL"),
1157 newCmd: func() (interface{}, error) {
1158 return btcjson.NewCmd("walletlock")
1160 staticCmd: func() interface{} {
1161 return btcjson.NewWalletLockCmd()
1163 marshalled: `{"jsonrpc":"1.0","method":"walletlock","params":[],"id":1}`,
1164 unmarshalled: &btcjson.WalletLockCmd{},
1167 name: "walletpassphrase",
1168 newCmd: func() (interface{}, error) {
1169 return btcjson.NewCmd("walletpassphrase", "pass", 60)
1171 staticCmd: func() interface{} {
1172 return btcjson.NewWalletPassphraseCmd("pass", 60)
1174 marshalled: `{"jsonrpc":"1.0","method":"walletpassphrase","params":["pass",60],"id":1}`,
1175 unmarshalled: &btcjson.WalletPassphraseCmd{
1181 name: "walletpassphrasechange",
1182 newCmd: func() (interface{}, error) {
1183 return btcjson.NewCmd("walletpassphrasechange", "old", "new")
1185 staticCmd: func() interface{} {
1186 return btcjson.NewWalletPassphraseChangeCmd("old", "new")
1188 marshalled: `{"jsonrpc":"1.0","method":"walletpassphrasechange","params":["old","new"],"id":1}`,
1189 unmarshalled: &btcjson.WalletPassphraseChangeCmd{
1190 OldPassphrase: "old",
1191 NewPassphrase: "new",
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())
1202 t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
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,
1214 // Ensure the command is created without error via the generic
1215 // new command creation function.
1216 cmd, err := test.newCmd()
1218 t.Errorf("Test #%d (%s) unexpected NewCmd error: %v ",
1222 // Marshal the command as created by the generic new command
1223 // creation function.
1224 marshalled, err = btcjson.MarshalCmd(testID, cmd)
1226 t.Errorf("MarshalCmd #%d (%s) unexpected error: %v", i,
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,
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,
1246 cmd, err = btcjson.UnmarshalCmd(&request)
1248 t.Errorf("UnmarshalCmd #%d (%s) unexpected error: %v", i,
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))