# Buggy code
def verify_offer_creation(self, assets, timeout):
    """
    Verify whether we are creating a valid order.
    This method raises a RuntimeError if the created order is not valid.
    """
    if assets.first.asset_id == assets.second.asset_id:
        raise RuntimeError("You cannot trade between the same wallet")

    if (
        assets.first.asset_id not in self.wallets
        or not self.wallets[assets.first.asset_id].created
    ):
        raise RuntimeError("Please create a %s wallet first" % assets.first.asset_id)

    if (
        assets.second.asset_id not in self.wallets
        or not self.wallets[assets.second.asset_id].created
    ):
        raise RuntimeError("Please create a %s wallet first" % assets.second.asset_id)

    asset1_min_unit = self.wallets[assets.first.asset_id].min_unit()
    if assets.first.amount < asset1_min_unit:
        raise RuntimeError(
            "The assets to trade should be higher than or equal to the min unit of this asset (%s)."
            % assets.first
        )

    asset2_min_unit = self.wallets[assets.second.asset_id].min_unit()
    if assets.first.amount < asset2_min_unit:
        raise RuntimeError(
            "The assets to trade should be higher than or equal to the min unit of this asset (%s)."
            % assets.second
        )

    if timeout < 0:
        raise RuntimeError("The timeout for this order should be positive")

    if timeout > MAX_ORDER_TIMEOUT:
        raise RuntimeError("The timeout for this order should be less than a day")


# Traceback (ValueError)
2019-01-14 09:17:48+0100 [-] INFO:OrderManager:Ask order created with id: 22403ab62cf279355450fb9b69816cca834a059b.3
2019-01-14 09:17:48+0100 [-] INFO:TrustChainCommunity:Signed block to 30303030 (Block 0ea44938 from ...51e65150:4 links ...30303030:0 for {'tick': {'trader_id': '22403ab62cf279355450fb9b69816cca834a059b', 'timestamp': 1547453868.099689, 'timeout': 3600, 'traded': 0, 'order_number': 3, 'assets': {'second': {'amount': 4403L, 'type': 'MB'}, 'first': {'amount': 374647L, 'type': 'BTC'}}}, 'version': 2} type ask) validation result (<function partial_next at 0x7f92fd193de8>, [])
2019-01-14 09:17:48+0100 [-] INFO:MarketCommunity:Inserting tick <Ask P: 0.011752, Q: 374647 BTC, O: 22403ab62cf279355450fb9b69816cca834a059b.3> from 22403ab62cf279355450fb9b69816cca834a059b.3, asset pair: 374647 BTC 4403 MB
2019-01-14 09:17:48+0100 [-] WARNING:DatabaseOrderBook:Invalid tick inserted in order book.
2019-01-14 09:17:48+0100 [-] INFO:MarketCommunity:Ask created with asset pair 374647 BTC 4403 MB
2019-01-14 09:17:48+0100 [-] 127.0.0.1 - - [14/Jan/2019:08:17:47 +0000] "PUT /market/asks HTTP/1.1" 200 17 "-" "python-requests/2.21.0"
2019-01-14 09:17:48+0100 [-] INFO:MarketCommunity:Sending match message with id 400b17a1768dc5af8e17, order id 22403ab62cf279355450fb9b69816cca834a059b.3 and tick order id b49ea564c321e52581419f729c19932564a9b016.8 to trader 22403ab62cf279355450fb9b69816cca834a059b (quantity: 374647)
2019-01-14 09:17:49+0100 [-] ERROR:DHTDiscoveryCommunity:Got ping-response with unknown identifier, dropping packet
2019-01-14 09:17:51+0100 [-] INFO:PopularityCommunity:Content to publish: 0
2019-01-14 09:17:51+0100 [-] INFO:CreditMiningManager:0 active download(s), 0 bytes uploaded
2019-01-14 09:17:51+0100 [-] INFO:Dispersy:estimate someones WAN address is ('109.173.152.79', 30908) (WAN was ('109.173.152.79', 30987), LAN stays ('192.168.100.9', 48853))
2019-01-14 09:17:51+0100 [-] INFO:Dispersy:estimate someones WAN address is ('109.173.152.79', 30908) (WAN was ('109.173.152.79', 31054), LAN stays ('192.168.100.9', 48853))
2019-01-14 09:17:52+0100 [-] INFO:Dispersy:estimate someones WAN address is ('73.153.51.182', 7759) (WAN was ('109.175.184.192', 19172), LAN stays ('192.168.1.11', 7759))
2019-01-14 09:17:55+0100 [-] 127.0.0.1 - - [14/Jan/2019:08:17:54 +0000] "GET /downloads?get_pieces=1 HTTP/1.1" 200 17 "-" "Mozilla/5.0"
2019-01-14 09:17:55+0100 [-] INFO:CreditMiningManager:0 active download(s), 0 bytes uploaded
2019-01-14 09:17:56+0100 [-] INFO:Request:Timeout for ping to Peer<5.79.71.187:35010, K86FHJw+2sZcoVZZM2ffFyJEpPA=>
2019-01-14 09:17:56+0100 [-] INFO:PopularityCommunity:Content to publish: 0
2019-01-14 09:17:57+0100 [-] INFO:MarketCommunity:We received a match message for order 22403ab62cf279355450fb9b69816cca834a059b.3 (matched quantity: 374647)
2019-01-14 09:17:57+0100 [-] INFO:TransactionManager:Transaction created with id: b49ea564c321e52581419f729c19932564a9b016.2, asset pair 374647 BTC 4403 MB
2019-01-14 09:17:57+0100 [-] ERROR:MarketCommunity:Exception occurred while handling packet!
2019-01-14 09:17:57+0100 [-] Traceback (most recent call last):
2019-01-14 09:17:57+0100 [-]   File "/usr/local/lib/python2.7/dist-packages/Tribler/pyipv8/ipv8/community.py", line 284, in on_packet
2019-01-14 09:17:57+0100 [-]     self.decode_map[msg_id](source_address, data)
2019-01-14 09:17:57+0100 [-]   File "/usr/local/lib/python2.7/dist-packages/Tribler/pyipv8/ipv8/lazy_community.py", line 49, in wrapper
2019-01-14 09:17:57+0100 [-]     return func(self, Peer(auth.public_key_bin, source_address), *output)
2019-01-14 09:17:57+0100 [-]   File "/usr/local/lib/python2.7/dist-packages/Tribler/community/market/community.py", line 1258, in received_start_transaction
2019-01-14 09:17:57+0100 [-]     incoming_address, outgoing_address = self.get_order_addresses(order)
2019-01-14 09:17:57+0100 [-]   File "/usr/local/lib/python2.7/dist-packages/Tribler/community/market/community.py", line 347, in get_order_addresses
2019-01-14 09:17:57+0100 [-]     WalletAddress(self.wallets[order.assets.first.asset_id].get_address())
2019-01-14 09:17:57+0100 [-]   File "/usr/local/lib/python2.7/dist-packages/Tribler/community/market/core/wallet_address.py", line 13, in __init__
2019-01-14 09:17:57+0100 [-]     raise ValueError("Wallet address must be a string")
2019-01-14 09:17:57+0100 [-] ValueError: Wallet address must be a string
2019-01-14 09:17:57+0100 [-]
2019-01-14 09:17:58+0100 [-] INFO:MarketCommunity:We received a match message for order 22403ab62cf279355450fb9b69816cca834a059b.3 (matched quantity: 374647)
2019-01-14 09:17:58+0100 [-] INFO:MarketCommunity:Sending decline match message with match id 697c38d3007533a3ba8c to trader 0435c98718863b3f90c83c84302718542e3260ef (ip: 77.229.13.248, port: 34791)

# Fixed code
def verify_offer_creation(self, assets, timeout):
    """
    Verify whether we are creating a valid order.
    This method raises a RuntimeError if the created order is not valid.
    """
    if assets.first.asset_id == assets.second.asset_id:
        raise RuntimeError("You cannot trade between the same wallet")

    if (
        assets.first.asset_id not in self.wallets
        or not self.wallets[assets.first.asset_id].created
    ):
        raise RuntimeError("Please create a %s wallet first" % assets.first.asset_id)

    if (
        assets.second.asset_id not in self.wallets
        or not self.wallets[assets.second.asset_id].created
    ):
        raise RuntimeError("Please create a %s wallet first" % assets.second.asset_id)

    asset1_min_unit = self.wallets[assets.first.asset_id].min_unit()
    if assets.first.amount < asset1_min_unit:
        raise RuntimeError(
            "The assets to trade should be higher than or equal to the min unit of this asset (%s)."
            % assets.first
        )

    asset2_min_unit = self.wallets[assets.second.asset_id].min_unit()
    if assets.second.amount < asset2_min_unit:
        raise RuntimeError(
            "The assets to trade should be higher than or equal to the min unit of this asset (%s)."
            % assets.second
        )

    if timeout < 0:
        raise RuntimeError("The timeout for this order should be positive")

    if timeout > MAX_ORDER_TIMEOUT:
        raise RuntimeError("The timeout for this order should be less than a day")