Repository: oceanprotocol/ocean.py
Issue: test_payer_market_flow - TypeError: Cannot convert None of type <class 'NoneType'> to bytes

**Describe the bug**

In running pytest, I got the bug described in the title. Full trackback below.

Note: all other tests passed. tox also fully passed.

**TODOs**

- [ ] Fix the bug so that the unit test passes
- [ ] If possible, identify why it passed on tox but not on pytest. Will be important going forward.

**To Reproduce**

Follow steps 1-5 of developers.md (incl recent commit https://github.com/oceanprotocol/ocean.py/commit/25c6aeec292109e3d393b4f1c25354c0a694d35f), choosing barge steps, except in step 2, make sure barge is clean, and run with provider 2 as follows
```console
docker system prune -a --volumes    # cleanup the old containers
./start_ocean.sh  --with-provider2   # run barge with provider on
```

You'll see in step 4 that the call to `pytest` gives one failure. 

To run *just* the failing test:
```
pytest tests/ocean/test_market_flow.py::test_payer_market_flow
```

Note: if you run `tox` then it will all pass.

**Expected behavior**
All tests from pytests should pass.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Traceback**
```
(venv) trentmc@trentmcLnv:~/code/ocean.py$ pytest tests/ocean/test_market_flow.py::test_payer_market_flow
============================================================================= test session starts ==============================================================================
platform linux -- Python 3.8.7, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /home/trentmc/code/ocean.py, configfile: pytest.ini
collected 1 item                                                                                                                                                               

tests/ocean/test_market_flow.py F                                                                                                                                                                                                                                    [100%]

================================================================================================================================= FAILURES =================================================================================================================================
__________________________________________________________________________________________________________________________ test_payer_market_flow __________________________________________________________________________________________________________________________

    def test_payer_market_flow():
        pub_wallet = get_publisher_wallet()
    
        publisher_ocean = get_publisher_ocean_instance()
        consumer_ocean = get_consumer_ocean_instance()
        another_consumer_ocean = get_another_consumer_ocean_instance(use_provider_mock=True)
    
        # Register Asset
        asset = get_registered_ddo(publisher_ocean, get_metadata(), pub_wallet)
        assert isinstance(asset, Asset)
        assert asset.data_token_address
    
        another_consumer_wallet = get_another_consumer_wallet()
        consumer_wallet = get_consumer_wallet()
    
        service = asset.get_service(service_type=ServiceTypes.ASSET_ACCESS)
        sa = ServiceAgreement.from_json(service.as_dictionary())
    
        # Mint data tokens and assign to publisher
        dt = publisher_ocean.get_data_token(asset.data_token_address)
        mint_tokens_and_wait(dt, pub_wallet.address, pub_wallet)
    
        ######
        # Give the consumer some datatokens so they can order the service
        try:
            tx_id = dt.transfer_tokens(consumer_wallet.address, 10, pub_wallet)
            dt.verify_transfer_tx(tx_id, pub_wallet.address, consumer_wallet.address)
        except (AssertionError, Exception) as e:
            print(e)
            raise
    
        ######
        # Place order for the download service
        order_requirements = consumer_ocean.assets.order(
            asset.did, another_consumer_wallet.address, sa.index
        )
    
        ######
        # Pay for the service and have another_consumer_wallet as consumer
        _order_tx_id = consumer_ocean.assets.pay_for_service(
            order_requirements.amount,
            order_requirements.data_token_address,
            asset.did,
            service.index,
            "0xF9f2DB837b3db03Be72252fAeD2f6E0b73E428b9",
            consumer_wallet,
            another_consumer_wallet.address,
        )
        asset_folder = None
        assert asset_folder is None
        if asset_folder is None:
            # Download the asset files
>           asset_folder = another_consumer_ocean.assets.download(
                asset.did,
                sa.index,
                another_consumer_wallet,
                _order_tx_id,
                another_consumer_ocean.config.downloads_path,
            )

tests/ocean/test_market_flow.py:160: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
ocean_lib/ocean/ocean_assets.py:540: in download
    return download_asset_files(
ocean_lib/assets/asset_downloader.py:73: in download_asset_files
    data_provider.download_service(
tests/resources/mocks/data_provider_mock.py:125: in download_service
    signature = DataServiceProvider.sign_message(wallet, did, config)
ocean_lib/data_provider/data_service_provider.py:90: in sign_message
    return Web3Helper.sign_hash(
ocean_lib/web3_internal/web3helper.py:62: in sign_hash
    s = wallet.sign(msg_hash)
ocean_lib/web3_internal/wallet.py:126: in sign
    account = self._web3.eth.account.privateKeyToAccount(self.private_key)
venv/lib/python3.8/site-packages/eth_utils/decorators.py:18: in _wrapper
    return self.method(obj, *args, **kwargs)
venv/lib/python3.8/site-packages/eth_account/account.py:199: in privateKeyToAccount
    key = self._parsePrivateKey(private_key)
venv/lib/python3.8/site-packages/eth_utils/decorators.py:18: in _wrapper
    return self.method(obj, *args, **kwargs)
venv/lib/python3.8/site-packages/eth_account/account.py:462: in _parsePrivateKey
    return self._keys.PrivateKey(HexBytes(key))
venv/lib/python3.8/site-packages/hexbytes/main.py:23: in __new__
    bytesval = to_bytes(val)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

val = None

    def to_bytes(val: Union[bool, bytearray, bytes, int, str]) -> bytes:
        """
        Equivalent to: eth_utils.hexstr_if_str(eth_utils.to_bytes, val)
    
        Convert a hex string, integer, or bool, to a bytes representation.
        Alternatively, pass through bytes or bytearray as a bytes value.
        """
        if isinstance(val, bytes):
            return val
        elif isinstance(val, str):
            return hexstr_to_bytes(val)
        elif isinstance(val, bytearray):
            return bytes(val)
        elif isinstance(val, bool):
            return b"\\x01" if val else b"\\x00"
        elif isinstance(val, int):
            # Note that this int check must come after the bool check, because
            #   isinstance(True, int) is True
            if val < 0:
                raise ValueError(f"Cannot convert negative integer {val} to bytes")
            else:
                return to_bytes(hex(val))
        else:
>           raise TypeError(f"Cannot convert {val!r} of type {type(val)} to bytes")
E           TypeError: Cannot convert None of type <class 'NoneType'> to bytes

venv/lib/python3.8/site-packages/hexbytes/_utils.py:30: TypeError
-------------------------------------------------------------------------------------------------------------------------- Captured stdout setup ---------------------------------------------------------------------------------------------------------------------------
sender: 0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58, 0xe2DD09d719Da89e5a3D0F2549c7E24566e947260, None, address: 0xe2DD09d719Da89e5a3D0F2549c7E24566e947260
private key: 0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58
public key: 0x8b1b222564fb8302e9acfa4bcd60060de03ae479fcbed38fe21e45cd39ddb3fefb60ba1b4625e00d02223027c8f485f6d77693ab62ce06289b23942c6b319ccf

sender balance: 91.726972148
--------------------------------------------------------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------------------------------------------------------
signing message with nonce 10: 0x009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483, account=0xe2DD09d719Da89e5a3D0F2549c7E24566e947260
signing message with nonce 0: did:op:009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483, account=None
--------------------------------------------------------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------------------------------------------------------
2021-02-24 15:34:31 trentmcLnv root[29378] INFO Schema: /home/trentmc/code/ocean.py/venv/lib/python3.8/site-packages/plecos/schemas/metadata_local_v0_5.json
2021-02-24 15:34:31 trentmcLnv ocean[29378] INFO Successfully created data token with address 0x009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483 for new dataset asset.
2021-02-24 15:34:31 trentmcLnv ocean_lib.data_provider.data_service_provider[29378] INFO Asset urls encrypted successfully, encrypted urls str: {"encryptedDocument": "0x04630b410b5
...
7fb8bdd1"}, encryptedEndpoint http://localhost:8030/api/v1/services/encrypt
2021-02-24 15:34:31 trentmcLnv ocean[29378] INFO Asset/ddo published on-chain successfully.
2021-02-24 15:34:39 trentmcLnv ocean_lib.data_provider.data_service_provider[29378] INFO invoke the initialize endpoint with this url: http://localhost:8030/api/v1/services/initialize?documentId=did:op:009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483&serviceId=3&serviceType=access&dataToken=0x009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483&consumerAddress=None
---------------------------------------------------------------------------------------------------------------------------- Captured log call -----------------------------------------------------------------------------------------------------------------------------
INFO     root:plecos.py:47 Schema: /home/trentmc/code/ocean.py/venv/lib/python3.8/site-packages/plecos/schemas/metadata_local_v0_5.json
INFO     ocean:ocean_assets.py:197 Successfully created data token with address 0x009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483 for new dataset asset.
INFO     ocean_lib.data_provider.data_service_provider:data_service_provider.py:78 Asset urls encrypted successfully, encrypted urls str: {"encryptedDocument": "0x04630b410
...
b462fde9f266f545f87fb8bdd1"}, encryptedEndpoint http://localhost:8030/api/v1/services/encrypt
INFO     ocean:ocean_assets.py:313 Asset/ddo published on-chain successfully.
INFO     ocean_lib.data_provider.data_service_provider:data_service_provider.py:128 invoke the initialize endpoint with this url: http://localhost:8030/api/v1/services/initialize?documentId=did:op:009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483&serviceId=3&serviceType=access&dataToken=0x009F3610Dab3A5E1f4A0de84e81b9BB17DbE2483&consumerAddress=None
========================================================================================================================= short test summary info ==========================================================================================================================
FAILED tests/ocean/test_market_flow.py::test_payer_market_flow - TypeError: Cannot convert None of type <class 'NoneType'> to bytes
============================================================================================================================ 1 failed in 11.66s ===
```

Changed files:
ocean_lib/web3_internal/wallet.py

diff --git a/ocean_lib/web3_internal/wallet.py b/ocean_lib/web3_internal/wallet.py
index de434d8..77a7c7a 100644
--- a/ocean_lib/web3_internal/wallet.py
+++ b/ocean_lib/web3_internal/wallet.py
@@ -33,6 +33,10 @@ class Wallet:
         password: typing.Union[str, None] = None,
         address: typing.Union[str, None] = None,
     ):
+        assert private_key or (
+            encrypted_key and password
+        ), "private_key or encrypted_key and password is required."
+
         self._web3 = web3
         self._last_tx_count.clear()
 
@@ -48,6 +52,12 @@ class Wallet:
             assert self._address is None or self._address == address
             self._address = address
             self._password = None
+
+        assert self.private_key, (
+            "something is not right, private key is not available. "
+            "please check the arguments are valid."
+        )
+
         self._max_gas_price = os.getenv(ENV_MAX_GAS_PRICE, None)
 
     @property