From 4d16b006c6c99f1fa499f62dd46164aba03e894a Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 27 Feb 2020 23:22:55 -0800 Subject: [PATCH] Fix PascaLIGO ID contract to pass tests --- src/test/contracts/id.ligo | 66 +++++++++++++++++++------------------- src/test/id_tests_p.ml | 6 ++-- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/test/contracts/id.ligo b/src/test/contracts/id.ligo index ec4d3c1ca..7f6418127 100644 --- a/src/test/contracts/id.ligo +++ b/src/test/contracts/id.ligo @@ -77,9 +77,9 @@ function buy (const parameter : buy; const storage : storage) : list(operation) controller = controller ; profile = profile ; ]; - identities[new_id] := Some(new_id_details); + identities[new_id] := new_id_details; end with ((nil : list(operation)), record [ - identities = updated_identities; + identities = identities; next_id = new_id + 1; name_price = storage.name_price; skip_price = storage.skip_price; @@ -94,22 +94,22 @@ function update_owner (const parameter : update_owner; const storage : storage) failwith("Updating owner doesn't cost anything."); end else skip; - const id : int = parameter[id]; - const new_owner : address = parameter[new_owner]; - var identities : big_map (id, id_details) := storage[identities]; + const id : int = parameter.id; + const new_owner : address = parameter.new_owner; + var identities : big_map (id, id_details) := storage.identities; const id_details : id_details = case identities[id] of Some(id_details) -> id_details | None -> (failwith("This ID does not exist."): id_details) end; - var is_allowed : bool := false; - if sender = id_details[owner] - then is_allowed := true + var is_allowed : bool := False; + if sender = id_details.owner + then is_allowed := True else failwith("You are not the owner of this ID."); - id_details[owner] := new_owner; - identities[id] := Some(id_details); + id_details.owner := new_owner; + identities[id] := id_details; end with ((nil: list(operation)), record [ - identities = updated_identities; + identities = identities; next_id = storage.next_id; name_price = storage.name_price; skip_price = storage.skip_price; @@ -121,52 +121,52 @@ function update_details (const parameter : update_details; const storage : stora if (amount =/= 0mutez) then failwith("Updating details doesn't cost anything.") else skip; - const id : int = parameter[id]; - const new_profile : option(bytes) = parameter[new_profile]; - const new_controller : option(address) = parameter[new_controller]; - const identities : big_map (id, id_details) = storage[identities]; + const id : int = parameter.id; + const new_profile : option(bytes) = parameter.new_profile; + const new_controller : option(address) = parameter.new_controller; + const identities : big_map (id, id_details) = storage.identities; const id_details: id_details = case identities[id] of Some(id_details) -> id_details | None -> (failwith("This ID does not exist."): id_details) end; - var is_allowed : bool := false; - if (sender = current_id_details[controller]) or (sender = current_id_details[owner]) - then is_allowed := true + var is_allowed : bool := False; + if (sender = id_details.controller) or (sender = id_details.owner) + then is_allowed := True else failwith("You are not the owner or controller of this ID."); - const owner: address = id_details[owner]; + const owner: address = id_details.owner; const profile: bytes = case new_profile of - None -> (* Default *) id_details[profile] + None -> (* Default *) id_details.profile | Some(new_profile) -> new_profile end; const controller: address = case new_controller of - None -> (* Default *) current_id_details[controller] + None -> (* Default *) id_details.controller | Some(new_controller) -> new_controller end; - id_details[owner] := owner; - id_details[controller] := controller; - id_details[profile] := profile; - identities[id] := Some(id_details); + id_details.owner := owner; + id_details.controller := controller; + id_details.profile := profile; + identities[id] := id_details; end with ((nil: list(operation)), record [ identities = identities; - next_id = storage[next_id]; - name_price = storage[name_price]; - skip_price = storage[skip_price]; + next_id = storage.next_id; + name_price = storage.name_price; + skip_price = storage.skip_price; ]) (* Let someone skip the next identity so nobody has to take one that's undesirable *) function skip_ (const p: unit; const storage: storage) : list(operation) * storage is begin - if amount = storage[skip_price] + if amount = storage.skip_price then skip else failwith("Incorrect amount paid."); end with ((nil: list(operation)), record [ - identities = storage[identities]; - next_id = storage[next_id] + 1; - name_price = storage[name_price]; - skip_price = storage[skip_price]; + identities = storage.identities; + next_id = storage.next_id + 1; + name_price = storage.name_price; + skip_price = storage.skip_price; ]) function main (const action : action; const storage : storage) : list(operation) * storage is diff --git a/src/test/id_tests_p.ml b/src/test/id_tests_p.ml index ab98a8c95..81f08c556 100644 --- a/src/test/id_tests_p.ml +++ b/src/test/id_tests_p.ml @@ -474,7 +474,7 @@ let skip () = ("name_price", e_mutez 1000000) ; ("skip_price", e_mutez 1000000) ; ] in - let%bind () = expect_eq ~options program "skip" + let%bind () = expect_eq ~options program "skip_" (e_pair (e_unit ()) storage) (e_pair (e_list []) new_storage) in ok () @@ -505,12 +505,12 @@ let skip_wrong_amount () = ("name_price", e_mutez 1000000) ; ("skip_price", e_mutez 1000000) ; ] in - let%bind () = expect_string_failwith ~options program "skip" + let%bind () = expect_string_failwith ~options program "skip_" (e_pair (e_unit ()) storage) "Incorrect amount paid." in ok () -let main = test_suite "ID Layer" [ +let main = test_suite "ID Layer (PascaLIGO)" [ test "buy" buy_id ; test "buy (sender addr)" buy_id_sender_addr ; test "buy (wrong amount)" buy_id_wrong_amount ;