Skip to content

Add `Proxy_ticket` to std_lib

Melwyn Saldanha requested to merge std_lib/prox_ticket into dev

Motivation and Context

Adding the Proxy_ticket module to std_lib will be helpful for testing contracts with tickets

Description

TODOs

  • A new section for Proxy_ticket in reference
  • Add expect tests for tests using Proxy_ticket

Component

  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

The new Proxy_ticket module available in the LIGO std_lib provides a way to test contrast with tickets

For example

If we want to originate a contract with ticket values as its initial storage, we can do

type storage = (bytes ticket) option
type unforged_storage = (bytes unforged_ticket) option

let main (() : unit) (s : storage) : operation list * storage =
  [] , (
    match s with
    | Some ticket ->
      let (_ , t) = Tezos.read_ticket ticket in
      Some t
    | None -> None
  )

let test_originate_contract =
  let mk_storage = fun (t : bytes ticket) -> Some t in
  let ticket_info = (0x0202, 15n) in
  let addr = Test.Proxy_ticket.originate ticket_info mk_storage main in
  let storage : michelson_program = Test.get_storage_of_address addr in
  let unforged_storage = (Test.decompile storage : unforged_storage) in

  (* the ticket 'unforged_storage' can be manipulated freely without caring about ticket linearity *)

  match unforged_storage with
  | Some { ticketer=_ ; value ; amount } ->
    let () = Test.log ("unforged_ticket", unforged_storage) in
    let () = assert (value = ticket_info.0) in
    let () = assert (amount = ticket_info.1) in
    ()
  | None -> failwith "impossible"

Result

$  ligo run test x.mligo
("unforged_ticket" , Some ({amount = 15n ; ticketer = KT1GAXjgbyNsXRj4trR23YRzQdLQV3uA2oXG ; value = 0x0202}))
Everything at the top-level was executed.
- test_originate_contract exited with value ().

Checklist:

  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha

Merge request reports