Testing for Endogeneity I apologize if this question is very basic. I have the following plain vanilla Instrumental Variable model. 

$Y=\alpha+X\beta+\varepsilon$

$X=\delta+Z\gamma+\eta$

$\varepsilon\perp\eta,\quad Z\perp\eta \quad$ true

I am interested in testing $\varepsilon\perp X$, that is, whether X is a valid instrument for the first equation (very informally stated, one might say I want to test whether $X$ is exogenous, or whether I need to instrument $X$ with $Z$)

My idea is: estimate the IV model using 2SLS or GMM, using both $X$ and $Z$ as instruments, and then perform a Sargan/Hansen test. My guess is that the test's power will depend on how strongly $Z$ predictx $X$ (that is, on how relevant of an instrument $Z$ is for $X$). In 2SLS, the first stage will fit perfectly and the test will be basically a test of whether the OLS residual are orthogonal to $Z$. Is this reasoning correct? Is the Sargan/Hansen test a valid test for $
\varepsilon\perp X$?
(i) I think your idea makes sense. Under the null, $[X,Z]$ is orthogonal to $\varepsilon$. Under the alternative, $X$ is correlated with $\varepsilon$. (ii) Your statement that it's "basically a test of whether the OLS residual are orthogonal to $Z$" is exactly what I think. (iii) Your thought about the power depending on the relevance of $Z$ also makes sense. If $Z$ is irrelevant, then the moment restrictions $E[Z_i' (y_i - \alpha - X_i \beta)] = 0$ hold for any $\beta$ (due to the uncorrelatedness of $Z_i$ and $X_i$) so the OLS residuals should appear to be uncorrelated with the instruments although the OLS estimator is inconsistent. I think this test is closely related with standard methods explained below, although I have not done any derivation in this regard.

(iv) As you would be aware, there are textbook methods to test endogeneity. Stata implements some. See help ivregress postestimation. You will see estat endogenous there. There, for the 2SLS estimation, OLS and 2SLS can be compared; or $y$ is regressed on $[X,\hat{\eta}]$, after which the statistical significance of $\hat\eta$ is tested.