So indeed it was credited to Abraham as righteousness.
Abram believed the Lord, and the Lord considered his response of faith as proof of genuine loyalty.
For what does the scripture say? “Abraham believed God, and it was credited to him as righteousness.”
So even David himself speaks regarding the blessedness of the man to whom God credits righteousness apart from works: