From cf8532e8f7b47ca58586a84b85d07f3915fa37f1 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 22 May 2018 19:46:50 +0200 Subject: [PATCH] Michelson, Test: fix some test contracts with new annotation syntax --- src/bin_client/test/contracts/accounts.tz | 46 +++++++++++-------- .../test/contracts/big_map_get_add.tz | 2 +- .../test/contracts/cadr_annotation.tz | 4 +- .../test/contracts/macro_annotations.tz | 6 +-- src/bin_client/test/contracts/map_caddaadr.tz | 4 +- src/bin_client/test/contracts/map_car.tz | 6 ++- src/bin_client/test/contracts/reservoir.tz | 12 ++--- src/bin_client/test/contracts/set_caddaadr.tz | 4 +- src/bin_client/test/contracts/set_car.tz | 4 +- src/bin_client/test/contracts/set_cdr.tz | 4 +- .../test/contracts/vote_for_delegate.tz | 6 +-- 11 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/bin_client/test/contracts/accounts.tz b/src/bin_client/test/contracts/accounts.tz index 2496225d9..585fee0e1 100644 --- a/src/bin_client/test/contracts/accounts.tz +++ b/src/bin_client/test/contracts/accounts.tz @@ -3,41 +3,51 @@ # (Right key (pair mutez (signed mutez))) withdraws mutez amount to a # IMPLICIT_ACCOUNT created from the key if the balance is available # and the key is correctly signed -parameter (or key_hash (pair key (pair mutez signature))); +parameter (or (key_hash %Initialize) + (pair %Withdraw + (key %from) + (pair + (mutez %withdraw_amount) + (signature %sig)))); # Maps the key to the balance they have stored -storage (map key_hash mutez); +storage (map :stored_balance key_hash mutez); code { DUP; CAR; # Deposit into account - IF_LEFT { DUP; DIIP{ CDR; DUP }; + IF_LEFT { DUP; DIIP{ CDR %stored_balance; DUP }; DIP{ SWAP }; GET; # Create the account - IF_NONE { DIP{ AMOUNT; SOME }; UPDATE; NIL operation; PAIR } + IF_SOME @previous_balance # Add to an existing account - { AMOUNT; ADD; SOME; SWAP; UPDATE; NIL operation; PAIR }} + { AMOUNT; ADD; SOME; SWAP; UPDATE; NIL operation; PAIR } + { DIP{ AMOUNT; SOME }; UPDATE; NIL operation; PAIR }} # Withdrawl { DUP; DUP; DUP; DUP; # Check signature on data - CAR; DIIP{ CDAR; H }; DIP{ CDDR }; CHECK_SIGNATURE; + CAR %from; + DIIP{ CDAR %withdraw_amount; H @signed_amount }; + DIP{ CDDR %sig }; CHECK_SIGNATURE; IF {} { FAIL }; # Get user account information - DIIP{ CDR; DUP }; CAR; HASH_KEY; DIP{ SWAP }; GET; + DIIP{ CDR %stored_balance; DUP }; + CAR %from; HASH_KEY @from_hash; DIP{ SWAP }; GET; # Account does not exist - IF_NONE { FAIL } + IF_NONE @previous_balance + { FAIL } # Account exists - { DUP; DIIP{ DUP; CDAR; DUP }; + { DUP; DIIP{ DUP; CDAR %withdraw_amount; DUP }; # Ensure funds are available - DIP{ CMPLT }; SWAP; + DIP{ CMPLT @not_enough }; SWAP; IF { FAIL } - { SUB; DIP{ DUP; DIP{ SWAP }}; DUP; + { SUB @new_balance; DIP{ DUP; DIP{ SWAP }}; DUP; # Delete account if balance is 0 - PUSH mutez 0; CMPEQ; - IF { DROP; NONE mutez } + PUSH @zero mutez 0; CMPEQ @null_balance; + IF { DROP; NONE @new_balance mutez } # Otherwise update storage with new balance - { SOME }; - SWAP; CAR; HASH_KEY; UPDATE; - SWAP; DUP; CDAR; + { SOME @new_balance }; + SWAP; CAR %from; HASH_KEY @from_hash; UPDATE; + SWAP; DUP; CDAR %withdraw_amount; # Execute the transfer - DIP{ CAR; HASH_KEY; IMPLICIT_ACCOUNT }; UNIT; - TRANSFER_TOKENS; + DIP{ CAR %from; HASH_KEY @from_hash; IMPLICIT_ACCOUNT @from_account}; UNIT; + TRANSFER_TOKENS @widthdraw_transfer_op; NIL operation; SWAP; CONS; PAIR }}}} diff --git a/src/bin_client/test/contracts/big_map_get_add.tz b/src/bin_client/test/contracts/big_map_get_add.tz index 63c6b5489..2dcf1ce69 100644 --- a/src/bin_client/test/contracts/big_map_get_add.tz +++ b/src/bin_client/test/contracts/big_map_get_add.tz @@ -1,4 +1,4 @@ -parameter (pair (pair @set_pair int (option int)) (pair @check_pair int (option int))) ; +parameter (pair (pair %set_pair int (option int)) (pair %check_pair int (option int))) ; storage (pair (big_map int int) unit) ; code { DUP ; DIP { CDAR } ; DUP ; DIP { CADR; DUP ; CAR ; DIP { CDR } ; UPDATE ; DUP } ; diff --git a/src/bin_client/test/contracts/cadr_annotation.tz b/src/bin_client/test/contracts/cadr_annotation.tz index b83d483e5..3f4978aeb 100644 --- a/src/bin_client/test/contracts/cadr_annotation.tz +++ b/src/bin_client/test/contracts/cadr_annotation.tz @@ -1,3 +1,3 @@ -parameter (pair (pair unit (string @no_name)) bool); +parameter (pair (pair %p1 unit (string %no_name)) bool); storage unit; -code { CAR @name; CADR @second_name; DROP; UNIT; NIL operation; PAIR } +code { CAR @param; CADR @name %no_name; DROP; UNIT; NIL operation; PAIR } diff --git a/src/bin_client/test/contracts/macro_annotations.tz b/src/bin_client/test/contracts/macro_annotations.tz index 368ba6a0c..f48f18e3d 100644 --- a/src/bin_client/test/contracts/macro_annotations.tz +++ b/src/bin_client/test/contracts/macro_annotations.tz @@ -1,6 +1,6 @@ parameter unit; -storage (pair @truc unit unit); -code { DROP; UNIT ; UNIT ; PAIR ; UNIT ; - DUUP @truc ; +storage (pair (unit %truc) unit); +code { DROP; UNIT ; UNIT ; PAIR %truc ; UNIT ; + DUUP @new_storage ; DIP { DROP ; DROP } ; NIL operation ; PAIR } diff --git a/src/bin_client/test/contracts/map_caddaadr.tz b/src/bin_client/test/contracts/map_caddaadr.tz index 4b6dccce9..45509839c 100644 --- a/src/bin_client/test/contracts/map_caddaadr.tz +++ b/src/bin_client/test/contracts/map_caddaadr.tz @@ -1,4 +1,4 @@ parameter unit; -storage (pair (pair nat (pair nat (pair (pair (pair nat mutez) nat) nat))) nat); -code { MAP_CDADDAADR { PUSH mutez 1000000 ; ADD } ; +storage (pair (pair nat (pair nat (pair (pair (pair (nat %p) (mutez %value)) nat) nat))) nat); +code { MAP_CDADDAADR @new_storage %value { PUSH mutez 1000000 ; ADD } ; NIL operation ; SWAP; SET_CAR }; diff --git a/src/bin_client/test/contracts/map_car.tz b/src/bin_client/test/contracts/map_car.tz index 7c50bffd6..b763590ec 100644 --- a/src/bin_client/test/contracts/map_car.tz +++ b/src/bin_client/test/contracts/map_car.tz @@ -1,3 +1,5 @@ parameter bool; -storage (pair bool nat); -code { DUP; CAR; DIP{CDR}; SWAP; MAP_CAR { AND }; NIL operation; PAIR }; +storage (pair (bool %b) (nat %n)); +code { DUP; CAR; DIP{CDR}; SWAP; + MAP_CAR @new_storage %b { AND }; + NIL operation; PAIR }; diff --git a/src/bin_client/test/contracts/reservoir.tz b/src/bin_client/test/contracts/reservoir.tz index d357e0acb..4e693c9ba 100644 --- a/src/bin_client/test/contracts/reservoir.tz +++ b/src/bin_client/test/contracts/reservoir.tz @@ -1,21 +1,21 @@ parameter unit ; storage (pair - (pair (timestamp @T) (mutez @N)) - (pair (contract @A unit) (contract @B unit))) ; + (pair (timestamp %T) (mutez %N)) + (pair (contract %A unit) (contract %B unit))) ; code - { CDR ; DUP ; CAAR ; # T + { CDR ; DUP ; CAAR %T; # T NOW ; COMPARE ; LE ; - IF { DUP ; CADR ; # N + IF { DUP ; CADR %N; # N BALANCE ; COMPARE ; LE ; IF { NIL operation ; PAIR } - { DUP ; CDDR ; # B + { DUP ; CDDR %B; # B BALANCE ; UNIT ; TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS ; PAIR } } - { DUP ; CDAR ; # A + { DUP ; CDAR %A; # A BALANCE ; UNIT ; TRANSFER_TOKENS ; diff --git a/src/bin_client/test/contracts/set_caddaadr.tz b/src/bin_client/test/contracts/set_caddaadr.tz index db967edb2..e98671e40 100644 --- a/src/bin_client/test/contracts/set_caddaadr.tz +++ b/src/bin_client/test/contracts/set_caddaadr.tz @@ -1,5 +1,5 @@ parameter mutez; -storage (pair (pair nat (pair nat (pair (pair (pair nat mutez) nat) nat))) nat); +storage (pair (pair nat (pair nat (pair (pair (pair (nat %p) (mutez %value)) nat) nat))) nat); code { DUP ; CAR ; SWAP ; CDR ; - SET_CADDAADR @annot ; + SET_CADDAADR @toplevel_pair_name %value ; NIL operation ; PAIR }; diff --git a/src/bin_client/test/contracts/set_car.tz b/src/bin_client/test/contracts/set_car.tz index ec63718d6..460b33856 100644 --- a/src/bin_client/test/contracts/set_car.tz +++ b/src/bin_client/test/contracts/set_car.tz @@ -1,3 +1,3 @@ parameter string; -storage (pair string nat); -code { DUP; CDR; DIP{CAR}; SET_CAR @hello; NIL operation; PAIR }; +storage (pair (string %s) (nat %n)); +code { DUP; CDR; DIP{CAR}; SET_CAR %s; NIL operation; PAIR }; diff --git a/src/bin_client/test/contracts/set_cdr.tz b/src/bin_client/test/contracts/set_cdr.tz index f4080a5e1..d725756bb 100644 --- a/src/bin_client/test/contracts/set_cdr.tz +++ b/src/bin_client/test/contracts/set_cdr.tz @@ -1,3 +1,3 @@ parameter nat; -storage (pair string nat); -code { DUP; CDR; DIP{CAR}; SET_CDR @annot; NIL operation; PAIR }; +storage (pair (string %s) (nat %n)); +code { DUP; CDR; DIP{CAR}; SET_CDR %n; NIL operation; PAIR }; diff --git a/src/bin_client/test/contracts/vote_for_delegate.tz b/src/bin_client/test/contracts/vote_for_delegate.tz index eac5145fa..0fba38a62 100644 --- a/src/bin_client/test/contracts/vote_for_delegate.tz +++ b/src/bin_client/test/contracts/vote_for_delegate.tz @@ -1,9 +1,9 @@ parameter (option key_hash) ; storage (pair - (pair (address @mgr1) (option key_hash)) - (pair (address @mgr2) (option key_hash))) ; + (pair %mgr1 (address %addr) (option key_hash)) + (pair %mgr2 (address %addr) (option key_hash))) ; code { # Update the storage - DUP ; CDAAR ; SOURCE ; + DUP ; CDAAR %addr; SOURCE ; IFCMPEQ { UNPAIR ; SWAP ; SET_CADR } { DUP ; CDDAR ; SOURCE ;