示例#1
0
// TestRpcCommand tests RpcCommand by generating some commands and
// trying to send them off.
func TestRpcCommand(t *testing.T) {
	user := "******"
	pass := "******"
	server := "invalid"
	var msg []byte
	_, err := btcjson.RpcCommand(user, pass, server, msg)
	if err == nil {
		t.Errorf("Should fail.")
	}
	msg, err = btcjson.CreateMessage("getinfo")
	if err != nil {
		t.Errorf("Cannot create valid json message")
	}
	_, err = btcjson.RpcCommand(user, pass, server, msg)
	if err == nil {
		t.Errorf("Should not connect to server.")
	}

	badMsg := []byte("{\"jsonrpc\":\"1.0\",\"id\":\"btcd\",\"method\":\"\"}")
	_, err = btcjson.RpcCommand(user, pass, server, badMsg)
	if err == nil {
		t.Errorf("Cannot have no method in msg..")
	}
	return
}
示例#2
0
// TestRpcCreateMessage tests CreateMessage using the table of messages
// in cmdtests.
func TestRpcCreateMessage(t *testing.T) {
	var err error
	for i, tt := range cmdtests {
		if tt.args == nil {
			_, err = btcjson.CreateMessage(tt.cmd)
		} else {
			_, err = btcjson.CreateMessage(tt.cmd, tt.args...)
		}
		if tt.pass {
			if err != nil {
				t.Errorf("Could not create command %d: %s %v.", i, tt.cmd, err)
			}
		} else {
			if err == nil {
				t.Errorf("Should create command. %d: %s", i, tt.cmd)
			}
		}
	}
	return
}