Add RPC tests and improve relevant error handling.