/ tests / tests / execution / optional_inputs_and_outputs_fail.adl
optional_inputs_and_outputs_fail.adl
  1  /*
  2  seed = 123456789
  3  min_height = 16
  4  
  5  # === Primitive Optionals ===
  6  
  7  [case]
  8  program = "test.alpha"
  9  function = "u64_in_out"
 10  input = ["{is_some:true, val:42u64}"]
 11  
 12  [case]
 13  program = "test.alpha"
 14  function = "u64_in_out"
 15  input = ["{is_some:false, val:0u64}"]
 16  
 17  [case]
 18  program = "test.alpha"
 19  function = "u8_in_out"
 20  input = ["{is_some:true, val:7u8}"]
 21  
 22  [case]
 23  program = "test.alpha"
 24  function = "u8_in_out"
 25  input = ["{is_some:false, val:0u8}"]
 26  
 27  [case]
 28  program = "test.alpha"
 29  function = "bool_in_out"
 30  input = ["{is_some:true, val:true}"]
 31  
 32  [case]
 33  program = "test.alpha"
 34  function = "bool_in_out"
 35  input = ["{is_some:false, val:false}"]
 36  
 37  # === Struct Optionals ===
 38  
 39  [case]
 40  program = "test.alpha"
 41  function = "struct_optional"
 42  input = ["{is_some:true, val:{x:{is_some:true, val:99u32}}}"]
 43  
 44  [case]
 45  program = "test.alpha"
 46  function = "struct_optional"
 47  input = ["{is_some:true, val:{x:{is_some:false, val:0u32}}}"]
 48  
 49  [case]
 50  program = "test.alpha"
 51  function = "struct_optional"
 52  input = ["{is_some:false, val:{x:{is_some:false, val:0u32}}}"]
 53  
 54  # === Array Optionals ===
 55  
 56  [case]
 57  program = "test.alpha"
 58  function = "array_optional"
 59  input = ["{is_some:true, val:[{is_some:true, val:1u8}, {is_some:false, val:0u8}]}"]
 60  
 61  [case]
 62  program = "test.alpha"
 63  function = "array_optional"
 64  input = ["{is_some:false, val:[{is_some:false, val:0u8}, {is_some:false, val:0u8}]}"]
 65  */
 66  
 67  // TODO: this test will currently fail because we don't allow inputs and outputs to have optionals in them.
 68  // This test should pass once that restriction is removed
 69  
 70  program test.alpha {
 71      // === Primitive Optionals ===
 72      transition u64_in_out(x: u64?) -> u64? {
 73          if x != none {
 74              assert(x.unwrap() == 42u64);
 75          }
 76          return x;
 77      }
 78  
 79      transition u8_in_out(x: u8?) -> u8? {
 80          if x != none {
 81              assert(x.unwrap() == 7u8);
 82          }
 83          return x;
 84      }
 85  
 86      transition bool_in_out(x: bool?) -> bool? {
 87          if x != none {
 88              assert(x.unwrap() == true);
 89          }
 90          return x;
 91      }
 92  
 93      // === Struct Optionals ===
 94      struct Foo {
 95          x: u32?,
 96      }
 97  
 98      transition struct_optional(f: Foo?) -> Foo? {
 99          if f != none {
100              let inner = f.unwrap();
101              if inner.x != none {
102                  assert(inner.x.unwrap() == 99u32);
103              }
104          }
105          return f;
106      }
107  
108      // === Array Optionals ===
109      transition array_optional(arr: [u8?; 2]?) -> [u8?; 2]? {
110          if arr != none {
111              let unwrapped = arr.unwrap();
112              assert(unwrapped[0].unwrap() == 1u8);
113              assert(unwrapped[1] == none);
114          }
115          return arr;
116      }
117  
118      @noupgrade
119      async constructor() {}
120  }