637fbcadec
This commit converts the RPC server over to use the new features available in the latest version of btcjson and improve a few things along the way. This following summarizes the changes: - All btcjson imports have been updated to the latest package version - The help has been significantly improved - Invoking help with no command specified now provides an alphabetized list of all supported commands along with one-line usage - The help for each command is automatically generated and provides much more explicit information such as the type of each parameter, whether or not it's optional or required, etc - The websocket-specific commands are now provided when accessing the help when connected via websockets - Help has been added for all websocket-specific commands and is only accessible when connected via websockets - The error returns and handling of both the standard and websocket handlers has been made consistent - All RPC errors have been converted to the new RPCError type - Various variables have been renamed for consistency - Several RPC errors have been improved - The commands that are marked as unimplemented have been moved into the separate map where they belong - Several comments have been improved - An unnecessary check has been removed from the createrawtransaction handler - The command parsing has been restructured a bit to pave the way for JSON-RPC 2.0 batching support
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
// Copyright (c) 2015 Conformal Systems LLC.
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import "testing"
|
|
|
|
// TestHelp ensures the help is reasonably accurate by checking that every
|
|
// command specified also has result types defined and the one-line usage and
|
|
// help text can be generated for them.
|
|
func TestHelp(t *testing.T) {
|
|
// Ensure there are result types specified for every handler.
|
|
for k := range rpcHandlers {
|
|
if _, ok := rpcResultTypes[k]; !ok {
|
|
t.Errorf("RPC handler defined for method '%v' without "+
|
|
"also specifying result types", k)
|
|
continue
|
|
}
|
|
|
|
}
|
|
for k := range wsHandlers {
|
|
if _, ok := rpcResultTypes[k]; !ok {
|
|
t.Errorf("RPC handler defined for method '%v' without "+
|
|
"also specifying result types", k)
|
|
continue
|
|
}
|
|
|
|
}
|
|
|
|
// Ensure the usage for every command can be generated without errors.
|
|
helpCacher := newHelpCacher()
|
|
if _, err := helpCacher.rpcUsage(true); err != nil {
|
|
t.Fatalf("Failed to generate one-line usage: %v", err)
|
|
}
|
|
if _, err := helpCacher.rpcUsage(true); err != nil {
|
|
t.Fatalf("Failed to generate one-line usage (cached): %v", err)
|
|
}
|
|
|
|
// Ensure the help for every command can be generated without errors.
|
|
for k := range rpcHandlers {
|
|
if _, err := helpCacher.rpcMethodHelp(k); err != nil {
|
|
t.Errorf("Failed to generate help for method '%v': %v",
|
|
k, err)
|
|
continue
|
|
}
|
|
if _, err := helpCacher.rpcMethodHelp(k); err != nil {
|
|
t.Errorf("Failed to generate help for method '%v'"+
|
|
"(cached): %v", k, err)
|
|
continue
|
|
}
|
|
}
|
|
for k := range wsHandlers {
|
|
if _, err := helpCacher.rpcMethodHelp(k); err != nil {
|
|
t.Errorf("Failed to generate help for method '%v': %v",
|
|
k, err)
|
|
continue
|
|
}
|
|
if _, err := helpCacher.rpcMethodHelp(k); err != nil {
|
|
t.Errorf("Failed to generate help for method '%v'"+
|
|
"(cached): %v", k, err)
|
|
continue
|
|
}
|
|
}
|
|
}
|