Skip to content

Testing framework: untranspilable ticket in bigmap update

type:fixed

small repro of the bug:



module Storage =
  struct
    type tickets = (address, unit ticket) big_map
    type storage_data = {
        price : tez;
    }
    type t = {data : storage_data; tickets : tickets}
  end

type storage = Storage.t

let buy_ticket ({data; tickets} : storage) : operation list * storage =
  let _check_given_amount =
    assert_with_error
      (Tezos.get_amount () = data.price)
      "1" in
  let owner = (Tezos.get_sender()) in
  let (owned_tickets_opt, tickets) =
    Big_map.get_and_update owner (None : unit ticket option) tickets in
  let new_ticket = Tezos.create_ticket unit 1n in
  let join_tickets =
    match owned_tickets_opt with
      None -> new_ticket
    | Some owned_tickets ->
        (match Tezos.join_tickets (owned_tickets, new_ticket) with
            None -> failwith "2"
            | Some joined_tickets -> joined_tickets)
  in
  let (_, tickets) =
    Big_map.get_and_update owner (Some join_tickets) tickets in
  [], {data = data; tickets = tickets}

let main (_, store : unit * storage) =
  buy_ticket(store)


let test_one = 
  let () = Test.reset_state 2n ([] : tez list) in
  let sender_ = Test.nth_bootstrap_account 1 in
  let () = Test.set_source sender_ in

  let init_storage = {
      data = {
        price = 1tz;
      };
      tickets = (Big_map.empty: (address, unit ticket) big_map);
  } in

  let (taddr, _, _) = Test.originate main init_storage 0mutez in
  let contr = Test.to_contract taddr in
  let r = Test.transfer_to_contract contr () 1tez in
  Test.log (r)

During big_map updates (Tezos_state.upd_bigmaps) after baking the transfer operation, a ticket do not have the same "shape":

  1. it has the form Pair [addr,Pair [v,amt]] instead of Pair [addr,v,amt]
  2. the address is represented as bytes

While (2) is normal, (1) is a little bit annoying.

In this MR, for (1) we introduce normalization for tickets (types that match "ticket" prim) and for (2) we handle the cases in which the address is represented as bytes.

Changelog details:

  • Testing framework: fix a bug where a ticket in a big_map was not transpilable
Edited by E. Rivas

Merge request reports

Loading