Fix optarg handling for listtransactions and add tests.

This commit is contained in:
Josh Rickmar 2013-11-26 16:08:31 -05:00
parent 79fe2e594b
commit 368d6c0779
2 changed files with 50 additions and 2 deletions

View file

@ -4391,7 +4391,7 @@ func NewListTransactionsCmd(id interface{}, optArgs ...interface{}) (*ListTransa
account = ac account = ac
} }
if len(optArgs) > 1 { if len(optArgs) > 1 {
cnt, ok := optArgs[0].(int) cnt, ok := optArgs[1].(int)
if !ok { if !ok {
return nil, errors.New("second optional argument count is not an int") return nil, errors.New("second optional argument count is not an int")
} }
@ -4399,7 +4399,7 @@ func NewListTransactionsCmd(id interface{}, optArgs ...interface{}) (*ListTransa
count = cnt count = cnt
} }
if len(optArgs) > 2 { if len(optArgs) > 2 {
frm, ok := optArgs[0].(int) frm, ok := optArgs[2].(int)
if !ok { if !ok {
return nil, errors.New("third optional argument from is not an int") return nil, errors.New("third optional argument from is not an int")
} }

View file

@ -770,6 +770,54 @@ var jsoncmdtests = []struct {
MinConf: 1, MinConf: 1,
}, },
}, },
{
name: "basic listtransactions",
f: func() (Cmd, error) {
return NewListTransactionsCmd(float64(1))
},
result: &ListTransactionsCmd{
id: float64(1),
Account: "",
Count: 10,
From: 0,
},
},
{
name: "listtransactions 1 optarg",
f: func() (Cmd, error) {
return NewListTransactionsCmd(float64(1), "abcde")
},
result: &ListTransactionsCmd{
id: float64(1),
Account: "abcde",
Count: 10,
From: 0,
},
},
{
name: "listtransactions 2 optargs",
f: func() (Cmd, error) {
return NewListTransactionsCmd(float64(1), "abcde", 123)
},
result: &ListTransactionsCmd{
id: float64(1),
Account: "abcde",
Count: 123,
From: 0,
},
},
{
name: "listtransactions 3 optargs",
f: func() (Cmd, error) {
return NewListTransactionsCmd(float64(1), "abcde", 123, 456)
},
result: &ListTransactionsCmd{
id: float64(1),
Account: "abcde",
Count: 123,
From: 456,
},
},
{ {
name: "basic listunspent", name: "basic listunspent",
f: func() (Cmd, error) { f: func() (Cmd, error) {