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)
def pack(val_expr, type_expr) -> bytes: """ Basically prepack (pack domain types) + forge (encode bytes). Resulting value is prefixed with 0x05. :param val_expr: value expression (Micheline expression) :param type_expr: type expression (Micheline expression) """ data = prepack_micheline(val_expr, type_expr) return b'\x05' + forge_micheline(data)
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 forge_transaction(content: Dict[str, Any]) -> bytes: res = forge_nat(operation_tags[content['kind']]) res += forge_address(content['source'], tz_only=True) res += forge_nat(int(content['fee'])) res += forge_nat(int(content['counter'])) res += forge_nat(int(content['gas_limit'])) res += forge_nat(int(content['storage_limit'])) res += forge_nat(int(content['amount'])) res += forge_address(content['destination']) if has_parameters(content): res += forge_bool(True) res += forge_entrypoint(content['parameters']['entrypoint']) res += forge_array(forge_micheline(content['parameters']['value'])) else: res += forge_bool(False) return res
def test_parameters_forging(self): expected = self.operation['parameters'].get('value', {'prim': 'Unit'}) actual = unforge_micheline(forge_micheline(expected)) self.assertEqual(expected, actual)
def forge(self, mode='readable') -> bytes: val_expr = self.to_micheline_value(mode=mode) return forge_micheline(val_expr)
def pack(val_expr, type_expr): data = prepack_micheline(val_expr, type_expr) return b'\x05' + forge_micheline(data)