The Lord reveals that He chastens the wicked for their sins, but also, He chastens the righteous to prove them and help them progress saying -
"Therefore, be not afraid of your enemies, for I have decreed in my heart, saith the Lord, that I will prove you in all things, whether you will abide in my covenant, even unto death, that you may be found worthy.
15 For if ye will not abide in my covenant ye are not worthy of me." (Doctrine and Covenants 98:14–15)