add tests for big_map
This commit is contained in:
parent
1c281ac079
commit
a9f7bb39e4
@ -8,4 +8,56 @@ function main(const p : unit; const s : storage_) : list(operation) * storage_ i
|
||||
toto := r[23];
|
||||
s.0 := r;
|
||||
}
|
||||
with ((nil: list(operation)), s)
|
||||
with ((nil: list(operation)), s)
|
||||
|
||||
|
||||
|
||||
// type foobar is map(int, int)
|
||||
|
||||
// const fb : foobar = map
|
||||
// 23 -> 0 ;
|
||||
// 42 -> 0 ;
|
||||
// end
|
||||
|
||||
function set_ (var n : int ; var m : storage_) : storage_ is block {
|
||||
var tmp : big_map(int,int) := m.0 ;
|
||||
tmp[23] := n ;
|
||||
m.0 := tmp ;
|
||||
} with m
|
||||
|
||||
function rm (var m : storage_) : storage_ is block {
|
||||
var tmp : big_map(int,int) := m.0 ;
|
||||
remove 42 from map tmp;
|
||||
m.0 := tmp;
|
||||
} with m
|
||||
|
||||
// not supported
|
||||
// function size_ (const m : storage_) : nat is
|
||||
// block {skip} with (size(m.0))
|
||||
|
||||
function gf (const m : storage_) : int is begin skip end with get_force(23, m.0)
|
||||
|
||||
function get (const m : storage_) : option(int) is
|
||||
begin
|
||||
skip
|
||||
end with m.0[42]
|
||||
|
||||
// const bm : storage_ = map
|
||||
// 144 -> 23 ;
|
||||
// 51 -> 23 ;
|
||||
// 42 -> 23 ;
|
||||
// 120 -> 23 ;
|
||||
// 421 -> 23 ;
|
||||
// end
|
||||
|
||||
// not supported
|
||||
// function iter_op (const m : storage_) : int is
|
||||
// var r : int := 0 ;
|
||||
// function aggregate (const i : int ; const j : int) : unit is block { r := r + i + j } with unit ;
|
||||
// block {
|
||||
// map_iter(m.0 , aggregate) ;
|
||||
// } with r ;
|
||||
|
||||
// function map_op (const m : storage_) : storage_ is
|
||||
// function increment (const i : int ; const j : int) : int is block { skip } with j + 1 ;
|
||||
// block { skip } with map_map(m.0 , increment) ;
|
||||
|
@ -392,6 +392,61 @@ let map () : unit result =
|
||||
in
|
||||
ok ()
|
||||
|
||||
let big_map () : unit result =
|
||||
let%bind program = type_file "./contracts/big_map.ligo" in
|
||||
let ez lst =
|
||||
let open Ast_simplified.Combinators in
|
||||
let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
|
||||
e_pair (e_typed_map lst' t_int t_int) (e_unit ())
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||
let make_expected = e_int in
|
||||
expect_eq_n program "gf" make_input make_expected
|
||||
in
|
||||
(* let%bind () =
|
||||
let make_input = fun n -> ez List.(map (fun x -> (x, x)) @@ range n) in
|
||||
let make_expected = e_nat in
|
||||
expect_eq_n_strict_pos_small program "size_" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let expected = ez [(23, 0) ; (42, 0)] in
|
||||
expect_eq_evaluate program "fb" expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n ->
|
||||
let m = ez [(23 , 0) ; (42 , 0)] in
|
||||
e_tuple [(e_int n) ; m]
|
||||
in
|
||||
let make_expected = fun n -> ez [(23 , n) ; (42 , 0)] in
|
||||
expect_eq_n_pos_small program "set_" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||
let make_expected = fun _ -> e_some @@ e_int 4 in
|
||||
expect_eq_n program "get" make_input make_expected
|
||||
in
|
||||
let%bind () =
|
||||
let expected = ez @@ List.map (fun x -> (x, 23)) [144 ; 51 ; 42 ; 120 ; 421] in
|
||||
expect_eq_evaluate program "bm" expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(23, 23) ; (42, 42)] in
|
||||
let expected = ez [23, 23] in
|
||||
expect_eq program "rm" input expected
|
||||
in *)
|
||||
(* let%bind () =
|
||||
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
|
||||
let expected = e_int 66 in
|
||||
expect_eq program "iter_op" input expected
|
||||
in
|
||||
let%bind () =
|
||||
let input = ez [(1 , 10) ; (2 , 20) ; (3 , 30) ] in
|
||||
let expected = ez [(1 , 11) ; (2 , 21) ; (3 , 31) ] in
|
||||
expect_eq program "map_op" input expected
|
||||
in *)
|
||||
ok ()
|
||||
|
||||
let list () : unit result =
|
||||
let%bind program = type_file "./contracts/list.ligo" in
|
||||
let ez lst =
|
||||
@ -690,6 +745,7 @@ let main = test_suite "Integration (End to End)" [
|
||||
test "string" string_expression ;
|
||||
test "option" option ;
|
||||
test "map" map ;
|
||||
test "big_map" big_map ;
|
||||
test "list" list ;
|
||||
test "loop" loop ;
|
||||
test "matching" matching ;
|
||||
|
Loading…
Reference in New Issue
Block a user