/ tests / tests / execution / counter_async_block.adl
counter_async_block.adl
 1  /*
 2  seed = 123456789
 3  min_height = 16
 4  
 5  [case]
 6  program = "test.alpha"
 7  function = "dubble"
 8  input = []
 9  private_key = "APrivateKey1zkpH5Ne1Xfd79t61VhK7b6yaYz92yW5dbuVkiFheR7rwCDE"
10  [case]
11  program = "test.alpha"
12  function = "dubble"
13  input = []
14  private_key = "APrivateKey1zkpH5Ne1Xfd79t61VhK7b6yaYz92yW5dbuVkiFheR7rwCDE"
15  [case]
16  program = "test.alpha"
17  function = "dubble"
18  input = []
19  private_key = "APrivateKey1zkpH5Ne1Xfd79t61VhK7b6yaYz92yW5dbuVkiFheR7rwCDE"
20  [case]
21  program = "test.alpha"
22  function = "dubble"
23  input = []
24  private_key = "APrivateKey1zkpH5Ne1Xfd79t61VhK7b6yaYz92yW5dbuVkiFheR7rwCDE"
25  */
26  
27  program test.alpha {
28      const SMALL:u64 = 0_1u64;
29      mapping counter: address => u64;
30  
31      async transition dubble() -> Future {
32          let addr = self.caller;
33          let f = async {
34              const BIG: u64 = 234u64;
35              let current_value: u64 = Mapping::get_or_use(counter, addr, 0_0u64 + BIG + SMALL);
36              Mapping::set(counter, addr, current_value + 1__u64);
37              current_value = Mapping::get(counter, addr);
38              Mapping::set(counter, addr, current_value + 0___1u64);
39              assert(counter.get(addr) == current_value + 1);
40          };
41          return f;
42      }
43  
44      async transition unsafe_increment() -> Future {
45          let addr = self.caller;
46          return async {
47              let current_value: u64 = Mapping::get(counter, addr);
48              for i:u64 in SMALL..10u64 {
49                  current_value = current_value + 1u64;
50              }
51              Mapping::set(counter, addr, current_value + 0__1u64);
52          };
53      }
54  
55      @noupgrade
56      async constructor() {}
57  }