map_of_maps.aes
1 2 contract MapOfMaps = 3 4 type board = map(int, map(int, string)) 5 type map2('a, 'b, 'c) = map('a, map('b, 'c)) 6 7 record state = { big1 : map2(string, string, string), 8 big2 : map2(string, string, string), 9 small1 : map(string, string), 10 small2 : map(string, string) } 11 12 function empty_state() = 13 { big1 = {}, big2 = {}, 14 small1 = {}, small2 = {} } 15 16 entrypoint init() = empty_state() 17 18 stateful entrypoint setup_state() = 19 let small = {["key"] = "val"} 20 put({ big1 = {["one"] = small}, 21 big2 = {["two"] = small}, 22 small1 = small, 23 small2 = small }) 24 25 // -- Garbage collection of inner map when outer map is garbage collected 26 stateful entrypoint test1_setup() = 27 let inner = {["key"] = "val"} 28 put(empty_state() { big1 = {["one"] = inner} }) 29 30 stateful entrypoint test1_execute() = 31 put(state{ big1 = {} }) 32 33 entrypoint test1_check() = 34 state.big1 35 36 // -- Inplace update 37 38 function small1() = state.small1 39 40 stateful entrypoint test2_setup() = 41 put(empty_state() { small1 = {["key"] = "val"} }) 42 43 stateful entrypoint test2_execute() = 44 put(state{ small1 = small1() }) 45 put(state{ small1["key2"] = "val2" }) 46 47 entrypoint test2_check() = 48 state.small1 49 50 // -- Map equality 51 52 stateful entrypoint test3_setup() = 53 put(empty_state() { small2 = {["a"] = "b"} }) 54 55 entrypoint test3_execute() = 56 () 57 58 entrypoint test3_check() = 59 state.small2 == {["a"] = "b"} 60 61 // -- Returning nested maps 62 63 stateful entrypoint test4_setup() = 64 put(empty_state()) 65 66 stateful entrypoint test4_execute() = 67 put(state{ big1 = {["a"] = {["b"] = "c"}} }) 68 69 entrypoint test4_check() = state.big1 70