diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 20635b5c6fba27b8c09cbdfb9f775862be442902..4f845d80920dfa64605161d8f615378a60e48eee 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -3034,10 +3034,12 @@ let from_fa1_2_contract_get_total_supply_callback ?burn_cap ~contract ~from client |> Process.check -let spawn_from_fa1_2_contract_transfer ?burn_cap ~contract ~amount ~from ~to_ - ?as_ client = +let spawn_from_fa1_2_contract_transfer ?(wait = "none") ?burn_cap ~contract + ~amount ~from ~to_ ?as_ client = spawn_command client @@ [ + "--wait"; + wait; "from"; "fa1.2"; "contract"; @@ -3052,9 +3054,10 @@ let spawn_from_fa1_2_contract_transfer ?burn_cap ~contract ~amount ~from ~to_ @ optional_arg "as" Fun.id as_ @ optional_arg "burn-cap" Tez.to_string burn_cap -let from_fa1_2_contract_transfer ?burn_cap ~contract ~amount ~from ~to_ ?as_ - client = +let from_fa1_2_contract_transfer ?wait ?burn_cap ~contract ~amount ~from ~to_ + ?as_ client = spawn_from_fa1_2_contract_transfer + ?wait ?burn_cap ~contract ~amount @@ -3064,10 +3067,12 @@ let from_fa1_2_contract_transfer ?burn_cap ~contract ~amount ~from ~to_ ?as_ client |> Process.check -let spawn_from_fa1_2_contract_approve ?burn_cap ~contract ~as_ ~amount ~from - client = +let spawn_from_fa1_2_contract_approve ?(wait = "none") ?burn_cap ~contract ~as_ + ~amount ~from client = spawn_command client @@ [ + "--wait"; + wait; "from"; "fa1.2"; "contract"; @@ -3081,8 +3086,10 @@ let spawn_from_fa1_2_contract_approve ?burn_cap ~contract ~as_ ~amount ~from ] @ optional_arg "burn-cap" Tez.to_string burn_cap -let from_fa1_2_contract_approve ?burn_cap ~contract ~as_ ~amount ~from client = +let from_fa1_2_contract_approve ?wait ?burn_cap ~contract ~as_ ~amount ~from + client = spawn_from_fa1_2_contract_approve + ?wait ?burn_cap ~contract ~as_ diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 52ab2f28b516909d141a09169ded22e7ac72666f..587fca1ea26d87635d2a2b1186b08d015cd27f80 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -1936,6 +1936,7 @@ val spawn_from_fa1_2_contract_get_total_supply_callback : (** Run [octez-client from fa1.2 contract transfer from to ]. *) val from_fa1_2_contract_transfer : + ?wait:string -> ?burn_cap:Tez.t -> contract:string -> amount:int -> @@ -1947,6 +1948,7 @@ val from_fa1_2_contract_transfer : (** Same as [from_fa1_2_contract_transfer], but do not wait for the process to exit. *) val spawn_from_fa1_2_contract_transfer : + ?wait:string -> ?burn_cap:Tez.t -> contract:string -> amount:int -> @@ -1958,6 +1960,7 @@ val spawn_from_fa1_2_contract_transfer : (** Run [octez-client from fa1.2 contract as approve from ]. *) val from_fa1_2_contract_approve : + ?wait:string -> ?burn_cap:Tez.t -> contract:string -> as_:string -> @@ -1968,6 +1971,7 @@ val from_fa1_2_contract_approve : (** Same as [from_fa1_2_contract_approve], but do not wait for the process to exit. *) val spawn_from_fa1_2_contract_approve : + ?wait:string -> ?burn_cap:Tez.t -> contract:string -> as_:string -> diff --git a/tezt/lib_tezos/fa12.ml b/tezt/lib_tezos/fa12.ml new file mode 100644 index 0000000000000000000000000000000000000000..87c4b926e49e5376c0c8b68ddaff9beaca56188f --- /dev/null +++ b/tezt/lib_tezos/fa12.ml @@ -0,0 +1,78 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type fa12_script = { + name : string list; + build_storage : Account.key -> string; + mint_entrypoint : string; + mint_arg : Account.key -> Tez.t -> string; +} + +let fa12_reference = + { + name = ["mini_scenarios"; "fa12_reference"]; + build_storage = + (fun admin -> + sf {|Pair {} (Pair "%s" (Pair False 0))|} admin.public_key_hash); + mint_entrypoint = "mint"; + mint_arg = + (fun owner amount -> + sf {|(Pair "%s" %d)|} owner.public_key_hash (Tez.to_mutez amount)); + } + +let lqt_fa12 = + { + name = ["mini_scenarios"; "lqt_fa12.mligo"]; + build_storage = + (fun admin -> sf {|Pair {} {} "%s" 0|} admin.public_key_hash); + mint_entrypoint = "mintOrBurn"; + mint_arg = + (fun owner amount -> + sf {|(Pair %d "%s")|} (Tez.to_mutez amount) owner.public_key_hash); + } + +let fa12_scripts = [fa12_reference; lqt_fa12] + +let originate_fa12 ~src ~admin ~fa12_script client protocol = + let initial_storage = fa12_script.build_storage admin in + Client.originate_contract_at + ~amount:Tez.zero + ~src + ~init:initial_storage + ~burn_cap:(Tez.of_int 2) + client + fa12_script.name + protocol + +let mint ~admin ~mint ~dest ~fa12_address ~fa12_script client = + let mint_arg = fa12_script.mint_arg dest mint in + Client.transfer + ~amount:Tez.zero + ~giver:admin.Account.public_key_hash + ~receiver:fa12_address + ~entrypoint:fa12_script.mint_entrypoint + ~arg:mint_arg + ~burn_cap:Tez.one + client diff --git a/tezt/lib_tezos/fa12.mli b/tezt/lib_tezos/fa12.mli new file mode 100644 index 0000000000000000000000000000000000000000..c7fbb6dd1c80397841503b1b1af9ed7468cf252f --- /dev/null +++ b/tezt/lib_tezos/fa12.mli @@ -0,0 +1,64 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type fa12_script = { + name : string list; + build_storage : Account.key -> string; + mint_entrypoint : string; + mint_arg : Account.key -> Tez.t -> string; +} + +(** {!fa12_script} for [mini_scenarios/fa12_reference]. *) +val fa12_reference : fa12_script + +(** {!fa12_script} for [mini_scenarios/lqt_fa12.mligo]. *) +val lqt_fa12 : fa12_script + +(** List of {!fa12_scripts} that can be used in generic FA1.2 tests. *) +val fa12_scripts : fa12_script list + +(** [originate_fa12 ~src ~admin ~fa12_script client protocol] originates + FA1.2 contract [fa12_script] from [src] with administrator set to [admin]. + + Returns a pair (alias * address) for the originated contract. +*) +val originate_fa12 : + src:string -> + admin:Account.key -> + fa12_script:fa12_script -> + Client.t -> + Protocol.t -> + (string * string) Lwt.t + +(** [mint ~admin ~mint ~dest ~fa12_address ~fa12_script client] mints [mint] + for [dest] using the administrator [admin]. *) +val mint : + admin:Account.key -> + mint:Tez.t -> + dest:Account.key -> + fa12_address:string -> + fa12_script:fa12_script -> + Client.t -> + unit Lwt.t diff --git a/tezt/tests/client_fa12.ml b/tezt/tests/client_fa12.ml index 06c35f4591b3cf2a39049610abd50cdb69d3e4a4..a805ed54a68df8229edc3d381e181cee77059ee6 100644 --- a/tezt/tests/client_fa12.ml +++ b/tezt/tests/client_fa12.ml @@ -30,35 +30,7 @@ Subject: Tests the client's FA1.2 commands *) -type fa12_script = { - name : string list; - build_storage : Account.key -> string; - mint_entrypoint : string; - mint_arg : Account.key -> Tez.t -> string; -} - -let fa12_scripts = - [ - { - name = ["mini_scenarios"; "fa12_reference"]; - build_storage = - (fun admin -> - sf {|Pair {} (Pair "%s" (Pair False 0))|} admin.public_key_hash); - mint_entrypoint = "mint"; - mint_arg = - (fun owner amount -> - sf {|(Pair "%s" %d)|} owner.public_key_hash (Tez.to_mutez amount)); - }; - { - name = ["mini_scenarios"; "lqt_fa12.mligo"]; - build_storage = - (fun admin -> sf {|Pair {} {} "%s" 0|} admin.public_key_hash); - mint_entrypoint = "mintOrBurn"; - mint_arg = - (fun owner amount -> - sf {|(Pair %d "%s")|} (Tez.to_mutez amount) owner.public_key_hash); - }; - ] +open Fa12 let register_fa12_test ~title ?(tags = []) test_body protocols = fa12_scripts @@ -75,29 +47,22 @@ let register_fa12_test ~title ?(tags = []) test_body protocols = (fun protocol -> let* client = Client.init_mockup ~protocol () in let admin = Account.Bootstrap.keys.(2) in - let initial_storage = fa12_script.build_storage admin in let* fa12_alias, fa12_address = - Client.originate_contract_at - ~amount:Tez.zero + originate_fa12 ~src:Account.Bootstrap.keys.(0).public_key_hash - ~init:initial_storage - ~burn_cap:(Tez.of_int 2) + ~admin + ~fa12_script client - fa12_script.name protocol in let initial_mint = Tez.of_mutez_int 20000 in - let mint_arg = - fa12_script.mint_arg Account.Bootstrap.keys.(1) initial_mint - in let* () = - Client.transfer - ~amount:Tez.zero - ~giver:admin.public_key_hash - ~receiver:fa12_address - ~entrypoint:fa12_script.mint_entrypoint - ~arg:mint_arg - ~burn_cap:Tez.one + mint + ~admin + ~mint:initial_mint + ~dest:Account.Bootstrap.keys.(1) + ~fa12_address + ~fa12_script client in (* originate viewer *)