import sys

import pytest

if sys.version_info >= (3, 3):
    from unittest.mock import Mock


ABI = [{}]
ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'


@pytest.mark.parametrize(
    'args,kwargs,expected',
    (
        ((ADDRESS,), {}, None),
        ((INVALID_CHECKSUM_ADDRESS,), {}, ValueError),
        ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
        ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
    )
)
def test_contract_address_validation(web3, args, kwargs, expected):
    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            web3.eth.contract(*args, **kwargs)
        return

    # run without errors
    web3.eth.contract(*args, **kwargs)


@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3")
def test_set_contract_factory(web3):
    factoryClass = Mock()
    web3.eth.setContractFactory(factoryClass)
    web3.eth.contract(contract_name='myname')
    factoryClass.factory.assert_called_once_with(web3, contract_name='myname')

import sys

import pytest

if sys.version_info >= (3, 3):
    from unittest.mock import Mock


ABI = [{}]
ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'


@pytest.mark.parametrize(
    'args,kwargs,expected',
    (
        ((ADDRESS,), {}, None),
        ((INVALID_CHECKSUM_ADDRESS,), {}, ValueError),
        ((), {'address': ADDRESS}, None),
        ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
    )
)
def test_contract_address_validation(web3, args, kwargs, expected):
    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            web3.eth.contract(*args, **kwargs)
        return

    # run without errors
    web3.eth.contract(*args, **kwargs)


@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3")
def test_set_contract_factory(web3):
    factoryClass = Mock()
    web3.eth.setContractFactory(factoryClass)
    web3.eth.contract(contract_name='myname')
    factoryClass.factory.assert_called_once_with(web3, contract_name='myname')

Replace duplicate test with valid address kwarg
Replace duplicate test with valid address kwarg

  import sys
  
  import pytest
  
  if sys.version_info >= (3, 3):
      from unittest.mock import Mock
  
  
  ABI = [{}]
  ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
  INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'
  
  
  @pytest.mark.parametrize(
      'args,kwargs,expected',
      (
          ((ADDRESS,), {}, None),
          ((INVALID_CHECKSUM_ADDRESS,), {}, ValueError),
-         ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
+         ((), {'address': ADDRESS}, None),
          ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
      )
  )
  def test_contract_address_validation(web3, args, kwargs, expected):
      if isinstance(expected, type) and issubclass(expected, Exception):
          with pytest.raises(expected):
              web3.eth.contract(*args, **kwargs)
          return
  
      # run without errors
      web3.eth.contract(*args, **kwargs)
  
  
  @pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3")
  def test_set_contract_factory(web3):
      factoryClass = Mock()
      web3.eth.setContractFactory(factoryClass)
      web3.eth.contract(contract_name='myname')
      factoryClass.factory.assert_called_once_with(web3, contract_name='myname')
  
Replace duplicate test with valid address kwarg
## Code Before:
import sys

import pytest

if sys.version_info >= (3, 3):
    from unittest.mock import Mock


ABI = [{}]
ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'


@pytest.mark.parametrize(
    'args,kwargs,expected',
    (
        ((ADDRESS,), {}, None),
        ((INVALID_CHECKSUM_ADDRESS,), {}, ValueError),
        ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
        ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
    )
)
def test_contract_address_validation(web3, args, kwargs, expected):
    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            web3.eth.contract(*args, **kwargs)
        return

    # run without errors
    web3.eth.contract(*args, **kwargs)


@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3")
def test_set_contract_factory(web3):
    factoryClass = Mock()
    web3.eth.setContractFactory(factoryClass)
    web3.eth.contract(contract_name='myname')
    factoryClass.factory.assert_called_once_with(web3, contract_name='myname')

## Instruction:
Replace duplicate test with valid address kwarg
## Code After:
import sys

import pytest

if sys.version_info >= (3, 3):
    from unittest.mock import Mock


ABI = [{}]
ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'


@pytest.mark.parametrize(
    'args,kwargs,expected',
    (
        ((ADDRESS,), {}, None),
        ((INVALID_CHECKSUM_ADDRESS,), {}, ValueError),
        ((), {'address': ADDRESS}, None),
        ((), {'address': INVALID_CHECKSUM_ADDRESS}, ValueError),
    )
)
def test_contract_address_validation(web3, args, kwargs, expected):
    if isinstance(expected, type) and issubclass(expected, Exception):
        with pytest.raises(expected):
            web3.eth.contract(*args, **kwargs)
        return

    # run without errors
    web3.eth.contract(*args, **kwargs)


@pytest.mark.skipif(sys.version_info < (3, 3), reason="needs Mock library from 3.3")
def test_set_contract_factory(web3):
    factoryClass = Mock()
    web3.eth.setContractFactory(factoryClass)
    web3.eth.contract(contract_name='myname')
    factoryClass.factory.assert_called_once_with(web3, contract_name='myname')
