This concept is present in so many fairy tales and folk tales all over the world.
Usually it's a magical test that no trickery or lies or games can get past.
-Sometimes it's explicit: "only one that's pure of heart" can hold something, enter some place, see something. -Sometimes it's implicit so that you only see the 'test' and one person fails while another passes, but it's not said explicitly that the test is for a pure-hearted individual. In these implicit ones the tests are designed to catch people who who are motivated by status, wealth, power etc "Worldly" things. So you have a poor old woman in tatters asking for water or grain or some food (This one is SOOOO universal) in circumstances that make it clear there is no reward for it. In fact often it calls for a sacrifice on the part of the person who doesn't know they're being tested.
It struck me as very Fi, the whole obsession with the 'true' quality of (specifically) "the heart". There is an element of a test of altruism but it's much more about the "true intentions" of the person and the test is designed to out fake kindness and reward people who are motivated purely by the desire to do what's right, no matter if they get credit for it or not.