Added test and fix for race condition in contract resolving