From 708dce8d99dd3a8d3586d29487d8da6f757b4e6b Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 27 Nov 2013 19:27:46 -0500 Subject: [PATCH] Fix sendmany optarg parsing and add tests. --- jsoncmd.go | 2 +- jsoncmd_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/jsoncmd.go b/jsoncmd.go index 2d221345..30e1df9c 100644 --- a/jsoncmd.go +++ b/jsoncmd.go @@ -5110,7 +5110,7 @@ func NewSendManyCmd(id interface{}, fromaccount string, amounts map[string]int64 minconf = m } if len(optArgs) > 1 { - c, ok := optArgs[0].(string) + c, ok := optArgs[1].(string) if !ok { return nil, errors.New("second optional parameter comment is not a string") } diff --git a/jsoncmd_test.go b/jsoncmd_test.go index 6c2951c1..9fb011e2 100644 --- a/jsoncmd_test.go +++ b/jsoncmd_test.go @@ -933,6 +933,55 @@ var jsoncmdtests = []struct { CommentTo: "comment to", }, }, + { + name: "basic sendmany", + f: func() (Cmd, error) { + pairs := map[string]int64{ + "address A": 1000, + "address B": 2000, + "address C": 3000, + } + return NewSendManyCmd(float64(1), + "account", + pairs) + }, + result: &SendManyCmd{ + id: float64(1), + FromAccount: "account", + Amounts: map[string]int64{ + "address A": 1000, + "address B": 2000, + "address C": 3000, + }, + MinConf: 1, // the default + }, + }, + { + name: "sendmany + options", + f: func() (Cmd, error) { + pairs := map[string]int64{ + "address A": 1000, + "address B": 2000, + "address C": 3000, + } + return NewSendManyCmd(float64(1), + "account", + pairs, + 10, + "comment") + }, + result: &SendManyCmd{ + id: float64(1), + FromAccount: "account", + Amounts: map[string]int64{ + "address A": 1000, + "address B": 2000, + "address C": 3000, + }, + MinConf: 10, + Comment: "comment", + }, + }, { name: "basic sendrawtransaction", f: func() (Cmd, error) {