def test_bytes_to_int(): assert bytes_to_int(bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])) == 0 assert bytes_to_int(bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])) == 1 assert bytes_to_int(bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01])) == 257 assert bytes_to_int(bytes([0x00])) == 0 assert bytes_to_int(bytes([0x01, 0x01])) == 257 assert bytes_to_int(bytes([0x00, 0x01, 0x01])) == 257 assert bytes_to_int(bytes([0x00, 0x00, 0x01, 0x01])) == 257 assert bytes_to_int(bytes([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])) == 2**256-1
def __init__(self, log): self.order_id = bytes_to_int(log['args']['id']) self.maker = Address(log['args']['maker']) self.pay_token = Address(log['args']['pay_gem']) self.pay_amount = Wad(log['args']['pay_amt']) self.buy_token = Address(log['args']['buy_gem']) self.buy_amount = Wad(log['args']['buy_amt']) self.timestamp = log['args']['timestamp'] self.raw = log
def __init__(self, log): self.order_id = bytes_to_int(log['transactionHash']) self.maker = Address(log['args']['makerAddress']) self.maker_token = Address(log['args']['makerToken']) self.maker_amount = Wad(log['args']['makerAmount']) self.taker = Address(log['args']['takerAddress']) self.taker_token = Address(log['args']['takerToken']) self.taker_amount = Wad(log['args']['takerAmount']) self.raw = log
def _make_order_id_result_function(receipt): receipt_logs = receipt['logs'] if receipt_logs is not None: for receipt_log in receipt_logs: if len(receipt_log['topics']) > 0 and receipt_log['topics'][ 0] == '0x773ff502687307abfa024ac9f62f9752a0d210dac2ffd9a29e38e12e2ea82c82': log_make_abi = [ abi for abi in SimpleMarket.abi if abi.get('name') == 'LogMake' ][0] event_data = get_event_data(log_make_abi, receipt_log) return bytes_to_int(event_data['args']['id']) return None
def test_bytes_to_int_from_int_should_fail(): with pytest.raises(AssertionError): bytes_to_int(0)
def test_bytes_to_int_from_string(): assert bytes_to_int('\x00') == 0 assert bytes_to_int('\x01') == 1 assert bytes_to_int('\x01\x01') == 257 assert bytes_to_int('\x00\x01\x01') == 257 assert bytes_to_int('\x00\x00\x01\x01') == 257