Refactored contract tests to remove code duplication