/ tests / tests / execution / complex_async_blocks.adl
complex_async_blocks.adl
  1  /*
  2  seed = 123456789
  3  min_height = 16
  4  
  5  [case]
  6  program = "four_program.alpha"
  7  function = "a"
  8  input = []
  9  */
 10  
 11  // This test checks that the finalization order is correct.
 12  // The functions are invoked in the following order:
 13  // "four::a"
 14  //   --> "two::b"
 15  //        --> "zero::c"
 16  //        --> "one::d"
 17  //   --> "three::e"
 18  //        --> "two::b"
 19  //             --> "zero::c"
 20  //             --> "one::d"
 21  //        --> "one::d"
 22  //        --> "zero::c"
 23  // The future (call graph) produced by the top-level finalize should reflect this structure.
 24  
 25  program zero_program.alpha {
 26      mapping counts: address => u64;
 27  
 28      async transition c() -> Future {
 29          let addr = self.signer;
 30          let f = async {
 31              let count: u64 = counts.get_or_use(addr, 0u64);
 32              counts.set(addr, count + 1u64);
 33          };
 34          return f;
 35      }
 36  
 37      @noupgrade
 38      async constructor() {}
 39  }
 40  
 41  
 42  // --- Next Program --- //
 43  
 44  
 45  program one_program.alpha {
 46      mapping counts: address => u64;
 47  
 48      async transition d() -> Future {
 49          let addr = self.signer;
 50          let f = async {
 51              let count: u64 = counts.get_or_use(addr, 0u64);
 52              counts.set(addr, count + 1u64);
 53          };
 54          return f;
 55      }
 56  
 57      @noupgrade
 58      async constructor() {}
 59  }
 60  
 61  // --- Next Program --- //
 62  
 63  
 64  import zero_program.alpha;
 65  import one_program.alpha;
 66  
 67  program two_program.alpha {
 68      mapping counts: address => u64;
 69  
 70      async transition b() -> Future {
 71          let f0: Future = zero_program.alpha/c();
 72          let f1: Future = one_program.alpha/d();
 73          let addr = self.signer; 
 74  
 75          return async {
 76              f0.await();
 77              f1.await();
 78              let count: u64 = counts.get_or_use(addr, 0u64);
 79              counts.set(addr, count + 1u64);
 80          };
 81      }
 82  
 83      @noupgrade
 84      async constructor() {}
 85  }
 86  
 87  // --- Next Program --- //
 88  
 89  import zero_program.alpha;
 90  import one_program.alpha;
 91  import two_program.alpha;
 92  
 93  program three_program.alpha {
 94      mapping counts: address => u64;
 95  
 96      async transition e() -> Future {
 97          let f0: Future = two_program.alpha/b();
 98          let f1: Future = one_program.alpha/d();
 99          let f2: Future = zero_program.alpha/c();
100          let addr = self.signer;
101          return async {
102              f0.await();
103              f1.await();
104              f2.await();
105              let count: u64 = counts.get_or_use(addr, 0u64);
106              counts.set(addr, count + 1u64);
107          };
108      }
109  
110      @noupgrade
111      async constructor() {}
112  }
113  
114  // --- Next Program --- //
115  
116  import two_program.alpha;
117  import three_program.alpha;
118  
119  program four_program.alpha {
120      mapping counts: address => u64;
121  
122      async transition a() -> Future {
123          let f0: Future = two_program.alpha/b();
124          let f1: Future = three_program.alpha/e();
125          let addr = self.signer;
126          return async {
127              f0.await();
128              f1.await();
129              let count: u64 = counts.get_or_use(addr, 0u64);
130              counts.set(addr, count + 1u64);
131          };
132      }
133  
134      @noupgrade
135      async constructor() {}
136  }