/ tests / tests / interpreter-leo / mapping_async_call.adl
mapping_async_call.adl
 1  program test.alpha {
 2      mapping map: u32 => u32;
 3      async transition main() -> (u32, Future) {
 4          let x = 5u32;
 5          let f = finalize(x);
 6          x = 6;
 7          assert(x == 6);
 8  
 9          // Ensures that that the async call is actually executed (including the asserts in `finalize`).
10          // This is technically illegal since `await` is not allowed in a transition. However, for testing purposes, this
11          // seems fine for now. We should improve this when we have better testing infra for the interpreter
12          f.await(); 
13          return (x, f);
14      }
15  
16      async function finalize(x: u32) {
17          map.set(0u32, 42u32);
18          assert(map.get(0u32) == 42u32);
19          map.set(1u32, map.get(0u32) + x);
20          assert(x == 5); // ensure we're using the old value of `x` not the updated one after the async block
21          assert(map.get(1u32) == 42u32 + 5);
22      }
23  }