/ tests / tests / execution / serialize_deserialize_roundtrip.adl
serialize_deserialize_roundtrip.adl
  1  /*
  2  seed = 123456789
  3  min_height = 16
  4  
  5  [case]
  6  program = "test.alpha"
  7  function = "test_u8_rt"
  8  input = ["42u8"]
  9  [case]
 10  program = "test.alpha"
 11  function = "test_u16_rt"
 12  input = ["1234u16"]
 13  [case]
 14  program = "test.alpha"
 15  function = "test_u32_rt"
 16  input = ["123456u32"]
 17  [case]
 18  program = "test.alpha"
 19  function = "test_u64_rt"
 20  input = ["9876543210u64"]
 21  [case]
 22  program = "test.alpha"
 23  function = "test_u128_rt"
 24  input = ["123456789012345678u128"]
 25  [case]
 26  program = "test.alpha"
 27  function = "test_i8_rt"
 28  input = ["-42i8"]
 29  [case]
 30  program = "test.alpha"
 31  function = "test_i16_rt"
 32  input = ["-1234i16"]
 33  [case]
 34  program = "test.alpha"
 35  function = "test_i32_rt"
 36  input = ["-123456i32"]
 37  [case]
 38  program = "test.alpha"
 39  function = "test_i64_rt"
 40  input = ["-9876543210i64"]
 41  [case]
 42  program = "test.alpha"
 43  function = "test_i128_rt"
 44  input = ["-123456789012345678i128"]
 45  [case]
 46  program = "test.alpha"
 47  function = "test_field_rt"
 48  input = ["123456field"]
 49  [case]
 50  program = "test.alpha"
 51  function = "test_group_rt"
 52  input = ["0group"]
 53  [case]
 54  program = "test.alpha"
 55  function = "test_scalar_rt"
 56  input = ["1scalar"]
 57  [case]
 58  program = "test.alpha"
 59  function = "test_address_rt"
 60  input = ["ax1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc"]
 61  [case]
 62  program = "test.alpha"
 63  function = "test_bool_rt"
 64  input = ["true"]
 65  [case]
 66  program = "test.alpha"
 67  function = "test_bool_rt"
 68  input = ["false"]
 69  [case]
 70  program = "test.alpha"
 71  function = "test_array_rt"
 72  input = ["[10u32, 20u32, 30u32, 40u32]"]
 73  */
 74  
 75  program test.alpha {
 76      mapping results: u8 => bool;
 77  
 78      transition test_u8_rt(value: u8) -> public bool {
 79          let bits: [bool; 34] = Serialize::to_bits(value);
 80          let reconstructed: u8 = Deserialize::from_bits::[u8](bits);
 81          let matches_non_raw: bool = value == reconstructed;
 82  
 83          let bits_raw: [bool; 8] = Serialize::to_bits_raw(value);
 84          let reconstructed_raw: u8 = Deserialize::from_bits_raw::[u8](bits_raw);
 85          let matches_raw: bool = value == reconstructed_raw;
 86  
 87          return matches_non_raw && matches_raw;
 88      }
 89  
 90      transition test_u16_rt(value: u16) -> public bool {
 91          let bits: [bool; 42] = Serialize::to_bits(value);
 92          let reconstructed: u16 = Deserialize::from_bits::[u16](bits);
 93          let matches_non_raw: bool = value == reconstructed;
 94  
 95          let bits_raw: [bool; 16] = Serialize::to_bits_raw(value);
 96          let reconstructed_raw: u16 = Deserialize::from_bits_raw::[u16](bits_raw);
 97          let matches_raw: bool = value == reconstructed_raw;
 98  
 99          return matches_non_raw && matches_raw;
100      }
101  
102      transition test_u32_rt(value: u32) -> public bool {
103          let bits: [bool; 58] = Serialize::to_bits(value);
104          let reconstructed: u32 = Deserialize::from_bits::[u32](bits);
105          let matches_non_raw: bool = value == reconstructed;
106  
107          let bits_raw: [bool; 32] = Serialize::to_bits_raw(value);
108          let reconstructed_raw: u32 = Deserialize::from_bits_raw::[u32](bits_raw);
109          let matches_raw: bool = value == reconstructed_raw;
110  
111          return matches_non_raw && matches_raw;
112      }
113  
114      transition test_u64_rt(value: u64) -> public bool {
115          let bits: [bool; 90] = Serialize::to_bits(value);
116          let reconstructed: u64 = Deserialize::from_bits::[u64](bits);
117          let matches_non_raw: bool = value == reconstructed;
118  
119          let bits_raw: [bool; 64] = Serialize::to_bits_raw(value);
120          let reconstructed_raw: u64 = Deserialize::from_bits_raw::[u64](bits_raw);
121          let matches_raw: bool = value == reconstructed_raw;
122  
123          return matches_non_raw && matches_raw;
124      }
125  
126      transition test_u128_rt(value: u128) -> public bool {
127          let bits: [bool; 154] = Serialize::to_bits(value);
128          let reconstructed: u128 = Deserialize::from_bits::[u128](bits);
129          let matches_non_raw: bool = value == reconstructed;
130  
131          let bits_raw: [bool; 128] = Serialize::to_bits_raw(value);
132          let reconstructed_raw: u128 = Deserialize::from_bits_raw::[u128](bits_raw);
133          let matches_raw: bool = value == reconstructed_raw;
134  
135          return matches_non_raw && matches_raw;
136      }
137  
138      transition test_i8_rt(value: i8) -> public bool {
139          let bits: [bool; 34] = Serialize::to_bits(value);
140          let reconstructed: i8 = Deserialize::from_bits::[i8](bits);
141          let matches_non_raw: bool = value == reconstructed;
142  
143          let bits_raw: [bool; 8] = Serialize::to_bits_raw(value);
144          let reconstructed_raw: i8 = Deserialize::from_bits_raw::[i8](bits_raw);
145          let matches_raw: bool = value == reconstructed_raw;
146  
147          return matches_non_raw && matches_raw;
148      }
149  
150      transition test_i16_rt(value: i16) -> public bool {
151          let bits: [bool; 42] = Serialize::to_bits(value);
152          let reconstructed: i16 = Deserialize::from_bits::[i16](bits);
153          let matches_non_raw: bool = value == reconstructed;
154  
155          let bits_raw: [bool; 16] = Serialize::to_bits_raw(value);
156          let reconstructed_raw: i16 = Deserialize::from_bits_raw::[i16](bits_raw);
157          let matches_raw: bool = value == reconstructed_raw;
158  
159          return matches_non_raw && matches_raw;
160      }
161  
162      transition test_i32_rt(value: i32) -> public bool {
163          let bits: [bool; 58] = Serialize::to_bits(value);
164          let reconstructed: i32 = Deserialize::from_bits::[i32](bits);
165          let matches_non_raw: bool = value == reconstructed;
166  
167          let bits_raw: [bool; 32] = Serialize::to_bits_raw(value);
168          let reconstructed_raw: i32 = Deserialize::from_bits_raw::[i32](bits_raw);
169          let matches_raw: bool = value == reconstructed_raw;
170  
171          return matches_non_raw && matches_raw;
172      }
173  
174      transition test_i64_rt(value: i64) -> public bool {
175          let bits: [bool; 90] = Serialize::to_bits(value);
176          let reconstructed: i64 = Deserialize::from_bits::[i64](bits);
177          let matches_non_raw: bool = value == reconstructed;
178  
179          let bits_raw: [bool; 64] = Serialize::to_bits_raw(value);
180          let reconstructed_raw: i64 = Deserialize::from_bits_raw::[i64](bits_raw);
181          let matches_raw: bool = value == reconstructed_raw;
182  
183          return matches_non_raw && matches_raw;
184      }
185  
186      transition test_i128_rt(value: i128) -> public bool {
187          let bits: [bool; 154] = Serialize::to_bits(value);
188          let reconstructed: i128 = Deserialize::from_bits::[i128](bits);
189          let matches_non_raw: bool = value == reconstructed;
190  
191          let bits_raw: [bool; 128] = Serialize::to_bits_raw(value);
192          let reconstructed_raw: i128 = Deserialize::from_bits_raw::[i128](bits_raw);
193          let matches_raw: bool = value == reconstructed_raw;
194  
195          return matches_non_raw && matches_raw;
196      }
197  
198      transition test_field_rt(value: field) -> public bool {
199          let bits: [bool; 279] = Serialize::to_bits(value);
200          let reconstructed: field = Deserialize::from_bits::[field](bits);
201          let matches_non_raw: bool = value == reconstructed;
202  
203          let bits_raw: [bool; 253] = Serialize::to_bits_raw(value);
204          let reconstructed_raw: field = Deserialize::from_bits_raw::[field](bits_raw);
205          let matches_raw: bool = value == reconstructed_raw;
206  
207          return matches_non_raw && matches_raw;
208      }
209  
210      transition test_group_rt(value: group) -> public bool {
211          let bits: [bool; 279] = Serialize::to_bits(value);
212          let reconstructed: group = Deserialize::from_bits::[group](bits);
213          let matches_non_raw: bool = value == reconstructed;
214  
215          let bits_raw: [bool; 253] = Serialize::to_bits_raw(value);
216          let reconstructed_raw: group = Deserialize::from_bits_raw::[group](bits_raw);
217          let matches_raw: bool = value == reconstructed_raw;
218  
219          return matches_non_raw && matches_raw;
220      }
221  
222      transition test_scalar_rt(value: scalar) -> public bool {
223          let bits: [bool; 277] = Serialize::to_bits(value);
224          let reconstructed: scalar = Deserialize::from_bits::[scalar](bits);
225          let matches_non_raw: bool = value == reconstructed;
226  
227          let bits_raw: [bool; 251] = Serialize::to_bits_raw(value);
228          let reconstructed_raw: scalar = Deserialize::from_bits_raw::[scalar](bits_raw);
229          let matches_raw: bool = value == reconstructed_raw;
230  
231          return matches_non_raw && matches_raw;
232      }
233  
234      transition test_address_rt(value: address) -> public bool {
235          let bits: [bool; 279] = Serialize::to_bits(value);
236          let reconstructed: address = Deserialize::from_bits::[address](bits);
237          let matches_non_raw: bool = value == reconstructed;
238  
239          let bits_raw: [bool; 253] = Serialize::to_bits_raw(value);
240          let reconstructed_raw: address = Deserialize::from_bits_raw::[address](bits_raw);
241          let matches_raw: bool = value == reconstructed_raw;
242  
243          return matches_non_raw && matches_raw;
244      }
245  
246      transition test_bool_rt(value: bool) -> public bool {
247          let bits: [bool; 27] = Serialize::to_bits(value);
248          let reconstructed: bool = Deserialize::from_bits::[bool](bits);
249          let matches_non_raw: bool = value == reconstructed;
250  
251          let bits_raw: [bool; 1] = Serialize::to_bits_raw(value);
252          let reconstructed_raw: bool = Deserialize::from_bits_raw::[bool](bits_raw);
253          let matches_raw: bool = value == reconstructed_raw;
254  
255          return matches_non_raw && matches_raw;
256      }
257  
258      transition test_array_rt(value: [u32; 4]) -> public bool {
259          let bits: [bool; 330] = Serialize::to_bits(value);
260          let reconstructed: [u32; 4] = Deserialize::from_bits::[[u32; 4]](bits);
261          let matches_non_raw: bool =
262              value[0u8] == reconstructed[0u8] &&
263              value[1u8] == reconstructed[1u8] &&
264              value[2u8] == reconstructed[2u8] &&
265              value[3u8] == reconstructed[3u8];
266  
267          let bits_raw: [bool; 128] = Serialize::to_bits_raw(value);
268          let reconstructed_raw: [u32; 4] = Deserialize::from_bits_raw::[[u32; 4]](bits_raw);
269          let matches_raw: bool =
270              value[0u8] == reconstructed_raw[0u8] &&
271              value[1u8] == reconstructed_raw[1u8] &&
272              value[2u8] == reconstructed_raw[2u8] &&
273              value[3u8] == reconstructed_raw[3u8];
274  
275          return matches_non_raw && matches_raw;
276      }
277  
278      @noupgrade
279      async constructor() {}
280  }