コード例 #1
0
ファイル: jsonapi_test.go プロジェクト: jimmysong/btcd
// 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
ファイル: jsonapi_test.go プロジェクト: jimmysong/btcd
// 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
}