lbcd/jsoncmd_test.go

1697 lines
31 KiB
Go
Raw Normal View History

2014-01-09 06:49:06 +01:00
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
// this has to be in the real json subpackage so we can mock up structs
package btcjson
import (
"encoding/json"
"github.com/davecgh/go-spew/spew"
"reflect"
"strings"
"testing"
)
2014-01-03 23:50:17 +01:00
var testId = float64(1)
var jsoncmdtests = []struct {
name string
cmd string
f func() (Cmd, error)
result Cmd // after marshal and unmarshal
}{
{
name: "basic",
cmd: "addmultisigaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewAddMultisigAddressCmd(testId, 1,
[]string{"foo", "bar"})
},
result: &AddMultisigAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
NRequired: 1,
Keys: []string{"foo", "bar"},
Account: "",
},
},
{
name: "+ optional",
cmd: "addmultisigaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewAddMultisigAddressCmd(testId, 1,
[]string{"foo", "bar"}, "address")
},
result: &AddMultisigAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
NRequired: 1,
Keys: []string{"foo", "bar"},
Account: "address",
},
},
// TODO(oga) Too many arguments to newaddmultisigaddress
{
name: "basic add",
cmd: "addnode",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewAddNodeCmd(testId, "address",
"add")
},
result: &AddNodeCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Addr: "address",
SubCmd: "add",
},
},
{
name: "basic remove",
cmd: "addnode",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewAddNodeCmd(testId, "address",
"remove")
},
result: &AddNodeCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Addr: "address",
SubCmd: "remove",
},
},
{
name: "basic onetry",
cmd: "addnode",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewAddNodeCmd(testId, "address",
"onetry")
},
result: &AddNodeCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Addr: "address",
SubCmd: "onetry",
},
},
// TODO(oga) try invalid subcmds
{
name: "basic",
cmd: "backupwallet",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewBackupWalletCmd(testId, "destination")
},
result: &BackupWalletCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Destination: "destination",
},
},
{
name: "basic",
cmd: "createmultisig",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewCreateMultisigCmd(testId, 1,
[]string{"key1", "key2", "key3"})
},
result: &CreateMultisigCmd{
2014-01-03 23:50:17 +01:00
id: testId,
NRequired: 1,
Keys: []string{"key1", "key2", "key3"},
},
},
{
name: "basic",
cmd: "createrawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewCreateRawTransactionCmd(testId,
[]TransactionInput{
2014-02-04 22:13:24 +01:00
{Txid: "tx1", Vout: 1},
{Txid: "tx2", Vout: 3}},
map[string]int64{"bob": 1, "bill": 2})
},
result: &CreateRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Inputs: []TransactionInput{
2014-02-04 22:13:24 +01:00
{Txid: "tx1", Vout: 1},
{Txid: "tx2", Vout: 3},
},
Amounts: map[string]int64{
"bob": 1,
"bill": 2,
},
},
},
{
name: "basic",
cmd: "debuglevel",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewDebugLevelCmd(testId, "debug")
},
result: &DebugLevelCmd{
2014-01-03 23:50:17 +01:00
id: testId,
LevelSpec: "debug",
},
},
{
name: "basic",
cmd: "decoderawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewDecodeRawTransactionCmd(testId,
"thisisahexidecimaltransaction")
},
result: &DecodeRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
HexTx: "thisisahexidecimaltransaction",
},
},
2013-10-31 21:37:14 +01:00
{
name: "basic",
cmd: "decodescript",
2013-10-31 21:37:14 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewDecodeScriptCmd(testId,
2013-10-31 21:37:14 +01:00
"a bunch of hex")
},
result: &DecodeScriptCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-31 21:37:14 +01:00
HexScript: "a bunch of hex",
},
},
{
name: "basic",
cmd: "dumpprivkey",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewDumpPrivKeyCmd(testId,
"address")
},
result: &DumpPrivKeyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "address",
},
},
{
name: "basic",
cmd: "dumpwallet",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewDumpWalletCmd(testId,
"filename")
},
result: &DumpWalletCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Filename: "filename",
},
},
{
name: "basic",
cmd: "encryptwallet",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewEncryptWalletCmd(testId,
"passphrase")
},
result: &EncryptWalletCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Passphrase: "passphrase",
},
},
{
name: "basic",
cmd: "getaccount",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetAccountCmd(testId,
"address")
},
result: &GetAccountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "address",
},
},
{
name: "basic",
cmd: "getaccountaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetAccountAddressCmd(testId,
"account")
},
result: &GetAccountAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "account",
},
},
2013-10-25 19:23:28 +02:00
{
name: "basic true",
cmd: "getaddednodeinfo",
2013-10-25 19:23:28 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetAddedNodeInfoCmd(testId, true)
2013-10-25 19:23:28 +02:00
},
result: &GetAddedNodeInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 19:23:28 +02:00
Dns: true,
},
},
{
name: "basic false",
cmd: "getaddednodeinfo",
2013-10-25 19:23:28 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetAddedNodeInfoCmd(testId, false)
2013-10-25 19:23:28 +02:00
},
result: &GetAddedNodeInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 19:23:28 +02:00
Dns: false,
},
},
{
name: "basic withnode",
cmd: "getaddednodeinfo",
2013-10-25 19:23:28 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetAddedNodeInfoCmd(testId, true,
2013-10-25 19:23:28 +02:00
"thisisanode")
},
result: &GetAddedNodeInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 19:23:53 +02:00
Dns: true,
2013-10-25 19:23:28 +02:00
Node: "thisisanode",
},
},
{
name: "basic",
cmd: "getaddressesbyaccount",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetAddressesByAccountCmd(testId,
"account")
},
result: &GetAddressesByAccountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "account",
},
},
{
name: "basic",
cmd: "getbalance",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBalanceCmd(testId)
},
result: &GetBalanceCmd{
2014-01-03 23:50:17 +01:00
id: testId,
MinConf: 1, // the default
},
},
{
name: "basic + account",
cmd: "getbalance",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBalanceCmd(testId, "account")
},
result: &GetBalanceCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "account",
MinConf: 1, // the default
},
},
{
name: "basic + minconf",
cmd: "getbalance",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBalanceCmd(testId, "", 2)
},
result: &GetBalanceCmd{
2014-01-03 23:50:17 +01:00
id: testId,
MinConf: 2,
},
},
{
name: "basic + account + minconf",
cmd: "getbalance",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBalanceCmd(testId, "account", 2)
},
result: &GetBalanceCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "account",
MinConf: 2,
},
},
{
name: "basic",
cmd: "getbestblockhash",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBestBlockHashCmd(testId)
},
result: &GetBestBlockHashCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "getblock",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBlockCmd(testId,
"somehash")
},
result: &GetBlockCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Hash: "somehash",
Verbose: true,
},
},
2014-05-12 18:53:34 +02:00
{
name: "basic",
cmd: "getblockchaininfo",
f: func() (Cmd, error) {
return NewGetBlockChainInfoCmd(testId)
},
result: &GetBlockChainInfoCmd{
id: testId,
},
},
{
name: "basic",
cmd: "getblockcount",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBlockCountCmd(testId)
},
result: &GetBlockCountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "getblockhash",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBlockHashCmd(testId, 1234)
},
result: &GetBlockHashCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Index: 1234,
},
},
{
name: "basic",
cmd: "getblocktemplate",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBlockTemplateCmd(testId)
},
result: &GetBlockTemplateCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic + request",
cmd: "getblocktemplate",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBlockTemplateCmd(testId,
&TemplateRequest{Mode: "mode",
Capabilities: []string{"one", "two", "three"}})
},
result: &GetBlockTemplateCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Request: &TemplateRequest{
Mode: "mode",
Capabilities: []string{
"one",
"two",
"three",
},
},
},
},
{
name: "basic + request no mode",
cmd: "getblocktemplate",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetBlockTemplateCmd(testId,
&TemplateRequest{
Capabilities: []string{"one", "two", "three"}})
},
result: &GetBlockTemplateCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Request: &TemplateRequest{
Capabilities: []string{
"one",
"two",
"three",
},
},
},
},
2013-10-25 20:42:25 +02:00
{
name: "basic",
cmd: "getconnectioncount",
2013-10-25 20:42:25 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetConnectionCountCmd(testId)
2013-10-25 20:42:25 +02:00
},
result: &GetConnectionCountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 20:42:25 +02:00
},
},
{
name: "basic",
cmd: "getdifficulty",
2013-10-25 20:42:25 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetDifficultyCmd(testId)
2013-10-25 20:42:25 +02:00
},
result: &GetDifficultyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 20:42:25 +02:00
},
},
{
name: "basic",
cmd: "getgenerate",
2013-10-25 20:42:25 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetGenerateCmd(testId)
2013-10-25 20:42:25 +02:00
},
result: &GetGenerateCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 20:42:25 +02:00
},
},
{
name: "basic",
cmd: "gethashespersec",
2013-10-25 20:42:25 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetHashesPerSecCmd(testId)
2013-10-25 20:42:25 +02:00
},
result: &GetHashesPerSecCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 20:42:25 +02:00
},
},
{
name: "basic",
cmd: "getinfo",
2013-10-25 20:42:25 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetInfoCmd(testId)
2013-10-25 20:42:25 +02:00
},
result: &GetInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 20:42:25 +02:00
},
},
{
name: "basic",
cmd: "getmininginfo",
2013-10-25 21:02:13 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetMiningInfoCmd(testId)
2013-10-25 21:02:13 +02:00
},
result: &GetMiningInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 21:02:13 +02:00
},
},
2013-10-25 20:42:25 +02:00
{
name: "basic",
cmd: "getnettotals",
2013-10-25 20:42:25 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetNetTotalsCmd(testId)
2013-10-25 20:42:25 +02:00
},
result: &GetNetTotalsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-25 20:42:25 +02:00
},
},
{
name: "basic",
cmd: "getnetworkhashps",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetNetworkHashPSCmd(testId)
},
result: &GetNetworkHashPSCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Blocks: 120,
Height: -1,
},
},
{
name: "basic + blocks",
cmd: "getnetworkhashps",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetNetworkHashPSCmd(testId, 5000)
},
result: &GetNetworkHashPSCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Blocks: 5000,
Height: -1,
},
},
{
name: "basic + blocks + height",
cmd: "getnetworkhashps",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetNetworkHashPSCmd(testId, 5000, 1000)
},
result: &GetNetworkHashPSCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Blocks: 5000,
Height: 1000,
},
},
2014-05-14 17:45:13 +02:00
{
name: "basic",
cmd: "getnetworkinfo",
f: func() (Cmd, error) {
return NewGetNetworkInfoCmd(testId)
},
result: &GetNetworkInfoCmd{
id: testId,
},
},
{
name: "basic",
cmd: "getnewaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetNewAddressCmd(testId, "account")
},
2013-10-25 21:02:13 +02:00
result: &GetNewAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "account",
2013-10-25 21:02:13 +02:00
},
},
{
name: "basic",
cmd: "getpeerinfo",
2013-10-25 21:02:13 +02:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetPeerInfoCmd(testId)
2013-10-25 21:02:13 +02:00
},
result: &GetPeerInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "getrawchangeaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawChangeAddressCmd(testId)
},
result: &GetRawChangeAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic + account",
cmd: "getrawchangeaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawChangeAddressCmd(testId,
"accountname")
},
result: &GetRawChangeAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "accountname",
},
},
{
name: "basic",
cmd: "getrawmempool",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawMempoolCmd(testId)
},
result: &GetRawMempoolCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic noverbose",
cmd: "getrawmempool",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawMempoolCmd(testId, false)
},
result: &GetRawMempoolCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic verbose",
cmd: "getrawmempool",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawMempoolCmd(testId, true)
},
result: &GetRawMempoolCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Verbose: true,
},
},
{
name: "basic",
cmd: "getrawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawTransactionCmd(testId,
"sometxid")
},
result: &GetRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Txid: "sometxid",
},
},
{
name: "basic + verbose",
cmd: "getrawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetRawTransactionCmd(testId,
"sometxid",
1)
},
result: &GetRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Txid: "sometxid",
Verbose: 1,
},
},
{
name: "basic",
cmd: "getreceivedbyaccount",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetReceivedByAccountCmd(testId,
"abtcaccount",
1)
},
result: &GetReceivedByAccountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "abtcaccount",
MinConf: 1,
},
},
2014-01-08 16:31:54 +01:00
{
name: "basic + opt",
cmd: "getreceivedbyaccount",
f: func() (Cmd, error) {
return NewGetReceivedByAccountCmd(testId,
"abtcaccount",
2)
},
result: &GetReceivedByAccountCmd{
id: testId,
Account: "abtcaccount",
MinConf: 2,
},
},
{
name: "basic",
cmd: "getreceivedbyaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetReceivedByAddressCmd(testId,
"abtcaddress",
1)
},
result: &GetReceivedByAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "abtcaddress",
MinConf: 1,
},
},
2014-01-08 16:31:54 +01:00
{
name: "basic + opt",
cmd: "getreceivedbyaddress",
f: func() (Cmd, error) {
return NewGetReceivedByAddressCmd(testId,
"abtcaddress",
2)
},
result: &GetReceivedByAddressCmd{
id: testId,
Address: "abtcaddress",
MinConf: 2,
},
},
{
name: "basic",
cmd: "gettransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetTransactionCmd(testId,
"atxid")
},
result: &GetTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Txid: "atxid",
},
},
{
name: "basic",
cmd: "gettxout",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetTxOutCmd(testId,
"sometx",
10)
},
result: &GetTxOutCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Txid: "sometx",
Output: 10,
},
},
{
name: "basic + optional",
cmd: "gettxout",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetTxOutCmd(testId,
"sometx",
10,
false)
},
result: &GetTxOutCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Txid: "sometx",
Output: 10,
IncludeMempool: false,
},
},
{
name: "basic",
cmd: "gettxoutsetinfo",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewGetTxOutSetInfoCmd(testId)
},
result: &GetTxOutSetInfoCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "getwork",
f: func() (Cmd, error) {
return NewGetWorkCmd(testId, "some data")
},
result: &GetWorkCmd{
id: testId,
Data: "some data",
},
},
{
name: "basic",
cmd: "help",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewHelpCmd(testId)
},
result: &HelpCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic + optional cmd",
cmd: "help",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewHelpCmd(testId,
"getinfo")
},
result: &HelpCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Command: "getinfo",
},
},
{
name: "basic",
cmd: "importprivkey",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewImportPrivKeyCmd(testId,
"somereallongprivatekey")
},
result: &ImportPrivKeyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
PrivKey: "somereallongprivatekey",
Rescan: true,
},
},
{
name: "basic + 1 opt",
cmd: "importprivkey",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewImportPrivKeyCmd(testId,
"somereallongprivatekey",
"some text")
},
result: &ImportPrivKeyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
PrivKey: "somereallongprivatekey",
Label: "some text",
Rescan: true,
},
},
{
name: "basic + 2 opts",
cmd: "importprivkey",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewImportPrivKeyCmd(testId,
"somereallongprivatekey",
"some text",
false)
},
result: &ImportPrivKeyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
PrivKey: "somereallongprivatekey",
Label: "some text",
2013-11-18 15:13:02 +01:00
Rescan: false,
},
},
{
name: "basic",
cmd: "importwallet",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewImportWalletCmd(testId,
"walletfilename.dat")
},
result: &ImportWalletCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Filename: "walletfilename.dat",
},
},
{
name: "basic",
cmd: "keypoolrefill",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewKeyPoolRefillCmd(testId)
},
result: &KeyPoolRefillCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
2014-01-17 18:18:34 +01:00
{
name: "newsize",
cmd: "keypoolrefill",
f: func() (Cmd, error) {
return NewKeyPoolRefillCmd(testId, 1000000)
},
result: &KeyPoolRefillCmd{
id: testId,
NewSize: 1000000,
},
},
{
name: "basic",
cmd: "listaccounts",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListAccountsCmd(testId, 1)
},
result: &ListAccountsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
MinConf: 1,
},
},
2014-01-08 16:31:54 +01:00
{
name: "basic + opt",
cmd: "listaccounts",
f: func() (Cmd, error) {
return NewListAccountsCmd(testId, 2)
},
result: &ListAccountsCmd{
id: testId,
MinConf: 2,
},
},
{
name: "basic",
cmd: "listaddressgroupings",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListAddressGroupingsCmd(testId)
},
result: &ListAddressGroupingsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
2013-11-07 20:11:50 +01:00
{
name: "basic",
cmd: "listlockunspent",
2013-11-07 20:11:50 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListLockUnspentCmd(testId)
2013-11-07 20:11:50 +01:00
},
result: &ListLockUnspentCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-11-07 20:11:50 +01:00
},
},
{
name: "basic",
cmd: "listreceivedbyaccount",
2013-11-07 20:11:50 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListReceivedByAccountCmd(testId)
2013-11-07 20:11:50 +01:00
},
result: &ListReceivedByAccountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-11-07 20:11:50 +01:00
MinConf: 1,
},
},
{
name: "basic + 1 opt",
cmd: "listreceivedbyaccount",
f: func() (Cmd, error) {
return NewListReceivedByAccountCmd(testId, 2)
},
result: &ListReceivedByAccountCmd{
id: testId,
MinConf: 2,
},
},
{
name: "basic + 2 opt",
cmd: "listreceivedbyaccount",
f: func() (Cmd, error) {
return NewListReceivedByAccountCmd(testId, 2, true)
},
result: &ListReceivedByAccountCmd{
id: testId,
MinConf: 2,
IncludeEmpty: true,
},
},
{
name: "basic",
cmd: "listreceivedbyaddress",
f: func() (Cmd, error) {
return NewListReceivedByAddressCmd(testId)
},
result: &ListReceivedByAddressCmd{
id: testId,
MinConf: 1,
},
},
{
name: "basic + 1 opt",
cmd: "listreceivedbyaddress",
f: func() (Cmd, error) {
return NewListReceivedByAddressCmd(testId, 2)
},
result: &ListReceivedByAddressCmd{
id: testId,
MinConf: 2,
},
},
{
name: "basic + 2 opt",
cmd: "listreceivedbyaddress",
f: func() (Cmd, error) {
return NewListReceivedByAddressCmd(testId, 2, true)
},
result: &ListReceivedByAddressCmd{
id: testId,
MinConf: 2,
IncludeEmpty: true,
},
},
{
name: "basic",
cmd: "listsinceblock",
f: func() (Cmd, error) {
return NewListSinceBlockCmd(testId)
},
result: &ListSinceBlockCmd{
id: testId,
TargetConfirmations: 1,
},
},
{
name: "basic + 1 ops",
cmd: "listsinceblock",
f: func() (Cmd, error) {
return NewListSinceBlockCmd(testId, "someblockhash")
},
result: &ListSinceBlockCmd{
id: testId,
BlockHash: "someblockhash",
TargetConfirmations: 1,
},
},
{
name: "basic + 2 ops",
cmd: "listsinceblock",
f: func() (Cmd, error) {
return NewListSinceBlockCmd(testId, "someblockhash", 3)
},
result: &ListSinceBlockCmd{
id: testId,
BlockHash: "someblockhash",
TargetConfirmations: 3,
},
},
{
name: "basic",
cmd: "listtransactions",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListTransactionsCmd(testId)
},
result: &ListTransactionsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "",
Count: 10,
From: 0,
},
},
{
name: "+ 1 optarg",
cmd: "listtransactions",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListTransactionsCmd(testId, "abcde")
},
result: &ListTransactionsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "abcde",
Count: 10,
From: 0,
},
},
{
name: "+ 2 optargs",
cmd: "listtransactions",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListTransactionsCmd(testId, "abcde", 123)
},
result: &ListTransactionsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "abcde",
Count: 123,
From: 0,
},
},
{
name: "+ 3 optargs",
cmd: "listtransactions",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListTransactionsCmd(testId, "abcde", 123, 456)
},
result: &ListTransactionsCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Account: "abcde",
Count: 123,
From: 456,
},
},
2013-11-07 20:11:50 +01:00
{
name: "basic",
cmd: "listunspent",
2013-11-07 20:11:50 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListUnspentCmd(testId)
2013-11-07 20:11:50 +01:00
},
result: &ListUnspentCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-11-07 20:11:50 +01:00
MinConf: 1,
MaxConf: 999999,
},
},
{
name: "basic + opts",
cmd: "listunspent",
2013-11-07 20:11:50 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewListUnspentCmd(testId, 0, 6)
2013-11-07 20:11:50 +01:00
},
result: &ListUnspentCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-11-07 20:11:50 +01:00
MinConf: 0,
MaxConf: 6,
},
},
2014-01-17 18:04:49 +01:00
{
name: "basic + opts + addresses",
cmd: "listunspent",
f: func() (Cmd, error) {
return NewListUnspentCmd(testId, 0, 6, []string{
"a", "b", "c",
})
},
result: &ListUnspentCmd{
id: testId,
MinConf: 0,
MaxConf: 6,
Addresses: []string{"a", "b", "c"},
},
},
{
name: "basic",
cmd: "lockunspent",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewLockUnspentCmd(testId, true)
},
result: &LockUnspentCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Unlock: true,
},
},
{
name: "basic",
cmd: "move",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewMoveCmd(testId,
"account1",
"account2",
12,
1)
},
result: &MoveCmd{
2014-01-03 23:50:17 +01:00
id: testId,
FromAccount: "account1",
ToAccount: "account2",
Amount: 12,
MinConf: 1, // the default
},
},
{
name: "basic + optionals",
cmd: "move",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewMoveCmd(testId,
"account1",
"account2",
12,
1,
"some comment")
},
result: &MoveCmd{
2014-01-03 23:50:17 +01:00
id: testId,
FromAccount: "account1",
ToAccount: "account2",
Amount: 12,
MinConf: 1, // the default
Comment: "some comment",
},
},
{
name: "basic",
cmd: "ping",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewPingCmd(testId)
},
result: &PingCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "sendfrom",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSendFromCmd(testId,
"account",
"address",
12,
1)
},
result: &SendFromCmd{
2014-01-03 23:50:17 +01:00
id: testId,
FromAccount: "account",
ToAddress: "address",
Amount: 12,
MinConf: 1, // the default
},
},
{
name: "basic + options",
cmd: "sendfrom",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSendFromCmd(testId,
"account",
"address",
12,
1,
"a comment",
"comment to")
},
result: &SendFromCmd{
2014-01-03 23:50:17 +01:00
id: testId,
FromAccount: "account",
ToAddress: "address",
Amount: 12,
MinConf: 1, // the default
Comment: "a comment",
CommentTo: "comment to",
},
},
{
name: "basic",
cmd: "sendmany",
f: func() (Cmd, error) {
pairs := map[string]int64{
"address A": 1000,
"address B": 2000,
"address C": 3000,
}
2014-01-03 23:50:17 +01:00
return NewSendManyCmd(testId,
"account",
pairs)
},
result: &SendManyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
FromAccount: "account",
Amounts: map[string]int64{
"address A": 1000,
"address B": 2000,
"address C": 3000,
},
MinConf: 1, // the default
},
},
{
name: "+ options",
cmd: "sendmany",
f: func() (Cmd, error) {
pairs := map[string]int64{
"address A": 1000,
"address B": 2000,
"address C": 3000,
}
2014-01-03 23:50:17 +01:00
return NewSendManyCmd(testId,
"account",
pairs,
10,
"comment")
},
result: &SendManyCmd{
2014-01-03 23:50:17 +01:00
id: testId,
FromAccount: "account",
Amounts: map[string]int64{
"address A": 1000,
"address B": 2000,
"address C": 3000,
},
MinConf: 10,
Comment: "comment",
},
},
{
name: "basic",
cmd: "sendrawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSendRawTransactionCmd(testId,
"hexstringofatx")
},
result: &SendRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
HexTx: "hexstringofatx",
},
},
{
name: "allowhighfees: false",
cmd: "sendrawtransaction",
f: func() (Cmd, error) {
return NewSendRawTransactionCmd(testId,
"hexstringofatx", false)
},
result: &SendRawTransactionCmd{
id: testId,
HexTx: "hexstringofatx",
},
},
{
name: "allowhighfees: true",
cmd: "sendrawtransaction",
f: func() (Cmd, error) {
return NewSendRawTransactionCmd(testId,
"hexstringofatx", true)
},
result: &SendRawTransactionCmd{
id: testId,
HexTx: "hexstringofatx",
AllowHighFees: true,
},
},
{
name: "basic",
cmd: "sendtoaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSendToAddressCmd(testId,
"somebtcaddress",
1)
},
result: &SendToAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "somebtcaddress",
Amount: 1,
},
},
{
name: "basic + optional",
cmd: "sendtoaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSendToAddressCmd(testId,
"somebtcaddress",
1,
"a comment",
"comment to")
},
result: &SendToAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "somebtcaddress",
Amount: 1,
Comment: "a comment",
CommentTo: "comment to",
},
},
{
name: "basic",
cmd: "setaccount",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSetAccountCmd(testId,
"somebtcaddress",
"account name")
},
result: &SetAccountCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "somebtcaddress",
Account: "account name",
},
},
{
name: "basic",
cmd: "setgenerate",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSetGenerateCmd(testId, true)
},
result: &SetGenerateCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Generate: true,
},
},
{
name: "basic + optional",
cmd: "setgenerate",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSetGenerateCmd(testId, true, 10)
},
result: &SetGenerateCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Generate: true,
GenProcLimit: 10,
},
},
{
name: "basic",
cmd: "settxfee",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSetTxFeeCmd(testId, 10)
},
result: &SetTxFeeCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Amount: 10,
},
},
2013-11-05 22:51:37 +01:00
{
name: "basic",
cmd: "signmessage",
2013-11-05 22:51:37 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSignMessageCmd(testId,
2013-11-05 22:51:37 +01:00
"btcaddress",
"a message")
},
result: &SignMessageCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-11-05 22:51:37 +01:00
Address: "btcaddress",
Message: "a message",
},
},
{
name: "basic",
cmd: "signrawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSignRawTransactionCmd(testId,
"sometxstring")
},
result: &SignRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
RawTx: "sometxstring",
},
},
/* {
name: "basic + optional",
cmd: "signrawtransaction",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSignRawTransactionCmd(testId,
"sometxstring",
[]RawTxInput{
RawTxInput{
Txid: "test",
Vout: 1,
ScriptPubKey: "test",
RedeemScript: "test",
},
},
[]string{"aprivatekey", "privkey2"},
"flags")
},
result: &SignRawTransactionCmd{
2014-01-03 23:50:17 +01:00
id: testId,
RawTx: "sometxstring",
Inputs: []RawTxInput{
RawTxInput{
Txid: "test",
Vout: 1,
ScriptPubKey: "test",
RedeemScript: "test",
},
},
PrivKeys: []string{"aprivatekey", "privkey2"},
Flags: "flags",
},
},*/
{
name: "basic",
cmd: "stop",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewStopCmd(testId)
},
result: &StopCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "submitblock",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSubmitBlockCmd(testId,
"lotsofhex")
},
result: &SubmitBlockCmd{
2014-01-03 23:50:17 +01:00
id: testId,
HexBlock: "lotsofhex",
},
},
2013-10-31 21:37:14 +01:00
{
name: "+ optional object",
cmd: "submitblock",
2013-10-31 21:37:14 +01:00
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewSubmitBlockCmd(testId,
2013-10-31 21:37:14 +01:00
"lotsofhex",
&SubmitBlockOptions{WorkId: "otherstuff"})
},
result: &SubmitBlockCmd{
2014-01-03 23:50:17 +01:00
id: testId,
2013-10-31 21:37:14 +01:00
HexBlock: "lotsofhex",
Options: &SubmitBlockOptions{WorkId: "otherstuff"},
},
},
{
name: "basic",
cmd: "validateaddress",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewValidateAddressCmd(testId,
"somebtcaddress")
},
result: &ValidateAddressCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "somebtcaddress",
},
},
{
name: "basic",
cmd: "verifychain",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewVerifyChainCmd(testId)
},
result: &VerifyChainCmd{
2014-01-03 23:50:17 +01:00
id: testId,
CheckLevel: 3,
CheckDepth: 288,
},
},
{
name: "basic + optional",
cmd: "verifychain",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewVerifyChainCmd(testId, 4, 1)
},
result: &VerifyChainCmd{
2014-01-03 23:50:17 +01:00
id: testId,
CheckLevel: 4,
CheckDepth: 1,
},
},
{
name: "basic",
cmd: "verifymessage",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewVerifyMessageCmd(testId,
"someaddress",
"somesig",
"a message")
},
result: &VerifyMessageCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Address: "someaddress",
Signature: "somesig",
Message: "a message",
},
},
{
name: "basic",
cmd: "walletlock",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewWalletLockCmd(testId)
},
result: &WalletLockCmd{
2014-01-03 23:50:17 +01:00
id: testId,
},
},
{
name: "basic",
cmd: "walletpassphrase",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewWalletPassphraseCmd(testId,
"phrase1",
10)
},
result: &WalletPassphraseCmd{
2014-01-03 23:50:17 +01:00
id: testId,
Passphrase: "phrase1",
Timeout: 10,
},
},
{
name: "basic",
cmd: "walletpassphrasechange",
f: func() (Cmd, error) {
2014-01-03 23:50:17 +01:00
return NewWalletPassphraseChangeCmd(testId,
"phrase1", "phrase2")
},
result: &WalletPassphraseChangeCmd{
2014-01-03 23:50:17 +01:00
id: testId,
OldPassphrase: "phrase1",
NewPassphrase: "phrase2",
},
},
}
func TestCmds(t *testing.T) {
for _, test := range jsoncmdtests {
c, err := test.f()
name := test.cmd + " " + test.name
if err != nil {
t.Errorf("%s: failed to run func: %v",
name, err)
continue
}
msg, err := json.Marshal(c)
if err != nil {
t.Errorf("%s: failed to marshal cmd: %v",
name, err)
continue
}
c2, err := ParseMarshaledCmd(msg)
if err != nil {
t.Errorf("%s: failed to ummarshal cmd: %v",
name, err)
continue
}
2014-01-03 23:50:17 +01:00
id, ok := (c.Id()).(float64)
if !ok || id != testId {
t.Errorf("%s: id not returned properly", name)
}
if c.Method() != test.cmd {
t.Errorf("%s: Method name not returned properly: "+
"%s vs. %s", name, c.Method(), test.cmd)
2014-01-03 23:50:17 +01:00
}
if !reflect.DeepEqual(test.result, c2) {
t.Errorf("%s: unmarshal not as expected. "+
"got %v wanted %v", name, spew.Sdump(c2),
spew.Sdump(test.result))
}
if !reflect.DeepEqual(c, c2) {
t.Errorf("%s: unmarshal not as we started with. "+
"got %v wanted %v", name, spew.Sdump(c2),
spew.Sdump(c))
}
2014-01-08 15:29:10 +01:00
newId := 2.0
c.SetId(newId)
id, ok = (c.Id()).(float64)
if !ok || id != newId {
t.Errorf("%s: id not returned properly after change.", name)
}
}
}
func TestHelps(t *testing.T) {
helpTests := []string{
"addmultisigaddress",
"addnode",
"backupwallet",
"createmultisig",
"createrawtransaction",
"debuglevel",
"decoderawtransaction",
"decodescript",
"dumpprivkey",
"dumpwallet",
"encryptwallet",
"getaccount",
"getaccountaddress",
"getaddednodeinfo",
"getaddressesbyaccount",
"getbalance",
"getbestblockhash",
"getblock",
"getblockcount",
"getblockhash",
"getblocktemplate",
"getconnectioncount",
"getdifficulty",
"getgenerate",
"gethashespersec",
"getinfo",
"getmininginfo",
"getnettotals",
"getnetworkhashps",
"getnewaddress",
"getpeerinfo",
"getrawchangeaddress",
"getrawmempool",
"getrawtransaction",
"getreceivedbyaccount",
"getreceivedbyaddress",
"gettransaction",
"gettxout",
"gettxoutsetinfo",
"getwork",
"help",
"importprivkey",
"importwallet",
"keypoolrefill",
"listaccounts",
"listaddressgroupings",
"listlockunspent",
"listreceivedbyaccount",
"listreceivedbyaddress",
"listsinceblock",
"listtransactions",
"listunspent",
"lockunspent",
"move",
"ping",
"sendfrom",
"sendmany",
"sendrawtransaction",
"sendtoaddress",
"setaccount",
"setgenerate",
"settxfee",
"signmessage",
"signrawtransaction",
"stop",
"submitblock",
"validateaddress",
"verifychain",
"verifymessage",
"walletlock",
"walletpassphrase",
"walletpassphrasechange",
}
for _, test := range helpTests {
helpStr, err := GetHelpString(test)
if err != nil {
t.Errorf("%s: failed to get help string: %v",
test, err)
continue
}
if !strings.HasPrefix(helpStr, test) {
t.Errorf("%s: help string doesn't begin with command "+
"name: \"%s\"", test, helpStr)
continue
}
}
}