Michelson, Test: fix some test contracts with new annotation syntax

This commit is contained in:
Alain Mebsout 2018-05-22 19:46:50 +02:00 committed by Benjamin Canou
parent ae6a97708e
commit cf8532e8f7
11 changed files with 55 additions and 43 deletions

View File

@ -3,41 +3,51 @@
# (Right key (pair mutez (signed mutez))) withdraws mutez amount to a # (Right key (pair mutez (signed mutez))) withdraws mutez amount to a
# IMPLICIT_ACCOUNT created from the key if the balance is available # IMPLICIT_ACCOUNT created from the key if the balance is available
# and the key is correctly signed # 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 # Maps the key to the balance they have stored
storage (map key_hash mutez); storage (map :stored_balance key_hash mutez);
code { DUP; CAR; code { DUP; CAR;
# Deposit into account # Deposit into account
IF_LEFT { DUP; DIIP{ CDR; DUP }; IF_LEFT { DUP; DIIP{ CDR %stored_balance; DUP };
DIP{ SWAP }; GET; DIP{ SWAP }; GET;
# Create the account # Create the account
IF_NONE { DIP{ AMOUNT; SOME }; UPDATE; NIL operation; PAIR } IF_SOME @previous_balance
# Add to an existing account # 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 # Withdrawl
{ DUP; DUP; DUP; DUP; { DUP; DUP; DUP; DUP;
# Check signature on data # 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 }; IF {} { FAIL };
# Get user account information # 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 # Account does not exist
IF_NONE { FAIL } IF_NONE @previous_balance
{ FAIL }
# Account exists # Account exists
{ DUP; DIIP{ DUP; CDAR; DUP }; { DUP; DIIP{ DUP; CDAR %withdraw_amount; DUP };
# Ensure funds are available # Ensure funds are available
DIP{ CMPLT }; SWAP; DIP{ CMPLT @not_enough }; SWAP;
IF { FAIL } IF { FAIL }
{ SUB; DIP{ DUP; DIP{ SWAP }}; DUP; { SUB @new_balance; DIP{ DUP; DIP{ SWAP }}; DUP;
# Delete account if balance is 0 # Delete account if balance is 0
PUSH mutez 0; CMPEQ; PUSH @zero mutez 0; CMPEQ @null_balance;
IF { DROP; NONE mutez } IF { DROP; NONE @new_balance mutez }
# Otherwise update storage with new balance # Otherwise update storage with new balance
{ SOME }; { SOME @new_balance };
SWAP; CAR; HASH_KEY; UPDATE; SWAP; CAR %from; HASH_KEY @from_hash; UPDATE;
SWAP; DUP; CDAR; SWAP; DUP; CDAR %withdraw_amount;
# Execute the transfer # Execute the transfer
DIP{ CAR; HASH_KEY; IMPLICIT_ACCOUNT }; UNIT; DIP{ CAR %from; HASH_KEY @from_hash; IMPLICIT_ACCOUNT @from_account}; UNIT;
TRANSFER_TOKENS; TRANSFER_TOKENS @widthdraw_transfer_op;
NIL operation; SWAP; CONS; NIL operation; SWAP; CONS;
PAIR }}}} PAIR }}}}

View File

@ -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) ; storage (pair (big_map int int) unit) ;
code { DUP ; DIP { CDAR } ; code { DUP ; DIP { CDAR } ;
DUP ; DIP { CADR; DUP ; CAR ; DIP { CDR } ; UPDATE ; DUP } ; DUP ; DIP { CADR; DUP ; CAR ; DIP { CDR } ; UPDATE ; DUP } ;

View File

@ -1,3 +1,3 @@
parameter (pair (pair unit (string @no_name)) bool); parameter (pair (pair %p1 unit (string %no_name)) bool);
storage unit; 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 }

View File

@ -1,6 +1,6 @@
parameter unit; parameter unit;
storage (pair @truc unit unit); storage (pair (unit %truc) unit);
code { DROP; UNIT ; UNIT ; PAIR ; UNIT ; code { DROP; UNIT ; UNIT ; PAIR %truc ; UNIT ;
DUUP @truc ; DUUP @new_storage ;
DIP { DROP ; DROP } ; DIP { DROP ; DROP } ;
NIL operation ; PAIR } NIL operation ; PAIR }

View File

@ -1,4 +1,4 @@
parameter unit; parameter unit;
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 { MAP_CDADDAADR { PUSH mutez 1000000 ; ADD } ; code { MAP_CDADDAADR @new_storage %value { PUSH mutez 1000000 ; ADD } ;
NIL operation ; SWAP; SET_CAR }; NIL operation ; SWAP; SET_CAR };

View File

@ -1,3 +1,5 @@
parameter bool; parameter bool;
storage (pair bool nat); storage (pair (bool %b) (nat %n));
code { DUP; CAR; DIP{CDR}; SWAP; MAP_CAR { AND }; NIL operation; PAIR }; code { DUP; CAR; DIP{CDR}; SWAP;
MAP_CAR @new_storage %b { AND };
NIL operation; PAIR };

View File

@ -1,21 +1,21 @@
parameter unit ; parameter unit ;
storage storage
(pair (pair
(pair (timestamp @T) (mutez @N)) (pair (timestamp %T) (mutez %N))
(pair (contract @A unit) (contract @B unit))) ; (pair (contract %A unit) (contract %B unit))) ;
code code
{ CDR ; DUP ; CAAR ; # T { CDR ; DUP ; CAAR %T; # T
NOW ; COMPARE ; LE ; NOW ; COMPARE ; LE ;
IF { DUP ; CADR ; # N IF { DUP ; CADR %N; # N
BALANCE ; BALANCE ;
COMPARE ; LE ; COMPARE ; LE ;
IF { NIL operation ; PAIR } IF { NIL operation ; PAIR }
{ DUP ; CDDR ; # B { DUP ; CDDR %B; # B
BALANCE ; UNIT ; BALANCE ; UNIT ;
TRANSFER_TOKENS ; TRANSFER_TOKENS ;
NIL operation ; SWAP ; CONS ; NIL operation ; SWAP ; CONS ;
PAIR } } PAIR } }
{ DUP ; CDAR ; # A { DUP ; CDAR %A; # A
BALANCE ; BALANCE ;
UNIT ; UNIT ;
TRANSFER_TOKENS ; TRANSFER_TOKENS ;

View File

@ -1,5 +1,5 @@
parameter mutez; 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 ; code { DUP ; CAR ; SWAP ; CDR ;
SET_CADDAADR @annot ; SET_CADDAADR @toplevel_pair_name %value ;
NIL operation ; PAIR }; NIL operation ; PAIR };

View File

@ -1,3 +1,3 @@
parameter string; parameter string;
storage (pair string nat); storage (pair (string %s) (nat %n));
code { DUP; CDR; DIP{CAR}; SET_CAR @hello; NIL operation; PAIR }; code { DUP; CDR; DIP{CAR}; SET_CAR %s; NIL operation; PAIR };

View File

@ -1,3 +1,3 @@
parameter nat; parameter nat;
storage (pair string nat); storage (pair (string %s) (nat %n));
code { DUP; CDR; DIP{CAR}; SET_CDR @annot; NIL operation; PAIR }; code { DUP; CDR; DIP{CAR}; SET_CDR %n; NIL operation; PAIR };

View File

@ -1,9 +1,9 @@
parameter (option key_hash) ; parameter (option key_hash) ;
storage (pair storage (pair
(pair (address @mgr1) (option key_hash)) (pair %mgr1 (address %addr) (option key_hash))
(pair (address @mgr2) (option key_hash))) ; (pair %mgr2 (address %addr) (option key_hash))) ;
code { # Update the storage code { # Update the storage
DUP ; CDAAR ; SOURCE ; DUP ; CDAAR %addr; SOURCE ;
IFCMPEQ IFCMPEQ
{ UNPAIR ; SWAP ; SET_CADR } { UNPAIR ; SWAP ; SET_CADR }
{ DUP ; CDDAR ; SOURCE ; { DUP ; CDDAR ; SOURCE ;