package octez-protocol-018-Proxford-libs
Octez protocol 018-Proxford libraries
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-18.1.tar.gz
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a
doc/src/octez-protocol-018-Proxford-libs.test-helpers/contract_helpers.ml.html
Source file contract_helpers.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2020-2021 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) open Protocol open Alpha_context open Error_monad_operators (** Initializes 2 addresses to do only operations plus one that will be used to bake. *) let init () = Context.init3 ~consensus_threshold:0 () >|=? fun (b, (src0, src1, src2)) -> let baker = match src0 with Implicit v -> v | Originated _ -> assert false in (b, baker, src1, src2) (** Return contents of a given file as string. *) let read_file f = In_channel.with_open_text f (fun ic -> really_input_string ic (in_channel_length ic)) (** Loads a script from file. *) let load_script ~storage file = let contract_string = read_file file in let code = Expr.toplevel_from_string contract_string in let storage = Expr.from_string storage in Alpha_context.Script.{code = lazy_expr code; storage = lazy_expr storage} (** Returns a block in which the contract is originated. *) let originate_contract_hash file storage src b baker = let script = load_script ~storage file in Op.contract_origination_hash (B b) src ~fee:(Test_tez.of_int 10) ~script >>=? fun (operation, dst) -> Incremental.begin_construction ~policy:Block.(By_account baker) b >>=? fun incr -> Incremental.add_operation incr operation >>=? fun incr -> Incremental.finalize_block incr >|=? fun b -> (dst, b) let originate_contract file storage src b baker = originate_contract_hash file storage src b baker >|=? fun (dst, b) -> (Contract.Originated dst, b) let fake_KT1 = Contract_hash.of_b58check_exn "KT1FAKEFAKEFAKEFAKEFAKEFAKEFAKGGSE2x" let default_self = fake_KT1 let default_payer = Signature.Public_key_hash.zero let default_sender = Contract.Implicit default_payer let default_step_constants = Script_interpreter. { sender = Contract default_sender; payer = default_payer; self = default_self; amount = Tez.zero; balance = Tez.zero; chain_id = Chain_id.zero; now = Script_timestamp.of_zint Z.zero; level = Script_int.zero_n; } (** Helper function that parses and typechecks a script, its initial storage and parameters from strings. It then executes the typed script with the storage and parameters and returns the result. The [step_constants] argument passes in some data which remains constant throughout script's execution, hence the name. This includes addresses of the sender and payer, the address of the smart contract, the amount of Tez transferred to it and so on. An [internal] operation is an operation generated by smart contract's execution rather than by an implicit account. *) let run_script ctx ?logger ?(step_constants = default_step_constants) ?(internal = false) contract ?(entrypoint = Entrypoint.default) ~storage ~parameter () = let contract_expr = Expr.from_string contract in let storage_expr = Expr.from_string storage in let parameter_expr = Expr.from_string parameter in let script = Script.{code = lazy_expr contract_expr; storage = lazy_expr storage_expr} in Script_interpreter.execute ctx Readable step_constants ?logger ~script ~cached_script:None ~entrypoint ~parameter:parameter_expr ~internal >>=?? fun res -> return res let originate_contract_from_string_hash ~script ~storage ~source_contract ~baker block = let code = Expr.toplevel_from_string script in let storage = Expr.from_string storage in let script = Alpha_context.Script.{code = lazy_expr code; storage = lazy_expr storage} in Op.contract_origination_hash (B block) source_contract ~fee:(Test_tez.of_int 10) ~script >>=? fun (operation, dst) -> Incremental.begin_construction ~policy:Block.(By_account baker) block >>=? fun incr -> Incremental.add_operation incr operation >>=? fun incr -> Incremental.finalize_block incr >|=? fun b -> (dst, script, b) let originate_contract_from_string ~script ~storage ~source_contract ~baker block = originate_contract_from_string_hash ~script ~storage ~source_contract ~baker block >|=? fun (dst, script, b) -> (Contract.Originated dst, script, b)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>