From 6a7f272c6af9901dc804297bdb9c305c7194963b Mon Sep 17 00:00:00 2001 From: Gauthier SEBILLE Date: Wed, 6 Mar 2024 11:17:48 +0100 Subject: [PATCH 1/5] Proto/michelson: Pair ticket under legacy flag --- .../lib_protocol/script_ir_translator.ml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index d6befe9ab5fd..fc0d0b08a7c3 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -2374,17 +2374,14 @@ let rec parse_data : _annot ) -> parse_ticket loc ticketer contents_type contents amount | Prim (_, D_Pair, _, _) -> - (* TODO: https://gitlab.com/tezos/tezos/-/issues/6833 - - In the future, this [D_Pair] constructor must - be allowed only when the legacy flag is set to true. *) - let*? ty = opened_ticket_type (location expr) t in - let+ ({destination; entrypoint = _}, (contents, amount)), ctxt = - non_terminal_recursion ctxt ty expr - in - ((destination, contents, amount), ctxt) - | _ -> - tzfail @@ unexpected expr [] Constant_namespace [D_Ticket; D_Pair] + if legacy then + let*? ty = opened_ticket_type (location expr) t in + let+ ({destination; entrypoint = _}, (contents, amount)), ctxt = + non_terminal_recursion ctxt ty expr + in + ((destination, contents, amount), ctxt) + else tzfail @@ unexpected expr [] Constant_namespace [D_Ticket] + | _ -> tzfail @@ unexpected expr [] Constant_namespace [D_Ticket] in match Ticket_amount.of_n amount with | Some amount -> ( -- GitLab From c96e4ddb64bc9b79a1322789fc08f0b26255cfd0 Mon Sep 17 00:00:00 2001 From: Gauthier SEBILLE Date: Wed, 6 Mar 2024 11:18:11 +0100 Subject: [PATCH 2/5] Proto/rollup: enable legacy mode to support legacy ticket Pair representation --- src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml index 8cec2b1c633d..c5068e5547b8 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.ml @@ -76,7 +76,7 @@ let make_transaction ctxt ~parameters_ty ~unparsed_parameters ~destination let+ parameters, ctxt = Script_ir_translator.parse_data ctxt - ~elab_conf:Script_ir_translator_config.(make ~legacy:false ()) + ~elab_conf:Script_ir_translator_config.(make ~legacy:true ()) ~allow_forged_tickets:true ~allow_forged_lazy_storage_id:false parameters_ty -- GitLab From 28f7f7bc874bf601f31f5cd05d1504389a97f9d5 Mon Sep 17 00:00:00 2001 From: Gauthier SEBILLE Date: Wed, 6 Mar 2024 11:20:59 +0100 Subject: [PATCH 3/5] Tezt/tests: update tests to use new Ticket constructor --- src/proto_alpha/lib_protocol/test/regression/test_logging.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/regression/test_logging.ml b/src/proto_alpha/lib_protocol/test/regression/test_logging.ml index af8a498c5286..126d58ae9f3b 100644 --- a/src/proto_alpha/lib_protocol/test/regression/test_logging.ml +++ b/src/proto_alpha/lib_protocol/test/regression/test_logging.ml @@ -378,11 +378,11 @@ let () = ~storage:"{}" "spawn_identities"; transaction - ~parameter:"Pair \"KT1Ln1MPvHDJ1phLL8dNL4jrKF6Q1yQCBG1v\" 17 3" + ~parameter:"Ticket \"KT1Ln1MPvHDJ1phLL8dNL4jrKF6Q1yQCBG1v\" nat 17 3" ~storage:"None" "ticket_join"; transaction - ~parameter:"Pair \"KT1Ln1MPvHDJ1phLL8dNL4jrKF6Q1yQCBG1v\" 17 3" + ~parameter:"Ticket \"KT1Ln1MPvHDJ1phLL8dNL4jrKF6Q1yQCBG1v\" nat 17 3" ~storage:"Unit" "ticket_split"; transaction ~parameter:"5" ~storage:"3" "view_toplevel_lib"; -- GitLab From 05050df95db00bed05788178a046d1b026a2bb69 Mon Sep 17 00:00:00 2001 From: Gauthier SEBILLE Date: Wed, 6 Mar 2024 11:21:36 +0100 Subject: [PATCH 4/5] Tezt/tests: update tests to succeed with new ticket constructor and fail with pair --- .../michelson/test_ticket_direct_spending.ml | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_direct_spending.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_direct_spending.ml index 84e95dca4f7e..471ffda0773b 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_direct_spending.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_direct_spending.ml @@ -147,24 +147,39 @@ let test_spending ~direct_ticket_spending_enable ~constructor () = (Destination.Contract implicit) block in - let arg = - match constructor with - | Pair -> sf "Pair %S Unit 1" boomerang_str - | Ticket -> sf "Ticket %S unit Unit 1" boomerang_str - in - if direct_ticket_spending_enable then - let* block = call_contract ~source:implicit ~contract:consumer ~arg block in - assert_ticket_balance - ~loc:__LOC__ - ~ticketer:boomerang - ~expected_balance:0 - (Destination.Contract implicit) - block - else - let*! res = call_contract ~source:implicit ~contract:consumer ~arg block in - Assert.proto_error ~loc:__LOC__ res (function - | Script_interpreter.Bad_contract_parameter _ -> true - | _ -> false) + match constructor with + | Pair -> + let arg = sf "Pair %S Unit 1" boomerang_str in + let*! res = + call_contract ~source:implicit ~contract:consumer ~arg block + in + if direct_ticket_spending_enable then + Assert.proto_error ~loc:__LOC__ res (function + | Script_tc_errors.Invalid_primitive _ -> true + | _ -> false) + else + Assert.proto_error ~loc:__LOC__ res (function + | Script_interpreter.Bad_contract_parameter _ -> true + | _ -> false) + | Ticket -> + let arg = sf "Ticket %S unit Unit 1" boomerang_str in + if direct_ticket_spending_enable then + let* block = + call_contract ~source:implicit ~contract:consumer ~arg block + in + assert_ticket_balance + ~loc:__LOC__ + ~ticketer:boomerang + ~expected_balance:0 + (Destination.Contract implicit) + block + else + let*! res = + call_contract ~source:implicit ~contract:consumer ~arg block + in + Assert.proto_error ~loc:__LOC__ res (function + | Script_interpreter.Bad_contract_parameter _ -> true + | _ -> false) let tests = [ -- GitLab From b30a976c237970ac94005a110bc848a1f25083a0 Mon Sep 17 00:00:00 2001 From: Gauthier SEBILLE Date: Wed, 6 Mar 2024 11:25:09 +0100 Subject: [PATCH 5/5] Tezt/tests: update protocol version for direct transfer of tickets --- ...ameters) from implicit account to orig.out | 72 ++---- ...mplicit account to originated directly.out | 43 +--- ...r (with complex parameters) from impli.out | 16 +- ...ameters) from implicit account to orig.out | 61 ----- ...mplicit account to originated directly.out | 48 ---- ...r (with complex parameters) from impli.out | 18 +- tezt/tests/tickets.ml | 236 +++++++++++------- 7 files changed, 189 insertions(+), 305 deletions(-) delete mode 100644 tezt/tests/expected/tickets.ml/Paris- Send Pair tickets (with complex parameters) from implicit account to orig.out delete mode 100644 tezt/tests/expected/tickets.ml/Paris- Send Pair tickets from implicit account to originated directly.out diff --git a/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets (with complex parameters) from implicit account to orig.out b/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets (with complex parameters) from implicit account to orig.out index be3a373cdeab..f6fbf24f8469 100644 --- a/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets (with complex parameters) from implicit account to orig.out +++ b/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets (with complex parameters) from implicit account to orig.out @@ -1,61 +1,35 @@ -./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2)}' +./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2))}' Node is bootstrapped. -Estimated gas: 4001.689 units (will add 100 for safety) -Estimated storage: 238 bytes added (will add 20 for safety) -Operation successfully injected in the node. -Operation hash is '[OPERATION_HASH]' -NOT waiting for the operation to be included. -Use command - octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] -and/or an external block explorer to make sure that it has been included. -This sequence of operations was run: +This simulation failed: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000843 + Fee to the baker: ꜩ0 Expected counter: 4 - Gas limit: 4102 - Storage limit: 258 bytes - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000843 - payload fees(the block proposer) ....... +ꜩ0.000843 + Gas limit: 1040000 + Storage limit: 60000 bytes Transaction: Amount: ꜩ0 From: [PUBLIC_KEY_HASH] To: [CONTRACT_HASH] Entrypoint: store Parameter: (Pair 99 - { Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; - Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2) }) - This transaction was successfully applied - Updated storage: - { Ticket 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 string "Ticket2" 2 ; - Ticket 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 string "Ticket1" 1 } - Storage size: 303 bytes - Paid storage size diff: 238 bytes - Consumed gas: 4001.656 - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.0595 - storage fees ........................... +ꜩ0.0595 - Ticket updates: - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket1" - Account updates: - [PUBLIC_KEY_HASH] ... -1 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket2" - Account updates: - [PUBLIC_KEY_HASH] ... -2 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket2" - Account updates: - [CONTRACT_HASH] ... +2 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket1" - Account updates: - [CONTRACT_HASH] ... +1 + { Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; + Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2)) }) + This operation FAILED. +At (unshown) location 0, value + (Pair 99 + { Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; + Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2)) }) +is invalid for type pair int (list (pair string (ticket string))). +At (unshown) location 2, value + { Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; + Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2)) } +is invalid for type list (pair string (ticket string)). +At (unshown) location 10, value + (Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2))) +is invalid for type pair string (ticket string). +At (unshown) location 12, invalid primitive Pair, only Ticket can be used here. +Fatal error: + transfer simulation failed diff --git a/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets from implicit account to originated directly.out b/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets from implicit account to originated directly.out index 9ded0d955dd7..5e642b7ffed4 100644 --- a/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets from implicit account to originated directly.out +++ b/tezt/tests/expected/tickets.ml/Alpha- Send Pair tickets from implicit account to originated directly.out @@ -1,48 +1,21 @@ ./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint save --arg 'Pair "[CONTRACT_HASH]" (Pair "Ticket" 1)' Node is bootstrapped. -Estimated gas: 3081.411 units (will add 100 for safety) -Estimated storage: 52 bytes added (will add 20 for safety) -Operation successfully injected in the node. -Operation hash is '[OPERATION_HASH]' -NOT waiting for the operation to be included. -Use command - octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] -and/or an external block explorer to make sure that it has been included. -This sequence of operations was run: +This simulation failed: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000635 + Fee to the baker: ꜩ0 Expected counter: 4 - Gas limit: 3182 - Storage limit: 72 bytes - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000635 - payload fees(the block proposer) ....... +ꜩ0.000635 + Gas limit: 1040000 + Storage limit: 60000 bytes Transaction: Amount: ꜩ0 From: [PUBLIC_KEY_HASH] To: [CONTRACT_HASH] Entrypoint: save Parameter: (Pair "[CONTRACT_HASH]" (Pair "Ticket" 1)) - This transaction was successfully applied - Updated storage: - { Ticket 0x01fb08747351ab3652f772910c4565880d8df616f800 string "Ticket" 1 } - Storage size: 246 bytes - Paid storage size diff: 52 bytes - Consumed gas: 3081.345 - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.013 - storage fees ........................... +ꜩ0.013 - Ticket updates: - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket" - Account updates: - [PUBLIC_KEY_HASH] ... -1 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket" - Account updates: - [CONTRACT_HASH] ... +1 + This operation FAILED. +At (unshown) location 0, invalid primitive Pair, only Ticket can be used here. +Fatal error: + transfer simulation failed diff --git a/tezt/tests/expected/tickets.ml/Alpha- Send tickets with Ticket constructor (with complex parameters) from impli.out b/tezt/tests/expected/tickets.ml/Alpha- Send tickets with Ticket constructor (with complex parameters) from impli.out index 0104fd22eaba..be3a373cdeab 100644 --- a/tezt/tests/expected/tickets.ml/Alpha- Send tickets with Ticket constructor (with complex parameters) from impli.out +++ b/tezt/tests/expected/tickets.ml/Alpha- Send tickets with Ticket constructor (with complex parameters) from impli.out @@ -1,7 +1,7 @@ -./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2))}' +./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2)}' Node is bootstrapped. -Estimated gas: 4001.005 units (will add 100 for safety) +Estimated gas: 4001.689 units (will add 100 for safety) Estimated storage: 238 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -12,28 +12,28 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000827 + Fee to the baker: ꜩ0.000843 Expected counter: 4 Gas limit: 4102 Storage limit: 258 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000827 - payload fees(the block proposer) ....... +ꜩ0.000827 + [PUBLIC_KEY_HASH] ... -ꜩ0.000843 + payload fees(the block proposer) ....... +ꜩ0.000843 Transaction: Amount: ꜩ0 From: [PUBLIC_KEY_HASH] To: [CONTRACT_HASH] Entrypoint: store Parameter: (Pair 99 - { Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; - Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2)) }) + { Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; + Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2) }) This transaction was successfully applied Updated storage: { Ticket 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 string "Ticket2" 2 ; Ticket 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 string "Ticket1" 1 } Storage size: 303 bytes Paid storage size diff: 238 bytes - Consumed gas: 4000.972 + Consumed gas: 4001.656 Balance updates: [PUBLIC_KEY_HASH] ... -ꜩ0.0595 storage fees ........................... +ꜩ0.0595 diff --git a/tezt/tests/expected/tickets.ml/Paris- Send Pair tickets (with complex parameters) from implicit account to orig.out b/tezt/tests/expected/tickets.ml/Paris- Send Pair tickets (with complex parameters) from implicit account to orig.out deleted file mode 100644 index 2f058a677b5e..000000000000 --- a/tezt/tests/expected/tickets.ml/Paris- Send Pair tickets (with complex parameters) from implicit account to orig.out +++ /dev/null @@ -1,61 +0,0 @@ - -./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2)}' -Node is bootstrapped. -Estimated gas: 4002.105 units (will add 100 for safety) -Estimated storage: 222 bytes added (will add 20 for safety) -Operation successfully injected in the node. -Operation hash is '[OPERATION_HASH]' -NOT waiting for the operation to be included. -Use command - octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] -and/or an external block explorer to make sure that it has been included. -This sequence of operations was run: - Manager signed operations: - From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000843 - Expected counter: 4 - Gas limit: 4103 - Storage limit: 242 bytes - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000843 - payload fees(the block proposer) ....... +ꜩ0.000843 - Transaction: - Amount: ꜩ0 - From: [PUBLIC_KEY_HASH] - To: [CONTRACT_HASH] - Entrypoint: store - Parameter: (Pair 99 - { Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; - Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2) }) - This transaction was successfully applied - Updated storage: - { Pair 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 (Pair "Ticket2" 2) ; - Pair 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 (Pair "Ticket1" 1) } - Storage size: 287 bytes - Paid storage size diff: 222 bytes - Consumed gas: 4002.072 - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.0555 - storage fees ........................... +ꜩ0.0555 - Ticket updates: - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket1" - Account updates: - [PUBLIC_KEY_HASH] ... -1 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket2" - Account updates: - [PUBLIC_KEY_HASH] ... -2 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket2" - Account updates: - [CONTRACT_HASH] ... +2 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket1" - Account updates: - [CONTRACT_HASH] ... +1 - diff --git a/tezt/tests/expected/tickets.ml/Paris- Send Pair tickets from implicit account to originated directly.out b/tezt/tests/expected/tickets.ml/Paris- Send Pair tickets from implicit account to originated directly.out deleted file mode 100644 index 389d74690982..000000000000 --- a/tezt/tests/expected/tickets.ml/Paris- Send Pair tickets from implicit account to originated directly.out +++ /dev/null @@ -1,48 +0,0 @@ - -./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint save --arg 'Pair "[CONTRACT_HASH]" (Pair "Ticket" 1)' -Node is bootstrapped. -Estimated gas: 3081.619 units (will add 100 for safety) -Estimated storage: 44 bytes added (will add 20 for safety) -Operation successfully injected in the node. -Operation hash is '[OPERATION_HASH]' -NOT waiting for the operation to be included. -Use command - octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] -and/or an external block explorer to make sure that it has been included. -This sequence of operations was run: - Manager signed operations: - From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000635 - Expected counter: 4 - Gas limit: 3182 - Storage limit: 64 bytes - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000635 - payload fees(the block proposer) ....... +ꜩ0.000635 - Transaction: - Amount: ꜩ0 - From: [PUBLIC_KEY_HASH] - To: [CONTRACT_HASH] - Entrypoint: save - Parameter: (Pair "[CONTRACT_HASH]" (Pair "Ticket" 1)) - This transaction was successfully applied - Updated storage: - { Pair 0x01fb08747351ab3652f772910c4565880d8df616f800 (Pair "Ticket" 1) } - Storage size: 238 bytes - Paid storage size diff: 44 bytes - Consumed gas: 3081.553 - Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.011 - storage fees ........................... +ꜩ0.011 - Ticket updates: - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket" - Account updates: - [PUBLIC_KEY_HASH] ... -1 - Ticketer: [CONTRACT_HASH] - Content type: string - Content: "Ticket" - Account updates: - [CONTRACT_HASH] ... +1 - diff --git a/tezt/tests/expected/tickets.ml/Paris- Send tickets with Ticket constructor (with complex parameters) from impli.out b/tezt/tests/expected/tickets.ml/Paris- Send tickets with Ticket constructor (with complex parameters) from impli.out index e26b3fd99068..2f058a677b5e 100644 --- a/tezt/tests/expected/tickets.ml/Paris- Send tickets with Ticket constructor (with complex parameters) from impli.out +++ b/tezt/tests/expected/tickets.ml/Paris- Send tickets with Ticket constructor (with complex parameters) from impli.out @@ -1,7 +1,7 @@ -./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2))}' +./octez-client --wait none transfer 0 from bootstrap1 to '[CONTRACT_HASH]' --burn-cap 1 --entrypoint store --arg 'Pair 99 {Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2)}' Node is bootstrapped. -Estimated gas: 4001.421 units (will add 100 for safety) +Estimated gas: 4002.105 units (will add 100 for safety) Estimated storage: 222 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -12,28 +12,28 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [PUBLIC_KEY_HASH] - Fee to the baker: ꜩ0.000827 + Fee to the baker: ꜩ0.000843 Expected counter: 4 - Gas limit: 4102 + Gas limit: 4103 Storage limit: 242 bytes Balance updates: - [PUBLIC_KEY_HASH] ... -ꜩ0.000827 - payload fees(the block proposer) ....... +ꜩ0.000827 + [PUBLIC_KEY_HASH] ... -ꜩ0.000843 + payload fees(the block proposer) ....... +ꜩ0.000843 Transaction: Amount: ꜩ0 From: [PUBLIC_KEY_HASH] To: [CONTRACT_HASH] Entrypoint: store Parameter: (Pair 99 - { Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket1" 1)) ; - Pair "garbage" (Pair "[CONTRACT_HASH]" (Pair "Ticket2" 2)) }) + { Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket1" 1) ; + Pair "garbage" (Ticket "[CONTRACT_HASH]" string "Ticket2" 2) }) This transaction was successfully applied Updated storage: { Pair 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 (Pair "Ticket2" 2) ; Pair 0x01b9ce1609aab1100170d2ea4f94e3407244090b1000 (Pair "Ticket1" 1) } Storage size: 287 bytes Paid storage size diff: 222 bytes - Consumed gas: 4001.388 + Consumed gas: 4002.072 Balance updates: [PUBLIC_KEY_HASH] ... -ꜩ0.0555 storage fees ........................... +ꜩ0.0555 diff --git a/tezt/tests/tickets.ml b/tezt/tests/tickets.ml index 9d287951c0ae..3f40d824cc70 100644 --- a/tezt/tests/tickets.ml +++ b/tezt/tests/tickets.ml @@ -48,12 +48,12 @@ let setup_node protocol ~direct_ticket_spending_enable = in return (node, client) -(* Return micheline encoding of ticket. *) -let encode_pair_ticket ~ticketer ~content ~amount = - sf {|Pair %S (Pair %S %d)|} ticketer content amount +type ticket_constructor = Pair | Ticket -let encode_string_ticket ~ticketer ~content ~amount = - sf {|Ticket %S string %S %d|} ticketer content amount +let encode_ticket ~constructor ~ticketer ~content ~amount = + match constructor with + | Pair -> sf {|Pair %S (Pair %S %d)|} ticketer content amount + | Ticket -> sf {|Ticket %S string %S %d|} ticketer content amount let test_create_and_remove_tickets = Protocol.register_regression_test @@ -236,7 +236,7 @@ let test_send_tickets_to_implicit_account = (* Tests that an implicit account can send a single ticket to originated using the [Transfer] manager operation. *) let test_direct_transfer_tickets_from_implicit_account_to_originated - ~encode_ticket protocol = + ~ticket_constructor protocol = let* _node, client = setup_node protocol ~direct_ticket_spending_enable:true in @@ -285,37 +285,64 @@ let test_direct_transfer_tickets_from_implicit_account_to_originated in let* () = Client.bake_for_and_wait client in (* Transfer ticket from implicit to originated using the [Transaction] manager operation. *) - let* () = - Client.transfer - ~burn_cap:Tez.one - ~amount:Tez.zero - ~giver:Constant.bootstrap1.alias - ~receiver:bag - ~entrypoint:"save" - ~arg:(encode_ticket ~ticketer ~content:"Ticket" ~amount:1) - ~hooks - client - in - let* () = Client.bake_for_and_wait client in - let* () = - assert_ticket_balance - ~contract:Constant.bootstrap1.alias - ~ticketer - ~ty:"string" - ~contents:"\"Ticket\"" - ~expected:0 - client - in - let* () = - assert_ticket_balance - ~contract:bag - ~ticketer - ~ty:"string" - ~contents:"\"Ticket\"" - ~expected:1 - client - in - unit + match ticket_constructor with + | Pair -> + let* () = + Process.check_error + ~msg:(rex "invalid primitive Pair, only Ticket can be used here") + (Client.spawn_transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:bag + ~entrypoint:"save" + ~arg: + (encode_ticket + ~constructor:Pair + ~ticketer + ~content:"Ticket" + ~amount:1) + ~hooks + client) + in + unit + | Ticket -> + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:bag + ~entrypoint:"save" + ~arg: + (encode_ticket + ~constructor:Ticket + ~ticketer + ~content:"Ticket" + ~amount:1) + ~hooks + client + in + let* () = Client.bake_for_and_wait client in + let* () = + assert_ticket_balance + ~contract:Constant.bootstrap1.alias + ~ticketer + ~ty:"string" + ~contents:"\"Ticket\"" + ~expected:0 + client + in + let* () = + assert_ticket_balance + ~contract:bag + ~ticketer + ~ty:"string" + ~contents:"\"Ticket\"" + ~expected:1 + client + in + unit let test_direct_transfer_tickets_from_implicit_account_to_originated_with_pair_constructor = @@ -323,11 +350,11 @@ let test_direct_transfer_tickets_from_implicit_account_to_originated_with_pair_c ~__FILE__ ~title:"Send Pair tickets from implicit account to originated directly" ~tags:["client"; "michelson"; "implicit"; "ticket"; "originated"] - ~supports:(Protocol.From_protocol 19) + ~supports:(Protocol.From_protocol 20) @@ fun protocol -> test_direct_transfer_tickets_from_implicit_account_to_originated protocol - ~encode_ticket:encode_pair_ticket + ~ticket_constructor:Pair let test_direct_transfer_tickets_from_implicit_account_to_originated_with_ticket_constructor = @@ -341,14 +368,14 @@ let test_direct_transfer_tickets_from_implicit_account_to_originated_with_ticket @@ fun protocol -> test_direct_transfer_tickets_from_implicit_account_to_originated protocol - ~encode_ticket:encode_string_ticket + ~ticket_constructor:Ticket (* Tests that an implicit account can send a tickets to originated using the [Transfer] manager operation. The parameter of the transfer is made complex to check that the [Transfer] properly scans the parameter and transfers all included tickets. *) let test_direct_transfer_tickets_from_implicit_account_to_originated_complex - ~encode_ticket protocol = + ~ticket_constructor protocol = let* _node, client = setup_node protocol ~direct_ticket_spending_enable:true in @@ -426,65 +453,84 @@ let test_direct_transfer_tickets_from_implicit_account_to_originated_complex sf {|Pair 99 {Pair "garbage" (%s) ; Pair "garbage" (%s)}|} (encode_ticket + ~constructor:ticket_constructor ~ticketer ~content:first_ticket_content ~amount:first_ticket_sent) (encode_ticket + ~constructor:ticket_constructor ~ticketer ~content:second_ticket_content ~amount:second_ticket_sent) in - let* () = - Client.transfer - ~hooks - ~burn_cap:Tez.one - ~amount:Tez.zero - ~giver:Constant.bootstrap1.alias - ~entrypoint:"store" - ~receiver:ticketer - ~arg:complex_arg_with_tickets - client - in - let* () = Client.bake_for_and_wait client in - (* Check that ticket balance is removed for implicit account. *) - let* () = - assert_ticket_balance - ~contract:Constant.bootstrap1.alias - ~ticketer - ~ty:"string" - ~contents:(sf "%S" first_ticket_content) - ~expected:(amount - first_ticket_sent) - client - in - let* () = - assert_ticket_balance - ~contract:Constant.bootstrap1.alias - ~ticketer - ~ty:"string" - ~contents:(sf "%S" second_ticket_content) - ~expected:(amount - second_ticket_sent) - client - in - (* Check that ticket balance is added for originated contract. *) - let* () = - assert_ticket_balance - ~contract:ticketer - ~ticketer - ~ty:"string" - ~contents:(sf "%S" first_ticket_content) - ~expected:first_ticket_sent - client - in - let* () = - assert_ticket_balance - ~contract:ticketer - ~ticketer - ~ty:"string" - ~contents:(sf "%S" second_ticket_content) - ~expected:second_ticket_sent - client - in - unit + match ticket_constructor with + | Pair -> + let* () = + Process.check_error + ~msg:(rex "invalid primitive Pair, only Ticket can be used here") + (Client.spawn_transfer + ~hooks + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~entrypoint:"store" + ~receiver:ticketer + ~arg:complex_arg_with_tickets + client) + in + unit + | Ticket -> + let* () = + Client.transfer + ~hooks + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~entrypoint:"store" + ~receiver:ticketer + ~arg:complex_arg_with_tickets + client + in + let* () = Client.bake_for_and_wait client in + (* Check that ticket balance is removed for implicit account. *) + let* () = + assert_ticket_balance + ~contract:Constant.bootstrap1.alias + ~ticketer + ~ty:"string" + ~contents:(sf "%S" first_ticket_content) + ~expected:(amount - first_ticket_sent) + client + in + let* () = + assert_ticket_balance + ~contract:Constant.bootstrap1.alias + ~ticketer + ~ty:"string" + ~contents:(sf "%S" second_ticket_content) + ~expected:(amount - second_ticket_sent) + client + in + (* Check that ticket balance is added for originated contract. *) + let* () = + assert_ticket_balance + ~contract:ticketer + ~ticketer + ~ty:"string" + ~contents:(sf "%S" first_ticket_content) + ~expected:first_ticket_sent + client + in + let* () = + assert_ticket_balance + ~contract:ticketer + ~ticketer + ~ty:"string" + ~contents:(sf "%S" second_ticket_content) + ~expected:second_ticket_sent + client + in + unit let test_direct_transfer_tickets_from_implicit_account_to_originated_complex_with_ticket_constructor = @@ -498,7 +544,7 @@ let test_direct_transfer_tickets_from_implicit_account_to_originated_complex_wit @@ fun protocol -> test_direct_transfer_tickets_from_implicit_account_to_originated_complex protocol - ~encode_ticket:encode_pair_ticket + ~ticket_constructor:Ticket let test_direct_transfer_tickets_from_implicit_account_to_originated_complex_with_pair_constructor = @@ -508,11 +554,11 @@ let test_direct_transfer_tickets_from_implicit_account_to_originated_complex_wit "Send Pair tickets (with complex parameters) from implicit account to \ originated directly" ~tags:["client"; "michelson"; "implicit"; "ticket"; "originated"] - ~supports:(Protocol.From_protocol 19) + ~supports:(Protocol.From_protocol 20) @@ fun protocol -> test_direct_transfer_tickets_from_implicit_account_to_originated_complex protocol - ~encode_ticket:encode_string_ticket + ~ticket_constructor:Pair (* This test originates one contract which mints and sends tickets to the address passed in the parameter. In this test, the receiver of the ticket is an -- GitLab