/ tests / tests / execution / optional_unwrap_none.adl
optional_unwrap_none.adl
 1  /*
 2  seed = 987654321
 3  min_height = 16
 4  
 5  [case]
 6  program = "unwrap_none_test.alpha"
 7  function = "unwrap_none"
 8  input = []
 9  
10  [case]
11  program = "unwrap_none_test.alpha"
12  function = "unwrap_struct_field_none"
13  input = []
14  */
15  
16  program unwrap_none_test.alpha {
17      // === Direct unwrap of a none value ===
18      transition unwrap_none() {
19          let x: u8? = none;
20          assert(x.unwrap() > 0); // ❌ should fail
21      }
22  
23      // === Struct with optional field ===
24      struct MaybeValue {
25          val: u64?,
26      }
27  
28      transition unwrap_struct_field_none() {
29          let s: MaybeValue = MaybeValue { val: none };
30          assert(s.val.unwrap() > 0); // ❌ should also fail
31      }
32  
33      @noupgrade
34      async constructor() {}
35  }