test and fix bugs in getaddednodeinfo
This commit is contained in:
parent
77316a003a
commit
b3b8b37855
2 changed files with 45 additions and 21 deletions
34
jsoncmd.go
34
jsoncmd.go
|
@ -1253,7 +1253,7 @@ func NewGetAddedNodeInfoCmd(id interface{}, dns bool, optArgs ...string) (*GetAd
|
||||||
if len(optArgs) > 1 {
|
if len(optArgs) > 1 {
|
||||||
return nil, ErrTooManyOptArgs
|
return nil, ErrTooManyOptArgs
|
||||||
}
|
}
|
||||||
node = optArgs[1]
|
node = optArgs[0]
|
||||||
}
|
}
|
||||||
return &GetAddedNodeInfoCmd{
|
return &GetAddedNodeInfoCmd{
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -1275,26 +1275,18 @@ func (cmd *GetAddedNodeInfoCmd) Method() string {
|
||||||
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
|
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
|
||||||
func (cmd *GetAddedNodeInfoCmd) MarshalJSON() ([]byte, error) {
|
func (cmd *GetAddedNodeInfoCmd) MarshalJSON() ([]byte, error) {
|
||||||
// Fill and marshal a RawCmd.
|
// Fill and marshal a RawCmd.
|
||||||
var raw RawCmd
|
|
||||||
if cmd.Node == "" {
|
raw := RawCmd{
|
||||||
raw = RawCmd{
|
Jsonrpc: "1.0",
|
||||||
Jsonrpc: "1.0",
|
Method: "getaddednodeinfo",
|
||||||
Method: "getaddednodeinfo",
|
Id: cmd.id,
|
||||||
Id: cmd.id,
|
Params: []interface{}{
|
||||||
Params: []interface{}{
|
cmd.Dns,
|
||||||
cmd.Dns,
|
},
|
||||||
},
|
}
|
||||||
}
|
|
||||||
} else {
|
if cmd.Node != "" {
|
||||||
raw = RawCmd{
|
raw.Params = append(raw.Params, cmd.Node)
|
||||||
Jsonrpc: "1.0",
|
|
||||||
Method: "getaddednodeinfo",
|
|
||||||
Id: cmd.id,
|
|
||||||
Params: []interface{}{
|
|
||||||
cmd.Dns,
|
|
||||||
cmd.Node,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Marshal(raw)
|
return json.Marshal(raw)
|
||||||
|
|
|
@ -190,6 +190,38 @@ var jsoncmdtests = []struct {
|
||||||
Account: "account",
|
Account: "account",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "basic getaddednodeinfo true",
|
||||||
|
f: func() (Cmd, error) {
|
||||||
|
return NewGetAddedNodeInfoCmd(float64(1), true)
|
||||||
|
},
|
||||||
|
result: &GetAddedNodeInfoCmd{
|
||||||
|
id: float64(1),
|
||||||
|
Dns: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "basic getaddednodeinfo false",
|
||||||
|
f: func() (Cmd, error) {
|
||||||
|
return NewGetAddedNodeInfoCmd(float64(1), false)
|
||||||
|
},
|
||||||
|
result: &GetAddedNodeInfoCmd{
|
||||||
|
id: float64(1),
|
||||||
|
Dns: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "basic getaddednodeinfo withnode",
|
||||||
|
f: func() (Cmd, error) {
|
||||||
|
return NewGetAddedNodeInfoCmd(float64(1), true,
|
||||||
|
"thisisanode")
|
||||||
|
},
|
||||||
|
result: &GetAddedNodeInfoCmd{
|
||||||
|
id: float64(1),
|
||||||
|
Dns: true,
|
||||||
|
Node: "thisisanode",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "basic ping",
|
name: "basic ping",
|
||||||
f: func() (Cmd, error) {
|
f: func() (Cmd, error) {
|
||||||
|
|
Loading…
Reference in a new issue