Self-testing is a device-independent technique based on non-local correlations whose aim is to certify the effective uniqueness of the quantum state and measurements needed to produce these correlations. It is known that the maximal violation of some Bell inequalities suffices for this purpose. However, most of the existing self-testing protocols for two devices exploit the well-known Clauser-Horne-Shimony-Holt Bell inequality or modifications of it, and always with two measurements per party. Here, we generalize the previous results by demonstrating that one can construct self-testing protocols based on the chained Bell inequalities, defined for two devices implementing an arbitrary number of two-output measurements. On the one hand, this proves that the quantum state and measurements leading to the maximal violation of the chained Bell inequality are unique. On the other hand, in the limit of a large number of measurements, our approach allows one to self-test the entire plane of measurements spanned by the Pauli matrices X and Z. Our results also imply that the chained Bell inequalities can be used to certify two bits of perfect randomness.As mentioned, the concept of self-testing was introduced by Mayers and Yao in [4], where the procedure to self-test a maximally entangled pair of qubits is described. This protocol was made robust in subsequent works, see [7,11]. In the following years new self-testing protocols for more complicated states such as graph states were described [10], as well as protocols for self-testing more complicated operations, such as entire quantum circuits [11]. A general numerical method for self-testing, known as the SWAP method, was introduced in [12], providing much better estimations of robustness than the analytical proofs. This numerical method can also be used to self-test three-qubit states such as GHZ states [13] and W states [14].Despite its importance, we lack general techniques to construct and prove self-testing protocols. Most of the existing examples are built from the maximal violation of a Bell inequality. Based on geometrical considerations, see for instance [15,16], one expects that generically there is a unique way, state and measurements, of producing the extremal correlations attaining the maximal quantum violation of a Bell inequality. This is not always the case, but whenever it is, we say that the corresponding Bell inequality is useful for self-testing. Following this approach, it is possible to prove that the state and measurements maximally violating the Clauser-Horne-Shimony-Holt (CHSH) inequality [25] are unique [5,7], and the corresponding state is a maximally entangled two-qubit state. More recently, a self-testing protocol for any two-qubit entangled states has been derived in [20] using the Bell inequalities introduced in [8], and all the self-testing configurations for a maximally entangled state of two qubits using two measurements of two outputs have been identified in [9]. From a general perspective, it is an interesting question to understand whic...