From 8b4c94de67e435e09d929aab0945ec6a30397184 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Mon, 18 Sep 2017 16:18:40 +0200 Subject: [PATCH] Michelson: add tests and doc for SET_CADDAADR and MAP_CADDAADR --- src/proto/alpha/docs/language.md | 22 ++++++++++++++++++++-- test/contracts/map_caddaadr.tz | 6 ++++++ test/contracts/set_caddaadr.tz | 7 +++++++ test/test_contracts.sh | 10 ++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/contracts/map_caddaadr.tz create mode 100644 test/contracts/set_caddaadr.tz diff --git a/src/proto/alpha/docs/language.md b/src/proto/alpha/docs/language.md index ebdcfe69f..8f7afa129 100644 --- a/src/proto/alpha/docs/language.md +++ b/src/proto/alpha/docs/language.md @@ -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 ---------------------- diff --git a/test/contracts/map_caddaadr.tz b/test/contracts/map_caddaadr.tz new file mode 100644 index 000000000..dc05e4643 --- /dev/null +++ b/test/contracts/map_caddaadr.tz @@ -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 }; diff --git a/test/contracts/set_caddaadr.tz b/test/contracts/set_caddaadr.tz new file mode 100644 index 000000000..467e5c8d9 --- /dev/null +++ b/test/contracts/set_caddaadr.tz @@ -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 }; diff --git a/test/test_contracts.sh b/test/test_contracts.sh index f8039d2f0..79a2e3184 100755 --- a/test/test_contracts.sh +++ b/test/test_contracts.sh @@ -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")' \