def test_holding_address(self):
        holding_address = addresser.make_holding_address(uuid4().hex)

        self.assertEqual(len(holding_address), 70, "The address is valid.")

        self.assertEqual(addresser.address_is(holding_address),
                         addresser.AddressSpace.HOLDING,
                         "The address is correctly identified as an Holding.")
    def test_offer_address(self):
        offer_address = addresser.make_offer_address(uuid4().hex)

        self.assertEqual(len(offer_address), 70, "The address is valid.")

        self.assertEqual(addresser.address_is(offer_address),
                         addresser.AddressSpace.OFFER,
                         "The address is correctly identified as an Offer.")
    def test_account_address(self):
        account_address = addresser.make_account_address(uuid4().hex)

        self.assertEqual(len(account_address), 70, "The address is valid.")

        self.assertEqual(addresser.address_is(account_address),
                         addresser.AddressSpace.ACCOUNT,
                         "The address is correctly identified as an Account.")
    def test_holding_address(self):
        holding_address = addresser.make_holding_address(uuid4().hex)

        self.assertEqual(len(holding_address), 70, "The address is valid.")

        self.assertEqual(addresser.address_is(holding_address),
                         addresser.AddressSpace.HOLDING,
                         "The address is correctly identified as an Holding.")
    def test_account_address(self):
        account_address = addresser.make_account_address(uuid4().hex)

        self.assertEqual(len(account_address), 70, "The address is valid.")

        self.assertEqual(addresser.address_is(account_address),
                         addresser.AddressSpace.ACCOUNT,
                         "The address is correctly identified as an Account.")
    def test_offer_address(self):
        offer_address = addresser.make_offer_address(uuid4().hex)

        self.assertEqual(len(offer_address), 70, "The address is valid.")

        self.assertEqual(addresser.address_is(offer_address),
                         addresser.AddressSpace.OFFER,
                         "The address is correctly identified as an Offer.")
    def test_resource_address(self):

        resource_address = addresser.make_resource_address(uuid4().hex)

        self.assertEqual(len(resource_address), 70, "The address is valid.")

        self.assertEqual(
            addresser.address_is(resource_address),
            addresser.AddressSpace.RESOURCE,
            "The address is correctly identified as an Resource.")
Ejemplo n.º 8
0
def data_to_dicts(address, data):
    """Deserializes a protobuf "container" binary based on its address. Returns
    a list of the decoded objects which were stored at that address.
    """
    data_type = address_is(address)

    try:
        container = CONTAINERS[data_type]
    except KeyError:
        raise TypeError('Unknown data type: {}'.format(data_type))

    entries = _parse_proto(container, data).entries
    return [_proto_to_dict(pb) for pb in entries]
Ejemplo n.º 9
0
def data_to_dicts(address, data):
    """Deserializes a protobuf "container" binary based on its address. Returns
    a list of the decoded objects which were stored at that address.
    """
    data_type = address_is(address)

    if IGNORE.get(data_type):
        return []

    try:
        container = CONTAINERS[data_type]
    except KeyError:
        raise TypeError('Unknown data type: {}'.format(data_type))

    entries = _parse_proto(container, data).entries
    return [_proto_to_dict(pb) for pb in entries]
Ejemplo n.º 10
0
def _update(database, block_num, address, resource):
    data_type = address_is(address)

    resource['start_block_num'] = block_num
    resource['end_block_num'] = sys.maxsize

    try:
        table_query = database.get_table(TABLE_NAMES[data_type])
        seconday_index = SECONDARY_INDEXES[data_type]
    except KeyError:
        raise TypeError('Unknown data type: {}'.format(data_type))

    query = table_query\
        .get_all(resource[seconday_index], index=seconday_index)\
        .filter({'end_block_num': sys.maxsize})\
        .update({'end_block_num': block_num})\
        .merge(table_query.insert(resource).without('replaced'))

    return database.run_query(query)
Ejemplo n.º 11
0
def _update(database, block_num, address, resource):
    data_type = address_is(address)

    resource['start_block_num'] = block_num
    resource['end_block_num'] = sys.maxsize

    try:
        table_query = database.get_table(TABLE_NAMES[data_type])
        seconday_index = SECONDARY_INDEXES[data_type]
    except KeyError:
        raise TypeError('Unknown data type: {}'.format(data_type))

    query = table_query\
        .get_all(resource[seconday_index], index=seconday_index)\
        .filter({'end_block_num': sys.maxsize})\
        .update({'end_block_num': block_num})\
        .merge(table_query.insert(resource).without('replaced'))

    return database.run_query(query)