@@ -939,6 +939,10 @@ mod tests {
939
939
#[ cfg( test) ]
940
940
mod destructure {
941
941
use super :: * ;
942
+ use crate :: neptune:: neptune_like_types_for_tests:: MmrSuccessorProofLookalike ;
943
+ use crate :: neptune:: neptune_like_types_for_tests:: TransactionKernelLookalike ;
944
+ use crate :: neptune:: neptune_like_types_for_tests:: UpdateWitnessLookalike ;
945
+ use crate :: twenty_first:: util_types:: mmr:: mmr_accumulator:: MmrAccumulator ;
942
946
943
947
#[ test]
944
948
fn unit_struct ( ) {
@@ -967,6 +971,9 @@ mod tests {
967
971
#[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
968
972
struct TupleDynamic ( Vec < u32 > ) ;
969
973
974
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
975
+ struct TupleNested ( Vec < Vec < u32 > > ) ;
976
+
970
977
#[ derive( Debug , Copy , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
971
978
struct NamedStatic {
972
979
field : u32 ,
@@ -977,9 +984,14 @@ mod tests {
977
984
field : Vec < u32 > ,
978
985
}
979
986
987
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
988
+ struct NamedNested {
989
+ field : Vec < Vec < u32 > > ,
990
+ }
991
+
980
992
// This macro is a little bit cursed due to the `$post_process`. Since it is
981
993
// very limited in scope, I say it's better than duplicating essentially the
982
- // same code four times. If you want to extend the scope of this macro, please
994
+ // same code six times. If you want to extend the scope of this macro, please
983
995
// re-design it.
984
996
macro_rules! one_field_test_case {
985
997
( fn $test_name: ident for $ty: ident: $f_name: tt $( $post_process: tt) * ) => {
@@ -998,8 +1010,8 @@ mod tests {
998
1010
let mut non_determinism = NonDeterminism :: default ( ) ;
999
1011
encode_to_memory( & mut non_determinism. ram, ptr, & foo) ;
1000
1012
1001
- let output = VM :: run( program, PublicInput :: default ( ) , non_determinism) ;
1002
- let [ output] = output. unwrap ( ) [ ..] else {
1013
+ let output = VM :: run( program, PublicInput :: default ( ) , non_determinism) ? ;
1014
+ let [ output] = output[ ..] else {
1003
1015
return Err ( TestCaseError :: Fail ( "unexpected output" . into( ) ) ) ;
1004
1016
} ;
1005
1017
@@ -1012,8 +1024,10 @@ mod tests {
1012
1024
1013
1025
one_field_test_case ! ( fn tuple_static for TupleStatic : 0 ) ;
1014
1026
one_field_test_case ! ( fn tuple_dynamic for TupleDynamic : 0 . len( ) ) ;
1027
+ one_field_test_case ! ( fn tuple_nested for TupleNested : 0 . len( ) ) ;
1015
1028
one_field_test_case ! ( fn named_static for NamedStatic : field ) ;
1016
1029
one_field_test_case ! ( fn named_dynamic for NamedDynamic : field. len( ) ) ;
1030
+ one_field_test_case ! ( fn named_nested for NamedNested : field. len( ) ) ;
1017
1031
}
1018
1032
1019
1033
mod two_fields {
@@ -1031,6 +1045,15 @@ mod tests {
1031
1045
#[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1032
1046
struct TupleDynDyn ( Vec < u32 > , Vec < u32 > ) ;
1033
1047
1048
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1049
+ struct TupleStatNest ( u32 , Vec < Vec < u32 > > ) ;
1050
+
1051
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1052
+ struct TupleNestStat ( Vec < Vec < u32 > > , u32 ) ;
1053
+
1054
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1055
+ struct TupleNestNest ( Vec < Vec < u32 > > , Vec < Vec < u32 > > ) ;
1056
+
1034
1057
#[ derive( Debug , Copy , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1035
1058
struct NamedStatStat {
1036
1059
a : u32 ,
@@ -1055,9 +1078,27 @@ mod tests {
1055
1078
b : Vec < u32 > ,
1056
1079
}
1057
1080
1081
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1082
+ struct NamedStatNest {
1083
+ a : u32 ,
1084
+ b : Vec < Vec < u32 > > ,
1085
+ }
1086
+
1087
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1088
+ struct NamedNestStat {
1089
+ a : Vec < Vec < u32 > > ,
1090
+ b : u32 ,
1091
+ }
1092
+
1093
+ #[ derive( Debug , Clone , BFieldCodec , TasmObject , Arbitrary ) ]
1094
+ struct NamedNestNest {
1095
+ a : Vec < Vec < u32 > > ,
1096
+ b : Vec < Vec < u32 > > ,
1097
+ }
1098
+
1058
1099
// This macro is a little bit cursed due to the `$post_process`es. Since it is
1059
1100
// very limited in scope, I say it's better than duplicating essentially the
1060
- // same code eight times. If you want to extend the scope of this macro, please
1101
+ // same code 14 times. If you want to extend the scope of this macro, please
1061
1102
// re-design it.
1062
1103
macro_rules! two_fields_test_case {
1063
1104
( fn $test_name: ident for $ty: ident:
@@ -1080,8 +1121,8 @@ mod tests {
1080
1121
let mut non_determinism = NonDeterminism :: default ( ) ;
1081
1122
encode_to_memory( & mut non_determinism. ram, ptr, & foo) ;
1082
1123
1083
- let output = VM :: run( program, PublicInput :: default ( ) , non_determinism) ;
1084
- let [ output_0, output_1] = output. unwrap ( ) [ ..] else {
1124
+ let output = VM :: run( program, PublicInput :: default ( ) , non_determinism) ? ;
1125
+ let [ output_0, output_1] = output[ ..] else {
1085
1126
return Err ( TestCaseError :: Fail ( "unexpected output" . into( ) ) ) ;
1086
1127
} ;
1087
1128
@@ -1098,10 +1139,16 @@ mod tests {
1098
1139
two_fields_test_case ! ( fn tuple_stat_dyn for TupleStatDyn : ( 0 ) ( 1 . len( ) ) ) ;
1099
1140
two_fields_test_case ! ( fn tuple_dyn_stat for TupleDynStat : ( 0 . len( ) ) ( 1 ) ) ;
1100
1141
two_fields_test_case ! ( fn tuple_dyn_dyn for TupleDynDyn : ( 0 . len( ) ) ( 1 . len( ) ) ) ;
1142
+ two_fields_test_case ! ( fn tuple_stat_nest for TupleStatNest : ( 0 ) ( 1 . len( ) ) ) ;
1143
+ two_fields_test_case ! ( fn tuple_nest_stat for TupleNestStat : ( 0 . len( ) ) ( 1 ) ) ;
1144
+ two_fields_test_case ! ( fn tuple_nest_nest for TupleNestNest : ( 0 . len( ) ) ( 1 . len( ) ) ) ;
1101
1145
two_fields_test_case ! ( fn named_stat_stat for NamedStatStat : ( a) ( b) ) ;
1102
1146
two_fields_test_case ! ( fn named_stat_dyn for NamedStatDyn : ( a) ( b. len( ) ) ) ;
1103
1147
two_fields_test_case ! ( fn named_dyn_stat for NamedDynStat : ( a. len( ) ) ( b) ) ;
1104
1148
two_fields_test_case ! ( fn named_dyn_dyn for NamedDynDyn : ( a. len( ) ) ( b. len( ) ) ) ;
1149
+ two_fields_test_case ! ( fn named_stat_nest for NamedStatNest : ( a) ( b. len( ) ) ) ;
1150
+ two_fields_test_case ! ( fn named_nest_stat for NamedNestStat : ( a. len( ) ) ( b) ) ;
1151
+ two_fields_test_case ! ( fn named_nest_nest for NamedNestNest : ( a. len( ) ) ( b. len( ) ) ) ;
1105
1152
}
1106
1153
1107
1154
#[ test]
@@ -1165,6 +1212,64 @@ mod tests {
1165
1212
let foo_again = Foo { a, b, c, d, e } ;
1166
1213
assert_eq ! ( foo, foo_again) ;
1167
1214
}
1215
+
1216
+ #[ proptest]
1217
+ fn destructure_update_witness (
1218
+ #[ strategy( arb( ) ) ] witness : UpdateWitnessLookalike ,
1219
+ #[ strategy( arb( ) ) ] witness_ptr : BFieldElement ,
1220
+ ) {
1221
+ let mut non_determinism = NonDeterminism :: default ( ) ;
1222
+ encode_to_memory ( & mut non_determinism. ram , witness_ptr, & witness) ;
1223
+
1224
+ let program = triton_program ! {
1225
+ read_io 1
1226
+ { & UpdateWitnessLookalike :: destructure( ) }
1227
+ write_io 5 write_io 5 write_io 4
1228
+ halt
1229
+ } ;
1230
+
1231
+ let input = PublicInput :: new ( vec ! [ witness_ptr] ) ;
1232
+ let output = VM :: run ( program, input, non_determinism. clone ( ) ) ?;
1233
+ let mut output = output. into_iter ( ) ;
1234
+ let mut next_ptr = || output. next ( ) . unwrap ( ) ;
1235
+ let ram = & non_determinism. ram ;
1236
+
1237
+ let old_kernel =
1238
+ * TransactionKernelLookalike :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1239
+ let new_kernel =
1240
+ * TransactionKernelLookalike :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1241
+ let old_kernel_mast_hash = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1242
+ let new_kernel_mast_hash = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1243
+ let old_proof = * Proof :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1244
+ let new_swbfi_bagged = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1245
+ let new_aocl = * MmrAccumulator :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1246
+ let new_swbfa_hash = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1247
+ let old_swbfi_bagged = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1248
+ let old_aocl = * MmrAccumulator :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1249
+ let old_swbfa_hash = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1250
+ let aocl_successor_proof =
1251
+ * MmrSuccessorProofLookalike :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1252
+ let outputs_hash = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1253
+ let public_announcements_hash = * Digest :: decode_from_memory ( ram, next_ptr ( ) ) . unwrap ( ) ;
1254
+
1255
+ let witness_again = UpdateWitnessLookalike {
1256
+ old_kernel,
1257
+ new_kernel,
1258
+ old_kernel_mast_hash,
1259
+ new_kernel_mast_hash,
1260
+ old_proof,
1261
+ new_swbfi_bagged,
1262
+ new_aocl,
1263
+ new_swbfa_hash,
1264
+ old_swbfi_bagged,
1265
+ old_aocl,
1266
+ old_swbfa_hash,
1267
+ aocl_successor_proof,
1268
+ outputs_hash,
1269
+ public_announcements_hash,
1270
+ } ;
1271
+ prop_assert_eq ! ( witness, witness_again) ;
1272
+ }
1168
1273
}
1169
1274
1170
1275
#[ test]
0 commit comments