Fix PascaLIGO ID contract to pass tests
This commit is contained in:
parent
4e984850c1
commit
4d16b006c6
@ -77,9 +77,9 @@ function buy (const parameter : buy; const storage : storage) : list(operation)
|
|||||||
controller = controller ;
|
controller = controller ;
|
||||||
profile = profile ;
|
profile = profile ;
|
||||||
];
|
];
|
||||||
identities[new_id] := Some(new_id_details);
|
identities[new_id] := new_id_details;
|
||||||
end with ((nil : list(operation)), record [
|
end with ((nil : list(operation)), record [
|
||||||
identities = updated_identities;
|
identities = identities;
|
||||||
next_id = new_id + 1;
|
next_id = new_id + 1;
|
||||||
name_price = storage.name_price;
|
name_price = storage.name_price;
|
||||||
skip_price = storage.skip_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.");
|
failwith("Updating owner doesn't cost anything.");
|
||||||
end
|
end
|
||||||
else skip;
|
else skip;
|
||||||
const id : int = parameter[id];
|
const id : int = parameter.id;
|
||||||
const new_owner : address = parameter[new_owner];
|
const new_owner : address = parameter.new_owner;
|
||||||
var identities : big_map (id, id_details) := storage[identities];
|
var identities : big_map (id, id_details) := storage.identities;
|
||||||
const id_details : id_details =
|
const id_details : id_details =
|
||||||
case identities[id] of
|
case identities[id] of
|
||||||
Some(id_details) -> id_details
|
Some(id_details) -> id_details
|
||||||
| None -> (failwith("This ID does not exist."): id_details)
|
| None -> (failwith("This ID does not exist."): id_details)
|
||||||
end;
|
end;
|
||||||
var is_allowed : bool := false;
|
var is_allowed : bool := False;
|
||||||
if sender = id_details[owner]
|
if sender = id_details.owner
|
||||||
then is_allowed := true
|
then is_allowed := True
|
||||||
else failwith("You are not the owner of this ID.");
|
else failwith("You are not the owner of this ID.");
|
||||||
id_details[owner] := new_owner;
|
id_details.owner := new_owner;
|
||||||
identities[id] := Some(id_details);
|
identities[id] := id_details;
|
||||||
end with ((nil: list(operation)), record [
|
end with ((nil: list(operation)), record [
|
||||||
identities = updated_identities;
|
identities = identities;
|
||||||
next_id = storage.next_id;
|
next_id = storage.next_id;
|
||||||
name_price = storage.name_price;
|
name_price = storage.name_price;
|
||||||
skip_price = storage.skip_price;
|
skip_price = storage.skip_price;
|
||||||
@ -121,52 +121,52 @@ function update_details (const parameter : update_details; const storage : stora
|
|||||||
if (amount =/= 0mutez)
|
if (amount =/= 0mutez)
|
||||||
then failwith("Updating details doesn't cost anything.")
|
then failwith("Updating details doesn't cost anything.")
|
||||||
else skip;
|
else skip;
|
||||||
const id : int = parameter[id];
|
const id : int = parameter.id;
|
||||||
const new_profile : option(bytes) = parameter[new_profile];
|
const new_profile : option(bytes) = parameter.new_profile;
|
||||||
const new_controller : option(address) = parameter[new_controller];
|
const new_controller : option(address) = parameter.new_controller;
|
||||||
const identities : big_map (id, id_details) = storage[identities];
|
const identities : big_map (id, id_details) = storage.identities;
|
||||||
const id_details: id_details =
|
const id_details: id_details =
|
||||||
case identities[id] of
|
case identities[id] of
|
||||||
Some(id_details) -> id_details
|
Some(id_details) -> id_details
|
||||||
| None -> (failwith("This ID does not exist."): id_details)
|
| None -> (failwith("This ID does not exist."): id_details)
|
||||||
end;
|
end;
|
||||||
var is_allowed : bool := false;
|
var is_allowed : bool := False;
|
||||||
if (sender = current_id_details[controller]) or (sender = current_id_details[owner])
|
if (sender = id_details.controller) or (sender = id_details.owner)
|
||||||
then is_allowed := true
|
then is_allowed := True
|
||||||
else failwith("You are not the owner or controller of this ID.");
|
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 =
|
const profile: bytes =
|
||||||
case new_profile of
|
case new_profile of
|
||||||
None -> (* Default *) id_details[profile]
|
None -> (* Default *) id_details.profile
|
||||||
| Some(new_profile) -> new_profile
|
| Some(new_profile) -> new_profile
|
||||||
end;
|
end;
|
||||||
const controller: address =
|
const controller: address =
|
||||||
case new_controller of
|
case new_controller of
|
||||||
None -> (* Default *) current_id_details[controller]
|
None -> (* Default *) id_details.controller
|
||||||
| Some(new_controller) -> new_controller
|
| Some(new_controller) -> new_controller
|
||||||
end;
|
end;
|
||||||
id_details[owner] := owner;
|
id_details.owner := owner;
|
||||||
id_details[controller] := controller;
|
id_details.controller := controller;
|
||||||
id_details[profile] := profile;
|
id_details.profile := profile;
|
||||||
identities[id] := Some(id_details);
|
identities[id] := id_details;
|
||||||
end with ((nil: list(operation)), record [
|
end with ((nil: list(operation)), record [
|
||||||
identities = identities;
|
identities = identities;
|
||||||
next_id = storage[next_id];
|
next_id = storage.next_id;
|
||||||
name_price = storage[name_price];
|
name_price = storage.name_price;
|
||||||
skip_price = storage[skip_price];
|
skip_price = storage.skip_price;
|
||||||
])
|
])
|
||||||
|
|
||||||
(* Let someone skip the next identity so nobody has to take one that's undesirable *)
|
(* 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
|
function skip_ (const p: unit; const storage: storage) : list(operation) * storage is
|
||||||
begin
|
begin
|
||||||
if amount = storage[skip_price]
|
if amount = storage.skip_price
|
||||||
then skip
|
then skip
|
||||||
else failwith("Incorrect amount paid.");
|
else failwith("Incorrect amount paid.");
|
||||||
end with ((nil: list(operation)), record [
|
end with ((nil: list(operation)), record [
|
||||||
identities = storage[identities];
|
identities = storage.identities;
|
||||||
next_id = storage[next_id] + 1;
|
next_id = storage.next_id + 1;
|
||||||
name_price = storage[name_price];
|
name_price = storage.name_price;
|
||||||
skip_price = storage[skip_price];
|
skip_price = storage.skip_price;
|
||||||
])
|
])
|
||||||
|
|
||||||
function main (const action : action; const storage : storage) : list(operation) * storage is
|
function main (const action : action; const storage : storage) : list(operation) * storage is
|
||||||
|
@ -474,7 +474,7 @@ let skip () =
|
|||||||
("name_price", e_mutez 1000000) ;
|
("name_price", e_mutez 1000000) ;
|
||||||
("skip_price", e_mutez 1000000) ; ]
|
("skip_price", e_mutez 1000000) ; ]
|
||||||
in
|
in
|
||||||
let%bind () = expect_eq ~options program "skip"
|
let%bind () = expect_eq ~options program "skip_"
|
||||||
(e_pair (e_unit ()) storage)
|
(e_pair (e_unit ()) storage)
|
||||||
(e_pair (e_list []) new_storage)
|
(e_pair (e_list []) new_storage)
|
||||||
in ok ()
|
in ok ()
|
||||||
@ -505,12 +505,12 @@ let skip_wrong_amount () =
|
|||||||
("name_price", e_mutez 1000000) ;
|
("name_price", e_mutez 1000000) ;
|
||||||
("skip_price", e_mutez 1000000) ; ]
|
("skip_price", e_mutez 1000000) ; ]
|
||||||
in
|
in
|
||||||
let%bind () = expect_string_failwith ~options program "skip"
|
let%bind () = expect_string_failwith ~options program "skip_"
|
||||||
(e_pair (e_unit ()) storage)
|
(e_pair (e_unit ()) storage)
|
||||||
"Incorrect amount paid."
|
"Incorrect amount paid."
|
||||||
in ok ()
|
in ok ()
|
||||||
|
|
||||||
let main = test_suite "ID Layer" [
|
let main = test_suite "ID Layer (PascaLIGO)" [
|
||||||
test "buy" buy_id ;
|
test "buy" buy_id ;
|
||||||
test "buy (sender addr)" buy_id_sender_addr ;
|
test "buy (sender addr)" buy_id_sender_addr ;
|
||||||
test "buy (wrong amount)" buy_id_wrong_amount ;
|
test "buy (wrong amount)" buy_id_wrong_amount ;
|
||||||
|
Loading…
Reference in New Issue
Block a user