Michelson: add tests and doc for SET_CADDAADR and MAP_CADDAADR

This commit is contained in:
Benjamin Canou 2017-09-18 16:18:40 +02:00
parent 7512f2df0b
commit 8b4c94de67
4 changed files with 43 additions and 2 deletions

View File

@ -1187,12 +1187,12 @@ These are macros are simply more convenient syntax for various common operations
* `SET_CAR`:
Set the first value of a pair.
> SET_CAR => CDR; SWAP; PAIR
> SET_CAR => CDR ; SWAP ; PAIR
* `SET_CDR`:
Set the first value of a pair.
> SET_CDR => CAR; PAIR
> SET_CDR => CAR ; PAIR
* `SET_C[AD]+R`:
A syntactic sugar for setting fields in nested pairs.
@ -1202,6 +1202,24 @@ These are macros are simply more convenient syntax for various common operations
> SET_CD(\rest=[AD]+)R ; C / S =>
{ DUP ; DIP { CDR ; SET_C(\rest)R } ; CAR ; PAIR } ; C / S
* `MAP_CAR` code:
Transform the first value of a pair.
> SET_CAR => DUP ; CDR ; SWAP ; code ; CAR ; PAIR
* `MAP_CDR` code:
Transform the first value of a pair.
> SET_CDR => DUP ; CDR ; code ; SWAP ; CAR ; PAIR
* `MAP_C[AD]+R` code:
A syntactic sugar for transforming fields in nested pairs.
> MAP_CA(\rest=[AD]+)R ; C / S =>
{ DUP ; DIP { CAR ; MAP_C(\rest)R code } ; CDR ; SWAP ; PAIR } ; C / S
> MAP_CD(\rest=[AD]+)R ; C / S =>
{ DUP ; DIP { CDR ; MAP_C(\rest)R code } ; CAR ; PAIR } ; C / S
IX - Concrete syntax
----------------------

View File

@ -0,0 +1,6 @@
parameter unit;
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
return (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
code { CDR ;
MAP_CADDAADR { PUSH tez "1.00" ; ADD } ;
DUP ; PAIR };

View File

@ -0,0 +1,7 @@
parameter unit;
storage (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
return (pair (pair nat (pair nat (pair (pair (pair nat tez) nat) nat))) nat);
code { CDR ; DUP ;
DIP { CADDAADR ; PUSH tez "1.00" ; ADD } ;
SET_CADDAADR ;
DUP ; PAIR };

View File

@ -265,6 +265,16 @@ assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 0)' '1' '(Pair "hello" 1
assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 500)' '3' '(Pair "hello" 3)'
assert_output $CONTRACT_PATH/set_cdr.tz '(Pair "hello" 7)' '100' '(Pair "hello" 100)'
assert_output $CONTRACT_PATH/set_caddaadr.tz \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0.00") 4) 5))) 6)' \
'Unit' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'
assert_output $CONTRACT_PATH/map_caddaadr.tz \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "0.00") 4) 5))) 6)' \
'Unit' \
'(Pair (Pair 1 (Pair 2 (Pair (Pair (Pair 3 "1.00") 4) 5))) 6)'
# Did the given key sign the string? (key is bootstrap1)
assert_output $CONTRACT_PATH/check_signature.tz \
'(Pair "26981d372a7b3866621bf79713d249197fe6d518ef702fa65738e1715bde9da54df04fefbcc84287ecaa9f74ad9296462731aa24bbcece63c6bf73a8f5752309" "hello")' \