"In order to afflict you, to test you in your latter end." All the commandments that are written in the Book of Deuteronomy (Mishneh Torah) are written in them in the language of "hear" (shema). And why is this so? At the time when Israel made the calf, they lost what they had said, "we will do" (na'aseh), but "we will hear/obey" (nishma) remained in their hand. Therefore Moses our teacher warns them in the language of "hear," so that they not lose "we will hear." "In order to afflict you." All that He afflicted them with in the wilderness, He did only for the sake of a test, to make known to all the creatures. "That which is in your heart." That all the peoples should know that you do not keep the commandments for the sake of the good and the contentment of spirit that He did with you, but rather out of love you did all that you did; even though He afflicted you, you did not refrain from keeping His commandments.
Why Moses Speaks in the Language of Hear in Deuteronomy
Midrash Aggadah, Deuteronomy 8:2
למען ענתך לנסתך באחריתך. כל מצות שבמשנה תורה כתיב בהו בלשון שמע, ולמה כן, בשעה שעשו ישראל את העגל איבדו מה שאמרו נעשה, אבל נשמע היה בידם, לפיכך משה רבינו מזהיר אותם בלשון שמע, שלא יאבדו את נשמע: למען ענותך. כל מה שעינה אותם במדבר לא עשה אלא בשביל נסיון להודיע לכל הבריות: את אשר בלבבך. שידעו כל העמים שאין אתם שומרים מצות בשביל טובה ונחת רוח שעשה עמכם, אלא מאהבה עשיתם כל מה שעשיתם, אעפ"י שעינה אתכם לא הנחתם מלשמור את מצותיו: