Example #1
0
    def test_storage_forging(self):
        expected = self.script['storage']
        actual = unforge_micheline(forge_micheline(expected))
        self.assertEqual(expected, actual)

        expected = self.program.storage.from_micheline_value(expected).to_micheline_value(mode='readable')
        actual = unforge_micheline(forge_micheline(expected))
        self.assertEqual(expected, actual)
Example #2
0
def blind_unpack(data: bytes):
    try:
        return unforge_chain_id(data)
    except ValueError:
        pass
    try:
        return unforge_address(data)
    except (ValueError, KeyError):
        pass
    try:
        return unforge_public_key(data)
    except (ValueError, KeyError):
        pass
    try:
        return unforge_signature(data)
    except ValueError:
        pass

    if len(data) > 0 and data.startswith(b'\x05'):
        try:
            res = unforge_micheline(data[1:])
            return micheline_value_to_python_object(res)
        except (ValueError, AssertionError):
            pass

    try:
        return data.decode()
    except ValueError:
        pass

    return data
Example #3
0
def unpack(data: bytes, type_expr):
    """ Unpack bytes (currently without unpacking domain types, so it's unforging + cutting 0x05 prefix).

    :param data: Packed data
    :param type_expr: type of the packed data (currently unused)
    :returns: Micheline expression
    """
    assert data.startswith(b'\x05'), f'packed data should start with 05'
    parsed = unforge_micheline(data[1:])
    return parsed
Example #4
0
 def test_forge_combs(self):
     expr = {
         'prim': 'Pair',
         'args': [{
             'int': '1'
         }, {
             'int': '2'
         }, {
             'int': '3'
         }, {
             'int': '4'
         }]
     }
     self.assertEqual(expr, unforge_micheline(forge_micheline(expr)))
 def test_parameters_forging(self):
     expected = self.operation['parameters'].get('value', {'prim': 'Unit'})
     actual = unforge_micheline(forge_micheline(expected))
     self.assertEqual(expected, actual)
Example #6
0
 def unpack(cls, data: bytes) -> 'MichelsonType':
     assert cls.is_packable(), f'{cls.prim} cannot be packed'
     assert data.startswith(b'\x05'), f'packed data should start with 05'
     val_expr = unforge_micheline(data[1:])
     return cls.from_micheline_value(val_expr)
Example #7
0
def unpack(data: bytes, type_expr):
    assert data.startswith(b'\x05'), f'packed data should start with 05'
    parsed = unforge_micheline(data[1:])
    return parsed