This commit introduces a new major version of the dcrjson module which
removes all dcrd RPC type support, instead focusing only on method and
type registration. The dcrd methods and types are moved to the
github.com/decred/dcrd/rpc/jsonrpc/types module.
In order to improve backwards compatibility with dcrjson/v2, the API
has been modified to register methods as interface{} instead of
string. This allows different method string types to be used to key
parameter types during registration and lookup, and will allow
dcrjson/v2 to forward registrations of RPC methods to v3 without
causing duplicate registrations errors for incompatible types.
With the introduction of the new types package, the RPC API has been
modified to replace concatenated hash blobs to JSON string arrays of
hash strings. The RPC API major version is bumped to reflect this
change.
A future update to dcrjson/v2 will add additional registrations,
forwarding the registrations to v3 and replacing command types with
type aliases where possible. Unfortunately, this can not be done
entirely in a single commit due to dcrjson/v2 and dcrjson/v3 sharing
the same directory in the source tree, and a branch will need to be
used for this update.
Module replacements are temporarily used to enable the changes for the
main module, including dcrctl. After the aforementioned update to
dcrjson/v2 and a forthcoming update to dcrwallet's RPC types package,
these replacements will be removed.
115 lines
2.0 KiB
Go
115 lines
2.0 KiB
Go
// Copyright (c) 2014 The btcsuite developers
|
|
// Copyright (c) 2015-2016 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package dcrjson
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// TestHelpers tests the various helper functions which create pointers to
|
|
// primitive types.
|
|
func TestHelpers(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
f func() interface{}
|
|
expected interface{}
|
|
}{
|
|
{
|
|
name: "bool",
|
|
f: func() interface{} {
|
|
return Bool(true)
|
|
},
|
|
expected: func() interface{} {
|
|
val := true
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "int",
|
|
f: func() interface{} {
|
|
return Int(5)
|
|
},
|
|
expected: func() interface{} {
|
|
val := int(5)
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "uint",
|
|
f: func() interface{} {
|
|
return Uint(5)
|
|
},
|
|
expected: func() interface{} {
|
|
val := uint(5)
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "int32",
|
|
f: func() interface{} {
|
|
return Int32(5)
|
|
},
|
|
expected: func() interface{} {
|
|
val := int32(5)
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "uint32",
|
|
f: func() interface{} {
|
|
return Uint32(5)
|
|
},
|
|
expected: func() interface{} {
|
|
val := uint32(5)
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "int64",
|
|
f: func() interface{} {
|
|
return Int64(5)
|
|
},
|
|
expected: func() interface{} {
|
|
val := int64(5)
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "uint64",
|
|
f: func() interface{} {
|
|
return Uint64(5)
|
|
},
|
|
expected: func() interface{} {
|
|
val := uint64(5)
|
|
return &val
|
|
}(),
|
|
},
|
|
{
|
|
name: "string",
|
|
f: func() interface{} {
|
|
return String("abc")
|
|
},
|
|
expected: func() interface{} {
|
|
val := "abc"
|
|
return &val
|
|
}(),
|
|
},
|
|
}
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
for i, test := range tests {
|
|
result := test.f()
|
|
if !reflect.DeepEqual(result, test.expected) {
|
|
t.Errorf("Test #%d (%s) unexpected value - got %v, "+
|
|
"want %v", i, test.name, result, test.expected)
|
|
continue
|
|
}
|
|
}
|
|
}
|