smartpy-tezos 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of smartpy-tezos might be problematic. Click here for more details.
- smartpy/__init__.py +703 -0
- smartpy/config.py +2 -0
- smartpy/environment.py +130 -0
- smartpy/metadata.py +430 -0
- smartpy/modules.py +309 -0
- smartpy/scenario_utils.py +39 -0
- smartpy/services.py +198 -0
- smartpy/sexp.py +45 -0
- smartpy/smartpy-docker +65 -0
- smartpy/state.py +23 -0
- smartpy/stdlib/address_utils.spy +28 -0
- smartpy/stdlib/fixed_point.spy +148 -0
- smartpy/stdlib/list_utils.spy +271 -0
- smartpy/stdlib/math.spy +74 -0
- smartpy/stdlib/rational.spy +229 -0
- smartpy/stdlib/statistics.spy +21 -0
- smartpy/stdlib/string_utils.spy +350 -0
- smartpy/stdlib/utils.spy +90 -0
- smartpy/syntax.py +1821 -0
- smartpy/templates/admin_hand_over.py +158 -0
- smartpy/templates/admin_multisig.py +760 -0
- smartpy/templates/atomicSwap.py +79 -0
- smartpy/templates/baking_swap.py +323 -0
- smartpy/templates/bls12_381.py +226 -0
- smartpy/templates/bridge.py +81 -0
- smartpy/templates/calculator.py +64 -0
- smartpy/templates/calculator_main.spy +47 -0
- smartpy/templates/calculator_new.py +31 -0
- smartpy/templates/chain_id.py +20 -0
- smartpy/templates/check_dfs.py +45 -0
- smartpy/templates/chess.py +1078 -0
- smartpy/templates/chess_test_3_repeat.py +72 -0
- smartpy/templates/chess_test_checkmate.py +80 -0
- smartpy/templates/chess_test_game1.py +214 -0
- smartpy/templates/chess_test_game2.py +105 -0
- smartpy/templates/collatz.py +72 -0
- smartpy/templates/contract_metadata.py +61 -0
- smartpy/templates/create_contract.py +388 -0
- smartpy/templates/effectful_apply.py +172 -0
- smartpy/templates/escrow.py +75 -0
- smartpy/templates/events.py +20 -0
- smartpy/templates/example_cyclic1.spy +8 -0
- smartpy/templates/example_cyclic2.spy +7 -0
- smartpy/templates/example_cyclic3.spy +7 -0
- smartpy/templates/example_import.spy +8 -0
- smartpy/templates/fa1_2.py +444 -0
- smartpy/templates/fa2_1_lib.py +1457 -0
- smartpy/templates/fa2_1_lib_test_fungible.py +134 -0
- smartpy/templates/fa2_1_lib_test_nft.py +134 -0
- smartpy/templates/fa2_1_lib_test_single_asset.py +127 -0
- smartpy/templates/fa2_fungible_minimal.py +285 -0
- smartpy/templates/fa2_lib.py +941 -0
- smartpy/templates/fa2_lib_fungible.py +208 -0
- smartpy/templates/fa2_lib_nft.py +216 -0
- smartpy/templates/fa2_lib_single_asset.py +211 -0
- smartpy/templates/fa2_lib_test_fungible.py +142 -0
- smartpy/templates/fa2_lib_test_nft.py +138 -0
- smartpy/templates/fa2_lib_test_single_asset.py +141 -0
- smartpy/templates/fa2_lib_testing.py +2723 -0
- smartpy/templates/fa2_lib_testing_fa2_1_helpers.py +153 -0
- smartpy/templates/fa2_nft_minimal.py +266 -0
- smartpy/templates/fa2_types.py +131 -0
- smartpy/templates/fibonacci.py +158 -0
- smartpy/templates/fibonacci_view.py +35 -0
- smartpy/templates/fifo.py +46 -0
- smartpy/templates/fixed_precision.py +83 -0
- smartpy/templates/game_of_life.py +86 -0
- smartpy/templates/inheritance.py +176 -0
- smartpy/templates/inlineMichelson.py +190 -0
- smartpy/templates/instantiate_from_metadata.py +82 -0
- smartpy/templates/inter_contract_calls.py +108 -0
- smartpy/templates/invalid_mutation_tests.py +249 -0
- smartpy/templates/jingleBells.py +65 -0
- smartpy/templates/lambdas.py +256 -0
- smartpy/templates/layout.py +46 -0
- smartpy/templates/minikitties.py +184 -0
- smartpy/templates/minimal.py +20 -0
- smartpy/templates/multisig.py +170 -0
- smartpy/templates/multisig_action.py +149 -0
- smartpy/templates/multisig_lambda.py +153 -0
- smartpy/templates/multisig_view.py +111 -0
- smartpy/templates/nim.py +87 -0
- smartpy/templates/nimLift.py +104 -0
- smartpy/templates/price_feed.py +1305 -0
- smartpy/templates/price_feed_multisign_admin.py +824 -0
- smartpy/templates/rng.spy +43 -0
- smartpy/templates/self_entrypoint.py +47 -0
- smartpy/templates/send_back.py +21 -0
- smartpy/templates/send_twice.py +52 -0
- smartpy/templates/shuffle.py +29 -0
- smartpy/templates/storeValue.py +43 -0
- smartpy/templates/stringManipulations.py +164 -0
- smartpy/templates/sub_entrypoint.py +42 -0
- smartpy/templates/syntax.py +157 -0
- smartpy/templates/test_address_comparison.py +90 -0
- smartpy/templates/test_address_utils.py +66 -0
- smartpy/templates/test_annots.py +20 -0
- smartpy/templates/test_big.py +1015 -0
- smartpy/templates/test_bitwise.py +185 -0
- smartpy/templates/test_calls.py +189 -0
- smartpy/templates/test_check_signature.py +90 -0
- smartpy/templates/test_closer.py +22 -0
- smartpy/templates/test_compare.py +81 -0
- smartpy/templates/test_compute_exception.py +49 -0
- smartpy/templates/test_conditionals.py +23 -0
- smartpy/templates/test_contract_hierarchy.py +120 -0
- smartpy/templates/test_convert.py +46 -0
- smartpy/templates/test_deprecated_syntax.py +24 -0
- smartpy/templates/test_div.py +66 -0
- smartpy/templates/test_docstrings.py +43 -0
- smartpy/templates/test_effects.py +406 -0
- smartpy/templates/test_empty.py +37 -0
- smartpy/templates/test_errors.py +172 -0
- smartpy/templates/test_errors_metadata.py +216 -0
- smartpy/templates/test_eval_order.py +424 -0
- smartpy/templates/test_factory_balance.py +24 -0
- smartpy/templates/test_failwith.py +58 -0
- smartpy/templates/test_fixed_point.py +78 -0
- smartpy/templates/test_for.py +119 -0
- smartpy/templates/test_hash_functions.py +62 -0
- smartpy/templates/test_import.py +21 -0
- smartpy/templates/test_imported.py +22 -0
- smartpy/templates/test_inheritance.py +61 -0
- smartpy/templates/test_initial_balance.py +41 -0
- smartpy/templates/test_inner_invalid.py +38 -0
- smartpy/templates/test_keywords.py +18 -0
- smartpy/templates/test_list_utils.py +233 -0
- smartpy/templates/test_lists.py +187 -0
- smartpy/templates/test_local_record.py +21 -0
- smartpy/templates/test_logs.py +42 -0
- smartpy/templates/test_maps.py +64 -0
- smartpy/templates/test_match.py +80 -0
- smartpy/templates/test_math.py +51 -0
- smartpy/templates/test_michelson_error.py +22 -0
- smartpy/templates/test_min.py +48 -0
- smartpy/templates/test_misc.py +51 -0
- smartpy/templates/test_modify.py +121 -0
- smartpy/templates/test_modules1.py +56 -0
- smartpy/templates/test_modules10.py +35 -0
- smartpy/templates/test_modules11.py +52 -0
- smartpy/templates/test_modules2.py +29 -0
- smartpy/templates/test_modules3.py +79 -0
- smartpy/templates/test_modules4.py +24 -0
- smartpy/templates/test_modules5.py +31 -0
- smartpy/templates/test_modules6.py +145 -0
- smartpy/templates/test_modules7.py +54 -0
- smartpy/templates/test_modules8.py +65 -0
- smartpy/templates/test_modules9.py +25 -0
- smartpy/templates/test_mutez.py +62 -0
- smartpy/templates/test_never.py +29 -0
- smartpy/templates/test_new_private.py +24 -0
- smartpy/templates/test_new_syntax.py +243 -0
- smartpy/templates/test_onchain_views.py +243 -0
- smartpy/templates/test_onchain_views_not_found.py +37 -0
- smartpy/templates/test_operation_order.py +80 -0
- smartpy/templates/test_option.py +40 -0
- smartpy/templates/test_pack.py +689 -0
- smartpy/templates/test_pattern_matching.py +92 -0
- smartpy/templates/test_poly.py +22 -0
- smartpy/templates/test_private_lambda.py +82 -0
- smartpy/templates/test_rational.py +131 -0
- smartpy/templates/test_rng.py +27 -0
- smartpy/templates/test_runtime_errors.py +60 -0
- smartpy/templates/test_scenario.py +172 -0
- smartpy/templates/test_scenario_context.py +48 -0
- smartpy/templates/test_self_data_set.py +25 -0
- smartpy/templates/test_send.py +63 -0
- smartpy/templates/test_set_contract_data.py +58 -0
- smartpy/templates/test_statistics.py +31 -0
- smartpy/templates/test_string_utils.py +147 -0
- smartpy/templates/test_threefry.py +34 -0
- smartpy/templates/test_ticket.py +173 -0
- smartpy/templates/test_timestamp.py +37 -0
- smartpy/templates/test_trace.py +18 -0
- smartpy/templates/test_transfers_to_accounts.py +38 -0
- smartpy/templates/test_type_abbrevs.py +63 -0
- smartpy/templates/test_type_errors.py +713 -0
- smartpy/templates/test_unification.py +23 -0
- smartpy/templates/test_variant.py +87 -0
- smartpy/templates/test_view_inheritance.py +57 -0
- smartpy/templates/test_void.py +20 -0
- smartpy/templates/test_with_storage.py +101 -0
- smartpy/templates/test_xss.py +42 -0
- smartpy/templates/threefry.spy +372 -0
- smartpy/templates/tictactoe.py +120 -0
- smartpy/templates/tictactoeFactory.py +146 -0
- smartpy/templates/toto.py +26 -0
- smartpy/templates/trilitech_tutorial_fa2_fungible_part1_complete.py +140 -0
- smartpy/templates/trilitech_tutorial_fa2_fungible_part2_complete.py +216 -0
- smartpy/templates/trilitech_tutorial_fa2_fungible_part3_complete.py +250 -0
- smartpy/templates/trilitech_tutorial_fa2_fungible_part4_complete.py +313 -0
- smartpy/templates/upgradable_lambdas.py +53 -0
- smartpy/templates/voting.py +28 -0
- smartpy/templates/voting_power.py +30 -0
- smartpy/templates/welcome.py +52 -0
- smartpy/types.py +391 -0
- smartpy/utils.py +133 -0
- smartpy_tezos-0.0.1.dist-info/LICENSE.md +21 -0
- smartpy_tezos-0.0.1.dist-info/METADATA +52 -0
- smartpy_tezos-0.0.1.dist-info/RECORD +201 -0
- smartpy_tezos-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import smartpy as sp
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@sp.module
|
|
5
|
+
def main():
|
|
6
|
+
tv: type = sp.variant(a=sp.int, b=sp.int)
|
|
7
|
+
|
|
8
|
+
t1: type = sp.lambda_[sp.int, tv]
|
|
9
|
+
t2: type = sp.lambda_[sp.int, sp.variant(a=sp.int)]
|
|
10
|
+
int_to_string: type = sp.lambda_[sp.int, sp.string]
|
|
11
|
+
|
|
12
|
+
def list_equal(lists):
|
|
13
|
+
(l1, l2) = lists
|
|
14
|
+
return sp.len(l1) == sp.len(l2) and sum(l1) == sum(l2)
|
|
15
|
+
|
|
16
|
+
class Pack(sp.Contract):
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self.data.unit = sp.bytes("0x05030b")
|
|
19
|
+
self.data.true = sp.bytes("0x05030a")
|
|
20
|
+
self.data.false = sp.bytes("0x050303")
|
|
21
|
+
self.data.mutez_0 = sp.bytes("0x050000")
|
|
22
|
+
self.data.mutez_1 = sp.bytes("0x050001")
|
|
23
|
+
self.data.mutez_2 = sp.bytes("0x050002")
|
|
24
|
+
self.data.mutez_3 = sp.bytes("0x050003")
|
|
25
|
+
self.data.mutez_10 = sp.bytes("0x05000a")
|
|
26
|
+
self.data.mutez_10_000 = sp.bytes("0x0500909c01")
|
|
27
|
+
self.data.mutez_1_000_000 = sp.bytes("0x050080897a")
|
|
28
|
+
self.data.mutez_1_000_000_000_000 = sp.bytes("0x050080c0a8ca9a3a")
|
|
29
|
+
self.data.nat_0 = sp.bytes("0x050000")
|
|
30
|
+
self.data.nat_1 = sp.bytes("0x050001")
|
|
31
|
+
self.data.nat_2 = sp.bytes("0x050002")
|
|
32
|
+
self.data.nat_3 = sp.bytes("0x050003")
|
|
33
|
+
self.data.nat_10 = sp.bytes("0x05000a")
|
|
34
|
+
self.data.nat_10_000 = sp.bytes("0x0500909c01")
|
|
35
|
+
self.data.nat_1_000_000 = sp.bytes("0x050080897a")
|
|
36
|
+
self.data.nat_1_000_000_000_000 = sp.bytes("0x050080c0a8ca9a3a")
|
|
37
|
+
self.data.int_0 = sp.bytes("0x050000")
|
|
38
|
+
self.data.int_1 = sp.bytes("0x050001")
|
|
39
|
+
self.data.int_2 = sp.bytes("0x050002")
|
|
40
|
+
self.data.int_3 = sp.bytes("0x050003")
|
|
41
|
+
self.data.int_10 = sp.bytes("0x05000a")
|
|
42
|
+
self.data.int_10_000 = sp.bytes("0x0500909c01")
|
|
43
|
+
self.data.int_1_000_000 = sp.bytes("0x050080897a")
|
|
44
|
+
self.data.int_1_000_000_000_000 = sp.bytes("0x050080c0a8ca9a3a")
|
|
45
|
+
self.data.int_minus_0 = sp.bytes("0x050000")
|
|
46
|
+
self.data.int_minus_1 = sp.bytes("0x050041")
|
|
47
|
+
self.data.int_minus_2 = sp.bytes("0x050042")
|
|
48
|
+
self.data.int_minus_3 = sp.bytes("0x050043")
|
|
49
|
+
self.data.int_minus_10 = sp.bytes("0x05004a")
|
|
50
|
+
self.data.int_minus_10_000 = sp.bytes("0x0500d09c01")
|
|
51
|
+
self.data.int_minus_1_000_000 = sp.bytes("0x0500c0897a")
|
|
52
|
+
self.data.int_minus_1_000_000_000_000 = sp.bytes("0x0500c0c0a8ca9a3a")
|
|
53
|
+
self.data.string_ = sp.bytes("0x050100000000")
|
|
54
|
+
self.data.string_a = sp.bytes("0x05010000000161")
|
|
55
|
+
self.data.string_ab = sp.bytes("0x0501000000026162")
|
|
56
|
+
self.data.string_abc = sp.bytes("0x050100000003616263")
|
|
57
|
+
self.data.bytes_0x = sp.bytes("0x050a00000000")
|
|
58
|
+
self.data.bytes_0x00 = sp.bytes("0x050a0000000100")
|
|
59
|
+
self.data.bytes_0xab00 = sp.bytes("0x050a00000002ab00")
|
|
60
|
+
self.data.pair_int_1_int_2 = sp.bytes("0x05070700010002")
|
|
61
|
+
self.data.pair_string_a_true = sp.bytes("0x050707010000000161030a")
|
|
62
|
+
self.data.timestamp_123 = sp.bytes("0x0500bb01")
|
|
63
|
+
self.data.signature_sig = sp.bytes(
|
|
64
|
+
"0x050a0000004027bcc456b12981bacfbf9755c589c16772da5200656386f34c46ee2a70a9c07be36268ce666894a5e8a0828027b6fa1a7a084a5ffa24208cc1dfec07d6f66e0f"
|
|
65
|
+
)
|
|
66
|
+
self.data.signature_spsig = sp.bytes(
|
|
67
|
+
"0x050a00000040865b0ceaa2decd64fea1b7e0e97d6ae8035125d821ebe99d7d5c8a559f36fdd43388a570e475011f6d2bbef184ece9bafbf0ac12157f7257988e9575ae2cbca9"
|
|
68
|
+
)
|
|
69
|
+
self.data.signature_p2sig = sp.bytes(
|
|
70
|
+
"0x050a00000040e7b25662eb9bb1e92ef7cb20c2fcaca120eccbe2d6af7511c2e510eb586ca8612d9dfe26bc7882a33b29b8c9706a04124f98dd281f1622d8da50db7a5cd4ab43"
|
|
71
|
+
)
|
|
72
|
+
self.data.signature = sp.bytes(
|
|
73
|
+
"0x050a000000404d6738931b59605ca0449b7b76a01d210ace9220051821ecf43382a7024ed99063c5bedb85c81b919d33a213c6d8fb47f2c9b4deaf6f68f56dee038ea739740f"
|
|
74
|
+
)
|
|
75
|
+
self.data.address_tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA = sp.bytes(
|
|
76
|
+
"0x050a000000160000db8fc132cf9624febe1675fbfd0c0fcdd7655f23"
|
|
77
|
+
)
|
|
78
|
+
self.data.address_tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93 = sp.bytes(
|
|
79
|
+
"0x050a0000001600014b7c404fd4fbcf931cde0a8971caf76f53c8e5c0"
|
|
80
|
+
)
|
|
81
|
+
self.data.address_tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K = sp.bytes(
|
|
82
|
+
"0x050a0000001600026e08178148d348cb59efffbdb403ca546b13304e"
|
|
83
|
+
)
|
|
84
|
+
self.data.address_tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc = sp.bytes(
|
|
85
|
+
"0x050a000000160003e0b0f0c1fa4d9d46c8281d3e98900f942283b15c"
|
|
86
|
+
)
|
|
87
|
+
self.data.key_hash_tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA = sp.bytes(
|
|
88
|
+
"0x050a0000001500db8fc132cf9624febe1675fbfd0c0fcdd7655f23"
|
|
89
|
+
)
|
|
90
|
+
self.data.key_hash_tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93 = sp.bytes(
|
|
91
|
+
"0x050a00000015014b7c404fd4fbcf931cde0a8971caf76f53c8e5c0"
|
|
92
|
+
)
|
|
93
|
+
self.data.key_hash_tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K = sp.bytes(
|
|
94
|
+
"0x050a00000015026e08178148d348cb59efffbdb403ca546b13304e"
|
|
95
|
+
)
|
|
96
|
+
self.data.key_hash_tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc = sp.bytes(
|
|
97
|
+
"0x050a0000001503e0b0f0c1fa4d9d46c8281d3e98900f942283b15c"
|
|
98
|
+
)
|
|
99
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy = sp.bytes(
|
|
100
|
+
"0x050a00000016019142eb01374f37f03023eefc82f2ede96e8ae51500"
|
|
101
|
+
)
|
|
102
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy_ = sp.bytes(
|
|
103
|
+
"0x050a00000016019142eb01374f37f03023eefc82f2ede96e8ae51500"
|
|
104
|
+
)
|
|
105
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy_foo = sp.bytes(
|
|
106
|
+
"0x050a00000019019142eb01374f37f03023eefc82f2ede96e8ae51500666f6f"
|
|
107
|
+
)
|
|
108
|
+
self.data.list_int_0_to_6 = sp.bytes(
|
|
109
|
+
"0x05020000000e0000000100020003000400050006"
|
|
110
|
+
)
|
|
111
|
+
self.data.list_int_range_0_1 = sp.bytes("0x0502000000020000")
|
|
112
|
+
self.data.list_int_range_0_2 = sp.bytes("0x05020000000400000001")
|
|
113
|
+
self.data.list_int_range_0_3 = sp.bytes("0x050200000006000000010002")
|
|
114
|
+
self.data.list_int_range_0_4 = sp.bytes("0x0502000000080000000100020003")
|
|
115
|
+
self.data.list_int_range_0_5 = sp.bytes(
|
|
116
|
+
"0x05020000000a00000001000200030004"
|
|
117
|
+
)
|
|
118
|
+
self.data.list_int_range_0_6 = sp.bytes(
|
|
119
|
+
"0x05020000000c000000010002000300040005"
|
|
120
|
+
)
|
|
121
|
+
self.data.list_int_range_0_7 = sp.bytes(
|
|
122
|
+
"0x05020000000e0000000100020003000400050006"
|
|
123
|
+
)
|
|
124
|
+
self.data.set_int_1_to_4 = sp.bytes("0x0502000000080001000200030004")
|
|
125
|
+
|
|
126
|
+
self.data.lambda_x_plus_2 = sp.bytes("0x0502000000080743035b00020312")
|
|
127
|
+
self.data.lambda_f1 = sp.bytes(
|
|
128
|
+
"0x05020000001b03210316072c020000000903200743035b00bb0102000000020317"
|
|
129
|
+
)
|
|
130
|
+
self.data.lambda_f2 = sp.bytes(
|
|
131
|
+
"0x05020000002703210316072c020000000903200743035b00bb01020000000e032105290004034c052900030312"
|
|
132
|
+
)
|
|
133
|
+
self.data.lambda_f3 = sp.bytes(
|
|
134
|
+
"0x05020000004c0743035b000007430368010000000141052100030325072c0200000022034c0570000203190325072c020000000c03200743036801000000014202000000000200000008034c0320034c0320"
|
|
135
|
+
)
|
|
136
|
+
self.data.lambda_michelson = sp.bytes(
|
|
137
|
+
"0x05020000000c03210743035b002a0312033a"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
self.data.list_string = sp.bytes(
|
|
141
|
+
"05020000002201000000057468697320010000000369732001000000026120010000000474657374"
|
|
142
|
+
)
|
|
143
|
+
self.data.map_string_int = sp.bytes(
|
|
144
|
+
"05020000000f07040100000006616e73776572002a"
|
|
145
|
+
)
|
|
146
|
+
self.data.record_string_int = sp.bytes("05070701000000047465737400b914")
|
|
147
|
+
self.data.variant_a_string_b_nat = sp.bytes("050505010000000474657374")
|
|
148
|
+
self.data.option_string = sp.bytes("050509010000000568656c6c6f")
|
|
149
|
+
self.data.none_string = sp.bytes("050306")
|
|
150
|
+
|
|
151
|
+
# Activate when sapling is implemented
|
|
152
|
+
# self.data.sapling_transaction = sp.bytes("0x00")
|
|
153
|
+
# self.data.sapling_state = sp.bytes("0x00")
|
|
154
|
+
|
|
155
|
+
self.data.chain_id = sp.bytes("050a00000004af1864d9") # NetXnHfVqm9iesp
|
|
156
|
+
self.data.level_2548242 = sp.bytes("05009288b702") # 2548242
|
|
157
|
+
|
|
158
|
+
@sp.private()
|
|
159
|
+
def f1(self, x):
|
|
160
|
+
if x.a:
|
|
161
|
+
return 123
|
|
162
|
+
else:
|
|
163
|
+
return x.b
|
|
164
|
+
|
|
165
|
+
@sp.private()
|
|
166
|
+
def f2(self, x):
|
|
167
|
+
sp.cast(x.b, sp.int)
|
|
168
|
+
if x.a:
|
|
169
|
+
return 123
|
|
170
|
+
else:
|
|
171
|
+
return x.b + x.c
|
|
172
|
+
|
|
173
|
+
@sp.private()
|
|
174
|
+
def f3(self, x):
|
|
175
|
+
y = 0
|
|
176
|
+
r = "A"
|
|
177
|
+
if x == 0:
|
|
178
|
+
if x == y:
|
|
179
|
+
r = "B"
|
|
180
|
+
return r
|
|
181
|
+
|
|
182
|
+
@sp.entrypoint
|
|
183
|
+
def pack(self, signature_sig, signature_spsig, signature_p2sig, s):
|
|
184
|
+
sp.cast(signature_sig, sp.signature)
|
|
185
|
+
sp.cast(signature_spsig, sp.signature)
|
|
186
|
+
sp.cast(signature_p2sig, sp.signature)
|
|
187
|
+
sp.cast(s, sp.signature)
|
|
188
|
+
assert self.data.unit == sp.pack(())
|
|
189
|
+
assert self.data.true == sp.pack(True)
|
|
190
|
+
assert self.data.false == sp.pack(False)
|
|
191
|
+
assert self.data.mutez_0 == sp.pack(sp.mutez(0))
|
|
192
|
+
assert self.data.mutez_1 == sp.pack(sp.mutez(1))
|
|
193
|
+
assert self.data.mutez_2 == sp.pack(sp.mutez(2))
|
|
194
|
+
assert self.data.mutez_3 == sp.pack(sp.mutez(3))
|
|
195
|
+
assert self.data.mutez_10 == sp.pack(sp.mutez(10))
|
|
196
|
+
assert self.data.mutez_10_000 == sp.pack(sp.mutez(10000))
|
|
197
|
+
assert self.data.mutez_1_000_000 == sp.pack(sp.mutez(1000000))
|
|
198
|
+
assert self.data.mutez_1_000_000_000_000 == sp.pack(sp.mutez(1000000000000))
|
|
199
|
+
assert self.data.nat_0 == sp.pack(sp.nat(0))
|
|
200
|
+
assert self.data.nat_1 == sp.pack(sp.nat(1))
|
|
201
|
+
assert self.data.nat_2 == sp.pack(sp.nat(2))
|
|
202
|
+
assert self.data.nat_3 == sp.pack(sp.nat(3))
|
|
203
|
+
assert self.data.nat_10 == sp.pack(sp.nat(10))
|
|
204
|
+
assert self.data.nat_10_000 == sp.pack(sp.nat(10000))
|
|
205
|
+
assert self.data.nat_1_000_000 == sp.pack(sp.nat(1000000))
|
|
206
|
+
assert self.data.nat_1_000_000_000_000 == sp.pack(sp.nat(1000000000000))
|
|
207
|
+
assert self.data.int_0 == sp.pack(sp.int(0))
|
|
208
|
+
assert self.data.int_1 == sp.pack(sp.int(1))
|
|
209
|
+
assert self.data.int_2 == sp.pack(sp.int(2))
|
|
210
|
+
assert self.data.int_3 == sp.pack(sp.int(3))
|
|
211
|
+
assert self.data.int_10 == sp.pack(sp.int(10))
|
|
212
|
+
assert self.data.int_10_000 == sp.pack(sp.int(10000))
|
|
213
|
+
assert self.data.int_1_000_000 == sp.pack(sp.int(1000000))
|
|
214
|
+
assert self.data.int_1_000_000_000_000 == sp.pack(sp.int(1000000000000))
|
|
215
|
+
assert self.data.int_minus_0 == sp.pack(sp.int(-0))
|
|
216
|
+
assert self.data.int_minus_1 == sp.pack(sp.int(-1))
|
|
217
|
+
assert self.data.int_minus_2 == sp.pack(sp.int(-2))
|
|
218
|
+
assert self.data.int_minus_3 == sp.pack(sp.int(-3))
|
|
219
|
+
assert self.data.int_minus_10 == sp.pack(sp.int(-10))
|
|
220
|
+
assert self.data.int_minus_10_000 == sp.pack(sp.int(-10000))
|
|
221
|
+
assert self.data.int_minus_1_000_000 == sp.pack(sp.int(-1000000))
|
|
222
|
+
assert self.data.int_minus_1_000_000_000_000 == sp.pack(
|
|
223
|
+
sp.int(-1000000000000)
|
|
224
|
+
)
|
|
225
|
+
assert self.data.string_ == sp.pack("")
|
|
226
|
+
assert self.data.string_a == sp.pack("a")
|
|
227
|
+
assert self.data.string_ab == sp.pack("ab")
|
|
228
|
+
assert self.data.string_abc == sp.pack("abc")
|
|
229
|
+
assert self.data.bytes_0x == sp.pack(sp.bytes("0x"))
|
|
230
|
+
assert self.data.bytes_0x00 == sp.pack(sp.bytes("0x00"))
|
|
231
|
+
assert self.data.bytes_0xab00 == sp.pack(sp.bytes("0xab00"))
|
|
232
|
+
assert self.data.pair_int_1_int_2 == sp.pack((1, 2))
|
|
233
|
+
assert self.data.pair_string_a_true == sp.pack(("a", True))
|
|
234
|
+
assert self.data.timestamp_123 == sp.pack(sp.timestamp(123))
|
|
235
|
+
# assert self.data.signature_sig == sp.pack(sp.signature("sigTBpkXw6tC72L2nJ2r2Jm5iB6uidTWqoMNd4oEawUbGBf5mHVfKawFYL8X8MJECpL73oBnfujyUZNLK2LQWD1FaCkYMP4j"))
|
|
236
|
+
# assert self.data.signature_spsig == sp.pack(sp.signature("spsig1PPUFZucuAQybs5wsqsNQ68QNgFaBnVKMFaoZZfi1BtNnuCAWnmL9wVy5HfHkR6AeodjVGxpBVVSYcJKyMURn6K1yknYLm"))
|
|
237
|
+
# assert self.data.signature_p2sig == sp.pack(sp.signature("p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1FhfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ"))
|
|
238
|
+
# assert self.data.signature == sp.pack(s)
|
|
239
|
+
|
|
240
|
+
assert self.data.signature_sig == sp.pack(signature_sig)
|
|
241
|
+
# assert self.data.signature_spsig == sp.pack(signature_spsig)
|
|
242
|
+
# assert self.data.signature_p2sig == sp.pack(signature_p2sig)
|
|
243
|
+
# self.data.signature = sp.pack(s)
|
|
244
|
+
assert self.data.address_tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA == sp.pack(
|
|
245
|
+
sp.address("tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA")
|
|
246
|
+
)
|
|
247
|
+
assert self.data.address_tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93 == sp.pack(
|
|
248
|
+
sp.address("tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93")
|
|
249
|
+
)
|
|
250
|
+
assert self.data.address_tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K == sp.pack(
|
|
251
|
+
sp.address("tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K")
|
|
252
|
+
)
|
|
253
|
+
assert self.data.key_hash_tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA == sp.pack(
|
|
254
|
+
sp.key_hash("tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA")
|
|
255
|
+
)
|
|
256
|
+
assert self.data.key_hash_tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93 == sp.pack(
|
|
257
|
+
sp.key_hash("tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93")
|
|
258
|
+
)
|
|
259
|
+
assert self.data.key_hash_tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K == sp.pack(
|
|
260
|
+
sp.key_hash("tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K")
|
|
261
|
+
)
|
|
262
|
+
# TODO activate when tz4 are implemented
|
|
263
|
+
# assert self.data.key_hash_tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc == sp.pack(sp.key_hash("tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc"))
|
|
264
|
+
assert self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy == sp.pack(
|
|
265
|
+
sp.address("KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy")
|
|
266
|
+
)
|
|
267
|
+
assert self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy_ == sp.pack(
|
|
268
|
+
sp.address("KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy%")
|
|
269
|
+
)
|
|
270
|
+
assert (
|
|
271
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy_foo
|
|
272
|
+
== sp.pack(sp.address("KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy%foo"))
|
|
273
|
+
)
|
|
274
|
+
assert self.data.list_int_0_to_6 == sp.pack([0, 1, 2, 3, 4, 5, 6])
|
|
275
|
+
assert self.data.list_int_range_0_1 == sp.pack(range(0, 1))
|
|
276
|
+
assert self.data.list_int_range_0_2 == sp.pack(range(0, 2))
|
|
277
|
+
assert self.data.list_int_range_0_3 == sp.pack(range(0, 3))
|
|
278
|
+
assert self.data.list_int_range_0_4 == sp.pack(range(0, 4))
|
|
279
|
+
assert self.data.list_int_range_0_5 == sp.pack(range(0, 5))
|
|
280
|
+
assert self.data.list_int_range_0_6 == sp.pack(range(0, 6))
|
|
281
|
+
assert self.data.list_int_range_0_7 == sp.pack(range(0, 7))
|
|
282
|
+
assert self.data.set_int_1_to_4 == sp.pack({1, 2, 3, 4})
|
|
283
|
+
|
|
284
|
+
assert self.data.lambda_x_plus_2 == sp.pack(lambda x: x + 2)
|
|
285
|
+
assert self.data.lambda_f1 == sp.pack(self.f1)
|
|
286
|
+
assert self.data.lambda_f2 == sp.pack(self.f2)
|
|
287
|
+
assert self.data.lambda_f3 == sp.pack(self.f3)
|
|
288
|
+
assert self.data.lambda_michelson == sp.pack(
|
|
289
|
+
lambda x: sp.michelson(
|
|
290
|
+
"DUP; PUSH int 42; ADD; MUL", [sp.int], [sp.int], x
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
assert self.data.list_string == sp.pack(["this ", "is ", "a ", "test"])
|
|
295
|
+
assert self.data.map_string_int == sp.pack({"answer": 42})
|
|
296
|
+
assert self.data.record_string_int == sp.pack(sp.record(a="test", b=1337))
|
|
297
|
+
assert self.data.variant_a_string_b_nat == sp.pack(
|
|
298
|
+
sp.cast(sp.variant.a("test"), sp.variant(a=sp.string, b=sp.nat))
|
|
299
|
+
)
|
|
300
|
+
assert self.data.option_string == sp.pack(
|
|
301
|
+
sp.cast(sp.Some("hello"), sp.option[sp.string])
|
|
302
|
+
)
|
|
303
|
+
assert self.data.none_string == sp.pack(sp.cast(None, sp.option[sp.string]))
|
|
304
|
+
|
|
305
|
+
# assert self.data.chain_id == sp.pack(sp.chain_id)
|
|
306
|
+
# TODO when chain_id creation is implemented
|
|
307
|
+
# assert self.data.chain_id == sp.chain_id("NetXnHfVqm9iesp")
|
|
308
|
+
assert self.data.level_2548242 == sp.pack(sp.level)
|
|
309
|
+
assert self.data.level_2548242 == sp.pack(sp.nat(2548242))
|
|
310
|
+
|
|
311
|
+
# TODO: activate when sapling is implemented
|
|
312
|
+
# assert self.data.sapling_transaction = sp.pack(...)
|
|
313
|
+
# assert self.data.sapling_state = sp.pack(...)
|
|
314
|
+
|
|
315
|
+
@sp.entrypoint
|
|
316
|
+
def unpack(self, signature_sig, signature_spsig, signature_p2sig, s):
|
|
317
|
+
sp.cast(signature_sig, sp.signature)
|
|
318
|
+
sp.cast(signature_spsig, sp.signature)
|
|
319
|
+
sp.cast(signature_p2sig, sp.signature)
|
|
320
|
+
sp.cast(s, sp.signature)
|
|
321
|
+
assert sp.unpack(self.data.unit, sp.unit).unwrap_some() == ()
|
|
322
|
+
assert sp.unpack(self.data.true, sp.bool).unwrap_some() == True
|
|
323
|
+
assert sp.unpack(self.data.false, sp.bool).unwrap_some() == False
|
|
324
|
+
assert sp.unpack(self.data.mutez_0, sp.mutez).unwrap_some() == sp.mutez(0)
|
|
325
|
+
assert sp.unpack(self.data.mutez_1, sp.mutez).unwrap_some() == sp.mutez(1)
|
|
326
|
+
assert sp.unpack(self.data.mutez_2, sp.mutez).unwrap_some() == sp.mutez(2)
|
|
327
|
+
assert sp.unpack(self.data.mutez_3, sp.mutez).unwrap_some() == sp.mutez(3)
|
|
328
|
+
assert sp.unpack(self.data.mutez_10, sp.mutez).unwrap_some() == sp.mutez(10)
|
|
329
|
+
assert sp.unpack(
|
|
330
|
+
self.data.mutez_10_000, sp.mutez
|
|
331
|
+
).unwrap_some() == sp.mutez(10000)
|
|
332
|
+
assert sp.unpack(
|
|
333
|
+
self.data.mutez_1_000_000, sp.mutez
|
|
334
|
+
).unwrap_some() == sp.mutez(1000000)
|
|
335
|
+
assert sp.unpack(
|
|
336
|
+
self.data.mutez_1_000_000_000_000, sp.mutez
|
|
337
|
+
).unwrap_some() == sp.mutez(1000000000000)
|
|
338
|
+
assert sp.unpack(self.data.nat_0, sp.nat).unwrap_some() == sp.nat(0)
|
|
339
|
+
assert sp.unpack(self.data.nat_1, sp.nat).unwrap_some() == sp.nat(1)
|
|
340
|
+
assert sp.unpack(self.data.nat_2, sp.nat).unwrap_some() == sp.nat(2)
|
|
341
|
+
assert sp.unpack(self.data.nat_3, sp.nat).unwrap_some() == sp.nat(3)
|
|
342
|
+
assert sp.unpack(self.data.nat_10, sp.nat).unwrap_some() == sp.nat(10)
|
|
343
|
+
assert sp.unpack(self.data.nat_10_000, sp.nat).unwrap_some() == sp.nat(
|
|
344
|
+
10000
|
|
345
|
+
)
|
|
346
|
+
assert sp.unpack(self.data.nat_1_000_000, sp.nat).unwrap_some() == sp.nat(
|
|
347
|
+
1000000
|
|
348
|
+
)
|
|
349
|
+
assert sp.unpack(
|
|
350
|
+
self.data.nat_1_000_000_000_000, sp.nat
|
|
351
|
+
).unwrap_some() == sp.nat(1000000000000)
|
|
352
|
+
assert sp.unpack(self.data.int_0, sp.int).unwrap_some() == sp.int(0)
|
|
353
|
+
assert sp.unpack(self.data.int_1, sp.int).unwrap_some() == sp.int(1)
|
|
354
|
+
assert sp.unpack(self.data.int_2, sp.int).unwrap_some() == sp.int(2)
|
|
355
|
+
assert sp.unpack(self.data.int_3, sp.int).unwrap_some() == sp.int(3)
|
|
356
|
+
assert sp.unpack(self.data.int_10, sp.int).unwrap_some() == sp.int(10)
|
|
357
|
+
assert sp.unpack(self.data.int_10_000, sp.int).unwrap_some() == sp.int(
|
|
358
|
+
10000
|
|
359
|
+
)
|
|
360
|
+
assert sp.unpack(self.data.int_1_000_000, sp.int).unwrap_some() == sp.int(
|
|
361
|
+
1000000
|
|
362
|
+
)
|
|
363
|
+
assert sp.unpack(
|
|
364
|
+
self.data.int_1_000_000_000_000, sp.int
|
|
365
|
+
).unwrap_some() == sp.int(1000000000000)
|
|
366
|
+
assert sp.unpack(self.data.int_minus_0, sp.int).unwrap_some() == sp.int(-0)
|
|
367
|
+
assert sp.unpack(self.data.int_minus_1, sp.int).unwrap_some() == sp.int(-1)
|
|
368
|
+
assert sp.unpack(self.data.int_minus_2, sp.int).unwrap_some() == sp.int(-2)
|
|
369
|
+
assert sp.unpack(self.data.int_minus_3, sp.int).unwrap_some() == sp.int(-3)
|
|
370
|
+
assert sp.unpack(self.data.int_minus_10, sp.int).unwrap_some() == sp.int(
|
|
371
|
+
-10
|
|
372
|
+
)
|
|
373
|
+
assert sp.unpack(
|
|
374
|
+
self.data.int_minus_10_000, sp.int
|
|
375
|
+
).unwrap_some() == sp.int(-10000)
|
|
376
|
+
assert sp.unpack(
|
|
377
|
+
self.data.int_minus_1_000_000, sp.int
|
|
378
|
+
).unwrap_some() == sp.int(-1000000)
|
|
379
|
+
assert sp.unpack(
|
|
380
|
+
self.data.int_minus_1_000_000_000_000, sp.int
|
|
381
|
+
).unwrap_some() == sp.int(-1000000000000)
|
|
382
|
+
assert sp.unpack(self.data.string_, sp.string).unwrap_some() == ""
|
|
383
|
+
assert sp.unpack(self.data.string_a, sp.string).unwrap_some() == "a"
|
|
384
|
+
assert sp.unpack(self.data.string_ab, sp.string).unwrap_some() == "ab"
|
|
385
|
+
assert sp.unpack(self.data.string_abc, sp.string).unwrap_some() == "abc"
|
|
386
|
+
assert sp.unpack(self.data.bytes_0x, sp.bytes).unwrap_some() == sp.bytes(
|
|
387
|
+
"0x"
|
|
388
|
+
)
|
|
389
|
+
assert sp.unpack(self.data.bytes_0x00, sp.bytes).unwrap_some() == sp.bytes(
|
|
390
|
+
"0x00"
|
|
391
|
+
)
|
|
392
|
+
assert sp.unpack(
|
|
393
|
+
self.data.bytes_0xab00, sp.bytes
|
|
394
|
+
).unwrap_some() == sp.bytes("0xab00")
|
|
395
|
+
assert sp.unpack(
|
|
396
|
+
self.data.pair_int_1_int_2, sp.pair[sp.int, sp.int]
|
|
397
|
+
).unwrap_some() == (1, 2)
|
|
398
|
+
assert sp.unpack(
|
|
399
|
+
self.data.pair_string_a_true, sp.pair[sp.string, sp.bool]
|
|
400
|
+
).unwrap_some() == ("a", True)
|
|
401
|
+
assert sp.unpack(
|
|
402
|
+
self.data.timestamp_123, sp.timestamp
|
|
403
|
+
).unwrap_some() == sp.timestamp(123)
|
|
404
|
+
assert (
|
|
405
|
+
sp.unpack(self.data.signature_sig, sp.signature).unwrap_some()
|
|
406
|
+
== signature_sig
|
|
407
|
+
)
|
|
408
|
+
# assert sp.unpack(self.data.signature_spsig, sp.signature).unwrap_some() == signature_spsig
|
|
409
|
+
# assert sp.unpack(self.data.signature_p2sig, sp.signature).unwrap_some() == signature_p2sig
|
|
410
|
+
# assert sp.unpack(self.data.signature, sp.signature).unwrap_some() == s
|
|
411
|
+
assert sp.unpack(
|
|
412
|
+
self.data.address_tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA, sp.address
|
|
413
|
+
).unwrap_some() == sp.address("tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA")
|
|
414
|
+
assert sp.unpack(
|
|
415
|
+
self.data.address_tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93, sp.address
|
|
416
|
+
).unwrap_some() == sp.address("tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93")
|
|
417
|
+
assert sp.unpack(
|
|
418
|
+
self.data.address_tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K, sp.address
|
|
419
|
+
).unwrap_some() == sp.address("tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K")
|
|
420
|
+
# TODO activate when tz4 are implemented
|
|
421
|
+
# assert sp.unpack(self.data.address_tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc, sp.address).unwrap_some() == sp.address("tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc")
|
|
422
|
+
assert sp.unpack(
|
|
423
|
+
self.data.key_hash_tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA, sp.key_hash
|
|
424
|
+
).unwrap_some() == sp.key_hash("tz1fextP23D6Ph2zeGTP8EwkP5Y8TufeFCHA")
|
|
425
|
+
assert sp.unpack(
|
|
426
|
+
self.data.key_hash_tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93, sp.key_hash
|
|
427
|
+
).unwrap_some() == sp.key_hash("tz2FCNBrERXtaTtNX6iimR1UJ5JSDxvdHM93")
|
|
428
|
+
assert sp.unpack(
|
|
429
|
+
self.data.key_hash_tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K, sp.key_hash
|
|
430
|
+
).unwrap_some() == sp.key_hash("tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K")
|
|
431
|
+
# TODO activate when tz4 are implemented
|
|
432
|
+
# assert sp.unpack(self.data.key_hash_tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Cc, sp.key_hash).unwrap_some() == sp.key_hash("tz4VVJutTUzLVFY64H1HTtNzFB4Uzfisk6Ccc")
|
|
433
|
+
assert sp.unpack(
|
|
434
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy, sp.address
|
|
435
|
+
).unwrap_some() == sp.address("KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy")
|
|
436
|
+
assert sp.unpack(
|
|
437
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy_, sp.address
|
|
438
|
+
).unwrap_some() == sp.address("KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy")
|
|
439
|
+
assert sp.unpack(
|
|
440
|
+
self.data.address_KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy_foo, sp.address
|
|
441
|
+
).unwrap_some() == sp.address("KT1Mpqi89gRyUuoXUPAWjHkqkk1F48eUKUVy%foo")
|
|
442
|
+
|
|
443
|
+
assert list_equal(
|
|
444
|
+
(
|
|
445
|
+
sp.unpack(self.data.list_int_0_to_6, sp.list[sp.int]).unwrap_some(),
|
|
446
|
+
[0, 1, 2, 3, 4, 5, 6],
|
|
447
|
+
)
|
|
448
|
+
)
|
|
449
|
+
assert list_equal(
|
|
450
|
+
(
|
|
451
|
+
sp.unpack(
|
|
452
|
+
self.data.list_int_range_0_1, sp.list[sp.int]
|
|
453
|
+
).unwrap_some(),
|
|
454
|
+
range(0, 1),
|
|
455
|
+
)
|
|
456
|
+
)
|
|
457
|
+
assert list_equal(
|
|
458
|
+
(
|
|
459
|
+
sp.unpack(
|
|
460
|
+
self.data.list_int_range_0_2, sp.list[sp.int]
|
|
461
|
+
).unwrap_some(),
|
|
462
|
+
range(0, 2),
|
|
463
|
+
)
|
|
464
|
+
)
|
|
465
|
+
assert list_equal(
|
|
466
|
+
(
|
|
467
|
+
sp.unpack(
|
|
468
|
+
self.data.list_int_range_0_3, sp.list[sp.int]
|
|
469
|
+
).unwrap_some(),
|
|
470
|
+
range(0, 3),
|
|
471
|
+
)
|
|
472
|
+
)
|
|
473
|
+
assert list_equal(
|
|
474
|
+
(
|
|
475
|
+
sp.unpack(
|
|
476
|
+
self.data.list_int_range_0_4, sp.list[sp.int]
|
|
477
|
+
).unwrap_some(),
|
|
478
|
+
range(0, 4),
|
|
479
|
+
)
|
|
480
|
+
)
|
|
481
|
+
assert list_equal(
|
|
482
|
+
(
|
|
483
|
+
sp.unpack(
|
|
484
|
+
self.data.list_int_range_0_5, sp.list[sp.int]
|
|
485
|
+
).unwrap_some(),
|
|
486
|
+
range(0, 5),
|
|
487
|
+
)
|
|
488
|
+
)
|
|
489
|
+
assert list_equal(
|
|
490
|
+
(
|
|
491
|
+
sp.unpack(
|
|
492
|
+
self.data.list_int_range_0_6, sp.list[sp.int]
|
|
493
|
+
).unwrap_some(),
|
|
494
|
+
range(0, 6),
|
|
495
|
+
)
|
|
496
|
+
)
|
|
497
|
+
assert list_equal(
|
|
498
|
+
(
|
|
499
|
+
sp.unpack(
|
|
500
|
+
self.data.list_int_range_0_7, sp.list[sp.int]
|
|
501
|
+
).unwrap_some(),
|
|
502
|
+
range(0, 7),
|
|
503
|
+
)
|
|
504
|
+
)
|
|
505
|
+
assert list_equal(
|
|
506
|
+
(
|
|
507
|
+
sp.unpack(self.data.set_int_1_to_4, sp.set[sp.int])
|
|
508
|
+
.unwrap_some()
|
|
509
|
+
.elements(),
|
|
510
|
+
[1, 2, 3, 4],
|
|
511
|
+
)
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
assert sp.pack(
|
|
515
|
+
sp.unpack(
|
|
516
|
+
self.data.lambda_x_plus_2, sp.lambda_[sp.int, sp.int]
|
|
517
|
+
).unwrap_some()
|
|
518
|
+
) == sp.pack(lambda x: x + 2)
|
|
519
|
+
assert sp.pack(
|
|
520
|
+
sp.unpack(
|
|
521
|
+
self.data.lambda_f1,
|
|
522
|
+
sp.lambda_[sp.record(a=sp.bool, b=sp.int), sp.int],
|
|
523
|
+
).unwrap_some()
|
|
524
|
+
) == sp.pack(self.f1)
|
|
525
|
+
assert sp.pack(
|
|
526
|
+
sp.unpack(
|
|
527
|
+
self.data.lambda_f2,
|
|
528
|
+
sp.lambda_[sp.record(a=sp.bool, b=sp.int, c=sp.int), sp.int],
|
|
529
|
+
).unwrap_some()
|
|
530
|
+
) == sp.pack(self.f2)
|
|
531
|
+
unpacked_f3 = sp.unpack(
|
|
532
|
+
self.data.lambda_f3, sp.lambda_[sp.int, sp.string]
|
|
533
|
+
).unwrap_some()
|
|
534
|
+
assert unpacked_f3(0) == self.f3(0)
|
|
535
|
+
assert unpacked_f3(1) == self.f3(1)
|
|
536
|
+
assert unpacked_f3(2) == self.f3(2)
|
|
537
|
+
unpacked_michelson = sp.unpack(
|
|
538
|
+
self.data.lambda_michelson, sp.lambda_[sp.int, sp.int]
|
|
539
|
+
).unwrap_some()
|
|
540
|
+
assert sp.pack(unpacked_michelson) == sp.pack(
|
|
541
|
+
lambda x: sp.michelson(
|
|
542
|
+
"DUP; PUSH int 42; ADD; MUL", [sp.int], [sp.int], x
|
|
543
|
+
)
|
|
544
|
+
)
|
|
545
|
+
assert unpacked_michelson(2) == 88
|
|
546
|
+
|
|
547
|
+
assert (
|
|
548
|
+
sp.concat(
|
|
549
|
+
sp.unpack(self.data.list_string, sp.list[sp.string]).unwrap_some()
|
|
550
|
+
)
|
|
551
|
+
== "this is a test"
|
|
552
|
+
)
|
|
553
|
+
m = sp.unpack(
|
|
554
|
+
self.data.map_string_int, sp.map[sp.string, sp.int]
|
|
555
|
+
).unwrap_some()
|
|
556
|
+
assert m["answer"] == 42 and sp.len(m) == 1
|
|
557
|
+
assert sp.unpack(
|
|
558
|
+
self.data.record_string_int, sp.record(a=sp.string, b=sp.int)
|
|
559
|
+
).unwrap_some() == sp.record(a="test", b=1337)
|
|
560
|
+
assert sp.unpack(
|
|
561
|
+
self.data.variant_a_string_b_nat, sp.variant(a=sp.string, b=sp.nat)
|
|
562
|
+
).unwrap_some() == sp.cast(
|
|
563
|
+
sp.variant.a("test"), sp.variant(a=sp.string, b=sp.nat)
|
|
564
|
+
)
|
|
565
|
+
assert sp.unpack(
|
|
566
|
+
self.data.option_string, sp.option[sp.string]
|
|
567
|
+
).unwrap_some() == sp.Some("hello")
|
|
568
|
+
assert sp.unpack(
|
|
569
|
+
self.data.none_string, sp.option[sp.string]
|
|
570
|
+
).unwrap_some() == sp.cast(None, sp.option[sp.string])
|
|
571
|
+
|
|
572
|
+
# TODO when chain_id creation is implemented
|
|
573
|
+
# assert sp.unpack(self.data.chain_id, sp.chain_id).unwrap_some() == sp.chain_id("NetXnHfVqm9iesp")
|
|
574
|
+
assert sp.unpack(self.data.level_2548242, sp.nat).unwrap_some() == 2548242
|
|
575
|
+
|
|
576
|
+
# TODO: activate when sapling is implemented
|
|
577
|
+
# assert sp.unpack(self.data.sapling_transaction, ...).unwrap_some() == ...
|
|
578
|
+
# assert sp.unpack(self.data.sapling_state, ...).unwrap_some() == ...
|
|
579
|
+
|
|
580
|
+
@sp.entrypoint
|
|
581
|
+
def pack_lambdas(self):
|
|
582
|
+
f1 = self.f3
|
|
583
|
+
sp.cast(f1, sp.lambda_[sp.int, sp.string])
|
|
584
|
+
p1 = sp.pack(f1)
|
|
585
|
+
f2 = sp.unpack(p1, sp.lambda_[sp.int, sp.string]).unwrap_some()
|
|
586
|
+
p2 = sp.pack(f2)
|
|
587
|
+
assert p1 == p2
|
|
588
|
+
assert f1(0) == f2(0)
|
|
589
|
+
assert f1(1) == f2(1)
|
|
590
|
+
assert f1(2) == f2(2)
|
|
591
|
+
|
|
592
|
+
@sp.entrypoint
|
|
593
|
+
def pack_lambdas2(self):
|
|
594
|
+
def f(x):
|
|
595
|
+
return x > 0
|
|
596
|
+
|
|
597
|
+
f1 = sp.cast(f, sp.lambda_[int, bool])
|
|
598
|
+
p1 = sp.pack(f1)
|
|
599
|
+
f2 = sp.unpack(p1, sp.lambda_[int, bool]).unwrap_some()
|
|
600
|
+
assert f2(1)
|
|
601
|
+
|
|
602
|
+
@sp.entrypoint
|
|
603
|
+
def pack_lambda_record(self):
|
|
604
|
+
f = lambda x: sp.record(a=1, b=x + 2)
|
|
605
|
+
|
|
606
|
+
f2 = sp.unpack(
|
|
607
|
+
sp.pack(f), sp.lambda_[int, sp.record(a=int, b=int)]
|
|
608
|
+
).unwrap_some()
|
|
609
|
+
assert f2(100).a == 1
|
|
610
|
+
|
|
611
|
+
g = lambda x: sp.record(a=x + 1)
|
|
612
|
+
|
|
613
|
+
g2 = sp.unpack(sp.pack(g), sp.lambda_[int, sp.record(a=int)]).unwrap_some()
|
|
614
|
+
assert g2(100).a == 101
|
|
615
|
+
|
|
616
|
+
@sp.entrypoint
|
|
617
|
+
def pack_lambda_variant(self):
|
|
618
|
+
f = lambda x: sp.cast(sp.variant.a(x + 1), tv)
|
|
619
|
+
f2 = sp.unpack(sp.pack(f), t1).unwrap_some()
|
|
620
|
+
assert f2(100).unwrap.a() == 101
|
|
621
|
+
|
|
622
|
+
f_ = lambda x: sp.variant.a(x + 1)
|
|
623
|
+
f2_ = sp.unpack(sp.pack(f_), t2).unwrap_some()
|
|
624
|
+
assert f2_(100).unwrap.a() == 101
|
|
625
|
+
|
|
626
|
+
@sp.entrypoint
|
|
627
|
+
def pack_unpack_pack_lambda(self):
|
|
628
|
+
assert sp.pack(self.f3) == sp.pack(
|
|
629
|
+
sp.unpack(sp.pack(self.f3), int_to_string).unwrap_some()
|
|
630
|
+
)
|
|
631
|
+
assert sp.pack(
|
|
632
|
+
sp.unpack(sp.pack(self.f3), int_to_string).unwrap_some()
|
|
633
|
+
) == sp.pack(
|
|
634
|
+
sp.unpack(
|
|
635
|
+
sp.pack(sp.unpack(sp.pack(self.f3), int_to_string).unwrap_some()),
|
|
636
|
+
int_to_string,
|
|
637
|
+
).unwrap_some()
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
if "main" in __name__:
|
|
642
|
+
|
|
643
|
+
@sp.add_test()
|
|
644
|
+
def test():
|
|
645
|
+
sc = sp.test_scenario("Pack")
|
|
646
|
+
c1 = main.Pack()
|
|
647
|
+
sc += c1
|
|
648
|
+
if sc.simulation_mode() is sp.SimulationMode.MOCKUP:
|
|
649
|
+
sc.p("mockups - TODO mockups cant use secret keys")
|
|
650
|
+
return
|
|
651
|
+
|
|
652
|
+
signature = sp.make_signature(
|
|
653
|
+
sp.test_account("keystore").secret_key,
|
|
654
|
+
sp.pack("value"),
|
|
655
|
+
message_format="Raw",
|
|
656
|
+
)
|
|
657
|
+
c1.pack(
|
|
658
|
+
signature_sig=sp.signature(
|
|
659
|
+
"sigTBpkXw6tC72L2nJ2r2Jm5iB6uidTWqoMNd4oEawUbGBf5mHVfKawFYL8X8MJECpL73oBnfujyUZNLK2LQWD1FaCkYMP4j"
|
|
660
|
+
),
|
|
661
|
+
signature_spsig=sp.signature(
|
|
662
|
+
"spsig1PPUFZucuAQybs5wsqsNQ68QNgFaBnVKMFaoZZfi1BtNnuCAWnmL9wVy5HfHkR6AeodjVGxpBVVSYcJKyMURn6K1yknYLm"
|
|
663
|
+
),
|
|
664
|
+
signature_p2sig=sp.signature(
|
|
665
|
+
"p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1FhfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ"
|
|
666
|
+
),
|
|
667
|
+
s=signature,
|
|
668
|
+
_level=2548242,
|
|
669
|
+
_chain_id=sp.chain_id_cst("0xaf1864d9feee0e1f"),
|
|
670
|
+
)
|
|
671
|
+
c1.unpack(
|
|
672
|
+
signature_sig=sp.signature(
|
|
673
|
+
"sigTBpkXw6tC72L2nJ2r2Jm5iB6uidTWqoMNd4oEawUbGBf5mHVfKawFYL8X8MJECpL73oBnfujyUZNLK2LQWD1FaCkYMP4j"
|
|
674
|
+
),
|
|
675
|
+
signature_spsig=sp.signature(
|
|
676
|
+
"spsig1PPUFZucuAQybs5wsqsNQ68QNgFaBnVKMFaoZZfi1BtNnuCAWnmL9wVy5HfHkR6AeodjVGxpBVVSYcJKyMURn6K1yknYLm"
|
|
677
|
+
),
|
|
678
|
+
signature_p2sig=sp.signature(
|
|
679
|
+
"p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1FhfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ"
|
|
680
|
+
),
|
|
681
|
+
s=signature,
|
|
682
|
+
_level=2548242,
|
|
683
|
+
_chain_id=sp.chain_id_cst("0xaf1864d9feee0e1f"),
|
|
684
|
+
)
|
|
685
|
+
c1.pack_lambdas()
|
|
686
|
+
c1.pack_lambdas2()
|
|
687
|
+
c1.pack_lambda_record()
|
|
688
|
+
c1.pack_lambda_variant()
|
|
689
|
+
c1.pack_unpack_pack_lambda()
|