Commit cf8532e8 authored by Alain Mebsout's avatar Alain Mebsout Committed by Benjamin Canou

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

parent ae6a9770
......@@ -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 }}}}
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 } ;
......
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 }
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 }
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 };
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 };
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 ;
......
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 };
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 };
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 };
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 ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment