casper_types/
gens.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
//! Contains functions for generating arbitrary values for use by
//! [`Proptest`](https://crates.io/crates/proptest).
#![allow(missing_docs)]

use alloc::{
    boxed::Box,
    collections::{BTreeMap, BTreeSet},
    string::String,
    vec,
};

use crate::{
    account::{
        self, action_thresholds::gens::account_action_thresholds_arb,
        associated_keys::gens::account_associated_keys_arb, Account, AccountHash,
    },
    addressable_entity::{
        action_thresholds::gens::action_thresholds_arb, associated_keys::gens::associated_keys_arb,
        MessageTopics, NamedKeyValue, Parameters, Weight,
    },
    block::BlockGlobalAddr,
    byte_code::ByteCodeKind,
    bytesrepr::Bytes,
    contract_messages::{MessageChecksum, MessageTopicSummary, TopicNameHash},
    contracts::{
        Contract, ContractHash, ContractPackage, ContractPackageStatus, ContractVersionKey,
        ContractVersions, EntryPoint as ContractEntryPoint, EntryPoints as ContractEntryPoints,
        NamedKeys,
    },
    crypto::{
        self,
        gens::{public_key_arb_no_system, secret_key_arb_no_system},
    },
    deploy_info::gens::deploy_info_arb,
    global_state::{Pointer, TrieMerkleProof, TrieMerkleProofStep},
    package::{EntityVersionKey, EntityVersions, Groups, PackageStatus},
    system::{
        auction::{
            gens::era_info_arb, Bid, BidAddr, BidKind, DelegationRate, Delegator, DelegatorBid,
            DelegatorKind, Reservation, UnbondingPurse, ValidatorBid, ValidatorCredit,
            WithdrawPurse, DELEGATION_RATE_DENOMINATOR,
        },
        mint::BalanceHoldAddr,
        SystemEntityType,
    },
    transaction::{
        gens::deploy_hash_arb, FieldsContainer, InitiatorAddrAndSecretKey, TransactionArgs,
        TransactionV1Payload,
    },
    transfer::{
        gens::{transfer_v1_addr_arb, transfer_v1_arb},
        TransferAddr,
    },
    AccessRights, AddressableEntity, AddressableEntityHash, BlockTime, ByteCode, CLType, CLValue,
    Digest, EntityAddr, EntityKind, EntryPoint, EntryPointAccess, EntryPointPayment,
    EntryPointType, EntryPoints, EraId, Group, InitiatorAddr, Key, NamedArg, Package, Parameter,
    Phase, PricingMode, ProtocolVersion, PublicKey, RuntimeArgs, SemVer, StoredValue, TimeDiff,
    Timestamp, Transaction, TransactionEntryPoint, TransactionInvocationTarget, TransactionRuntime,
    TransactionScheduling, TransactionTarget, TransactionV1, URef, U128, U256, U512,
};
use proptest::{
    array, bits, bool,
    collection::{self, vec, SizeRange},
    option,
    prelude::*,
    result,
};

pub fn u8_slice_32() -> impl Strategy<Value = [u8; 32]> {
    collection::vec(any::<u8>(), 32).prop_map(|b| {
        let mut res = [0u8; 32];
        res.clone_from_slice(b.as_slice());
        res
    })
}

pub fn u2_slice_32() -> impl Strategy<Value = [u8; 32]> {
    array::uniform32(any::<u8>()).prop_map(|mut arr| {
        for byte in arr.iter_mut() {
            *byte &= 0b11;
        }
        arr
    })
}

pub(crate) fn named_keys_arb(depth: usize) -> impl Strategy<Value = NamedKeys> {
    collection::btree_map("\\PC*", key_arb(), depth).prop_map(NamedKeys::from)
}

pub fn access_rights_arb() -> impl Strategy<Value = AccessRights> {
    prop_oneof![
        Just(AccessRights::NONE),
        Just(AccessRights::READ),
        Just(AccessRights::ADD),
        Just(AccessRights::WRITE),
        Just(AccessRights::READ_ADD),
        Just(AccessRights::READ_WRITE),
        Just(AccessRights::ADD_WRITE),
        Just(AccessRights::READ_ADD_WRITE),
    ]
}

pub fn phase_arb() -> impl Strategy<Value = Phase> {
    prop_oneof![
        Just(Phase::Payment),
        Just(Phase::Session),
        Just(Phase::FinalizePayment),
    ]
}

pub fn uref_arb() -> impl Strategy<Value = URef> {
    (array::uniform32(bits::u8::ANY), access_rights_arb())
        .prop_map(|(id, access_rights)| URef::new(id, access_rights))
}

pub fn era_id_arb() -> impl Strategy<Value = EraId> {
    any::<u64>().prop_map(EraId::from)
}

pub fn key_arb() -> impl Strategy<Value = Key> {
    prop_oneof![
        account_hash_arb().prop_map(Key::Account),
        u8_slice_32().prop_map(Key::Hash),
        uref_arb().prop_map(Key::URef),
        transfer_v1_addr_arb().prop_map(Key::Transfer),
        deploy_hash_arb().prop_map(Key::DeployInfo),
        era_id_arb().prop_map(Key::EraInfo),
        uref_arb().prop_map(|uref| Key::Balance(uref.addr())),
        bid_addr_validator_arb().prop_map(Key::BidAddr),
        bid_addr_delegator_arb().prop_map(Key::BidAddr),
        account_hash_arb().prop_map(Key::Withdraw),
        u8_slice_32().prop_map(Key::Dictionary),
        balance_hold_addr_arb().prop_map(Key::BalanceHold),
        Just(Key::EraSummary),
    ]
}

pub fn colliding_key_arb() -> impl Strategy<Value = Key> {
    prop_oneof![
        u2_slice_32().prop_map(|bytes| Key::Account(AccountHash::new(bytes))),
        u2_slice_32().prop_map(Key::Hash),
        u2_slice_32().prop_map(|bytes| Key::URef(URef::new(bytes, AccessRights::NONE))),
        u2_slice_32().prop_map(|bytes| Key::Transfer(TransferAddr::new(bytes))),
        u2_slice_32().prop_map(Key::Dictionary),
    ]
}

pub fn account_hash_arb() -> impl Strategy<Value = AccountHash> {
    u8_slice_32().prop_map(AccountHash::new)
}

pub fn entity_addr_arb() -> impl Strategy<Value = EntityAddr> {
    prop_oneof![
        u8_slice_32().prop_map(EntityAddr::System),
        u8_slice_32().prop_map(EntityAddr::Account),
        u8_slice_32().prop_map(EntityAddr::SmartContract),
    ]
}

pub fn topic_name_hash_arb() -> impl Strategy<Value = TopicNameHash> {
    u8_slice_32().prop_map(TopicNameHash::new)
}

pub fn bid_addr_validator_arb() -> impl Strategy<Value = BidAddr> {
    u8_slice_32().prop_map(BidAddr::new_validator_addr)
}

pub fn bid_addr_delegator_arb() -> impl Strategy<Value = BidAddr> {
    let x = u8_slice_32();
    let y = u8_slice_32();
    (x, y).prop_map(BidAddr::new_delegator_account_addr)
}

pub fn balance_hold_addr_arb() -> impl Strategy<Value = BalanceHoldAddr> {
    let x = uref_arb().prop_map(|uref| uref.addr());
    let y = any::<u64>();
    (x, y).prop_map(|(x, y)| BalanceHoldAddr::new_gas(x, BlockTime::new(y)))
}

pub fn block_global_addr_arb() -> impl Strategy<Value = BlockGlobalAddr> {
    prop_oneof![
        0 => Just(BlockGlobalAddr::BlockTime),
        1 => Just(BlockGlobalAddr::MessageCount)
    ]
}

pub fn weight_arb() -> impl Strategy<Value = Weight> {
    any::<u8>().prop_map(Weight::new)
}

pub fn account_weight_arb() -> impl Strategy<Value = account::Weight> {
    any::<u8>().prop_map(account::Weight::new)
}

pub fn sem_ver_arb() -> impl Strategy<Value = SemVer> {
    (any::<u32>(), any::<u32>(), any::<u32>())
        .prop_map(|(major, minor, patch)| SemVer::new(major, minor, patch))
}

pub fn protocol_version_arb() -> impl Strategy<Value = ProtocolVersion> {
    sem_ver_arb().prop_map(ProtocolVersion::new)
}

pub fn u128_arb() -> impl Strategy<Value = U128> {
    collection::vec(any::<u8>(), 0..16).prop_map(|b| U128::from_little_endian(b.as_slice()))
}

pub fn u256_arb() -> impl Strategy<Value = U256> {
    collection::vec(any::<u8>(), 0..32).prop_map(|b| U256::from_little_endian(b.as_slice()))
}

pub fn u512_arb() -> impl Strategy<Value = U512> {
    prop_oneof![
        1 => Just(U512::zero()),
        8 => collection::vec(any::<u8>(), 0..64).prop_map(|b| U512::from_little_endian(b.as_slice())),
        1 => Just(U512::MAX),
    ]
}

pub fn cl_simple_type_arb() -> impl Strategy<Value = CLType> {
    prop_oneof![
        Just(CLType::Bool),
        Just(CLType::I32),
        Just(CLType::I64),
        Just(CLType::U8),
        Just(CLType::U32),
        Just(CLType::U64),
        Just(CLType::U128),
        Just(CLType::U256),
        Just(CLType::U512),
        Just(CLType::Unit),
        Just(CLType::String),
        Just(CLType::Key),
        Just(CLType::URef),
    ]
}

pub fn cl_type_arb() -> impl Strategy<Value = CLType> {
    cl_simple_type_arb().prop_recursive(4, 16, 8, |element| {
        prop_oneof![
            // We want to produce basic types too
            element.clone(),
            // For complex type
            element
                .clone()
                .prop_map(|val| CLType::Option(Box::new(val))),
            element.clone().prop_map(|val| CLType::List(Box::new(val))),
            // Realistic Result type generator: ok is anything recursive, err is simple type
            (element.clone(), cl_simple_type_arb()).prop_map(|(ok, err)| CLType::Result {
                ok: Box::new(ok),
                err: Box::new(err)
            }),
            // Realistic Map type generator: key is simple type, value is complex recursive type
            (cl_simple_type_arb(), element.clone()).prop_map(|(key, value)| CLType::Map {
                key: Box::new(key),
                value: Box::new(value)
            }),
            // Various tuples
            element
                .clone()
                .prop_map(|cl_type| CLType::Tuple1([Box::new(cl_type)])),
            (element.clone(), element.clone()).prop_map(|(cl_type1, cl_type2)| CLType::Tuple2([
                Box::new(cl_type1),
                Box::new(cl_type2)
            ])),
            (element.clone(), element.clone(), element).prop_map(
                |(cl_type1, cl_type2, cl_type3)| CLType::Tuple3([
                    Box::new(cl_type1),
                    Box::new(cl_type2),
                    Box::new(cl_type3)
                ])
            ),
        ]
    })
}

pub fn cl_value_arb() -> impl Strategy<Value = CLValue> {
    // If compiler brings you here it most probably means you've added a variant to `CLType` enum
    // but forgot to add generator for it.
    let stub: Option<CLType> = None;
    if let Some(cl_type) = stub {
        match cl_type {
            CLType::Bool
            | CLType::I32
            | CLType::I64
            | CLType::U8
            | CLType::U32
            | CLType::U64
            | CLType::U128
            | CLType::U256
            | CLType::U512
            | CLType::Unit
            | CLType::String
            | CLType::Key
            | CLType::URef
            | CLType::PublicKey
            | CLType::Option(_)
            | CLType::List(_)
            | CLType::ByteArray(..)
            | CLType::Result { .. }
            | CLType::Map { .. }
            | CLType::Tuple1(_)
            | CLType::Tuple2(_)
            | CLType::Tuple3(_)
            | CLType::Any => (),
        }
    };

    prop_oneof![
        Just(CLValue::from_t(()).expect("should create CLValue")),
        any::<bool>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        any::<i32>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        any::<i64>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        any::<u8>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        any::<u32>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        any::<u64>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        u128_arb().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        u256_arb().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        u512_arb().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        key_arb().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        uref_arb().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        ".*".prop_map(|x: String| CLValue::from_t(x).expect("should create CLValue")),
        option::of(any::<u64>()).prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        collection::vec(uref_arb(), 0..100)
            .prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        result::maybe_err(key_arb(), ".*")
            .prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        collection::btree_map(".*", u512_arb(), 0..100)
            .prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        any::<bool>().prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        (any::<bool>(), any::<i32>())
            .prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        (any::<bool>(), any::<i32>(), any::<i64>())
            .prop_map(|x| CLValue::from_t(x).expect("should create CLValue")),
        // Fixed lists of any size
        any::<u8>().prop_map(|len| CLValue::from_t([len; 32]).expect("should create CLValue")),
    ]
}

pub fn result_arb() -> impl Strategy<Value = Result<u32, u32>> {
    result::maybe_ok(any::<u32>(), any::<u32>())
}

pub fn named_args_arb() -> impl Strategy<Value = NamedArg> {
    (".*", cl_value_arb()).prop_map(|(name, value)| NamedArg::new(name, value))
}

pub fn group_arb() -> impl Strategy<Value = Group> {
    ".*".prop_map(Group::new)
}

pub fn entry_point_access_arb() -> impl Strategy<Value = EntryPointAccess> {
    prop_oneof![
        Just(EntryPointAccess::Public),
        collection::vec(group_arb(), 0..32).prop_map(EntryPointAccess::Groups),
        Just(EntryPointAccess::Template),
    ]
}

pub fn entry_point_type_arb() -> impl Strategy<Value = EntryPointType> {
    prop_oneof![
        Just(EntryPointType::Caller),
        Just(EntryPointType::Called),
        Just(EntryPointType::Factory),
    ]
}

pub fn entry_point_payment_arb() -> impl Strategy<Value = EntryPointPayment> {
    prop_oneof![
        Just(EntryPointPayment::Caller),
        Just(EntryPointPayment::DirectInvocationOnly),
        Just(EntryPointPayment::SelfOnward),
    ]
}

pub fn parameter_arb() -> impl Strategy<Value = Parameter> {
    (".*", cl_type_arb()).prop_map(|(name, cl_type)| Parameter::new(name, cl_type))
}

pub fn parameters_arb() -> impl Strategy<Value = Parameters> {
    collection::vec(parameter_arb(), 0..10)
}

pub fn entry_point_arb() -> impl Strategy<Value = EntryPoint> {
    (
        ".*",
        parameters_arb(),
        entry_point_type_arb(),
        entry_point_access_arb(),
        entry_point_payment_arb(),
        cl_type_arb(),
    )
        .prop_map(
            |(name, parameters, entry_point_type, entry_point_access, entry_point_payment, ret)| {
                EntryPoint::new(
                    name,
                    parameters,
                    ret,
                    entry_point_access,
                    entry_point_type,
                    entry_point_payment,
                )
            },
        )
}

pub fn contract_entry_point_arb() -> impl Strategy<Value = ContractEntryPoint> {
    (
        ".*",
        parameters_arb(),
        entry_point_type_arb(),
        entry_point_access_arb(),
        cl_type_arb(),
    )
        .prop_map(
            |(name, parameters, entry_point_type, entry_point_access, ret)| {
                ContractEntryPoint::new(name, parameters, ret, entry_point_access, entry_point_type)
            },
        )
}

pub fn entry_points_arb() -> impl Strategy<Value = EntryPoints> {
    collection::vec(entry_point_arb(), 1..10).prop_map(EntryPoints::from)
}

pub fn contract_entry_points_arb() -> impl Strategy<Value = ContractEntryPoints> {
    collection::vec(contract_entry_point_arb(), 1..10).prop_map(ContractEntryPoints::from)
}

pub fn message_topics_arb() -> impl Strategy<Value = MessageTopics> {
    collection::vec(any::<String>(), 1..100).prop_map(|topic_names| {
        MessageTopics::from(
            topic_names
                .into_iter()
                .map(|name| {
                    let name_hash = crypto::blake2b(&name).into();
                    (name, name_hash)
                })
                .collect::<BTreeMap<String, TopicNameHash>>(),
        )
    })
}

pub fn account_arb() -> impl Strategy<Value = Account> {
    (
        account_hash_arb(),
        named_keys_arb(20),
        uref_arb(),
        account_associated_keys_arb(),
        account_action_thresholds_arb(),
    )
        .prop_map(
            |(account_hash, named_keys, main_purse, associated_keys, action_thresholds)| {
                Account::new(
                    account_hash,
                    named_keys,
                    main_purse,
                    associated_keys,
                    action_thresholds,
                )
            },
        )
}

pub fn contract_package_arb() -> impl Strategy<Value = ContractPackage> {
    (
        uref_arb(),
        contract_versions_arb(),
        disabled_contract_versions_arb(),
        groups_arb(),
    )
        .prop_map(|(access_key, versions, disabled_versions, groups)| {
            ContractPackage::new(
                access_key,
                versions,
                disabled_versions,
                groups,
                ContractPackageStatus::default(),
            )
        })
}

pub fn contract_arb() -> impl Strategy<Value = Contract> {
    (
        protocol_version_arb(),
        contract_entry_points_arb(),
        u8_slice_32(),
        u8_slice_32(),
        named_keys_arb(20),
    )
        .prop_map(
            |(
                protocol_version,
                entry_points,
                contract_package_hash_arb,
                contract_wasm_hash,
                named_keys,
            )| {
                Contract::new(
                    contract_package_hash_arb.into(),
                    contract_wasm_hash.into(),
                    named_keys,
                    entry_points,
                    protocol_version,
                )
            },
        )
}

pub fn system_entity_type_arb() -> impl Strategy<Value = SystemEntityType> {
    prop_oneof![
        Just(SystemEntityType::Mint),
        Just(SystemEntityType::HandlePayment),
        Just(SystemEntityType::StandardPayment),
        Just(SystemEntityType::Auction),
    ]
}

pub fn transaction_runtime_arb() -> impl Strategy<Value = TransactionRuntime> {
    prop_oneof![
        Just(TransactionRuntime::VmCasperV1),
        Just(TransactionRuntime::VmCasperV2),
    ]
}

pub fn entity_kind_arb() -> impl Strategy<Value = EntityKind> {
    prop_oneof![
        system_entity_type_arb().prop_map(EntityKind::System),
        account_hash_arb().prop_map(EntityKind::Account),
        transaction_runtime_arb().prop_map(EntityKind::SmartContract),
    ]
}

pub fn addressable_entity_hash_arb() -> impl Strategy<Value = AddressableEntityHash> {
    u8_slice_32().prop_map(AddressableEntityHash::new)
}

pub fn addressable_entity_arb() -> impl Strategy<Value = AddressableEntity> {
    (
        protocol_version_arb(),
        u8_slice_32(),
        u8_slice_32(),
        uref_arb(),
        associated_keys_arb(),
        action_thresholds_arb(),
        entity_kind_arb(),
    )
        .prop_map(
            |(
                protocol_version,
                contract_package_hash_arb,
                contract_wasm_hash,
                main_purse,
                associated_keys,
                action_thresholds,
                entity_kind,
            )| {
                AddressableEntity::new(
                    contract_package_hash_arb.into(),
                    contract_wasm_hash.into(),
                    protocol_version,
                    main_purse,
                    associated_keys,
                    action_thresholds,
                    entity_kind,
                )
            },
        )
}

pub fn byte_code_arb() -> impl Strategy<Value = ByteCode> {
    collection::vec(any::<u8>(), 1..1000)
        .prop_map(|byte_code| ByteCode::new(ByteCodeKind::V1CasperWasm, byte_code))
}

pub fn contract_version_key_arb() -> impl Strategy<Value = ContractVersionKey> {
    (1..32u32, 1..1000u32)
        .prop_map(|(major, contract_ver)| ContractVersionKey::new(major, contract_ver))
}

pub fn entity_version_key_arb() -> impl Strategy<Value = EntityVersionKey> {
    (1..32u32, 1..1000u32)
        .prop_map(|(major, contract_ver)| EntityVersionKey::new(major, contract_ver))
}

pub fn contract_versions_arb() -> impl Strategy<Value = ContractVersions> {
    collection::btree_map(
        contract_version_key_arb(),
        u8_slice_32().prop_map(ContractHash::new),
        1..5,
    )
}

pub fn entity_versions_arb() -> impl Strategy<Value = EntityVersions> {
    collection::btree_map(
        entity_version_key_arb(),
        u8_slice_32().prop_map(AddressableEntityHash::new),
        1..5,
    )
    .prop_map(EntityVersions::from)
}

pub fn disabled_versions_arb() -> impl Strategy<Value = BTreeSet<EntityVersionKey>> {
    collection::btree_set(entity_version_key_arb(), 0..5)
}

pub fn disabled_contract_versions_arb() -> impl Strategy<Value = BTreeSet<ContractVersionKey>> {
    collection::btree_set(contract_version_key_arb(), 0..5)
}

pub fn groups_arb() -> impl Strategy<Value = Groups> {
    collection::btree_map(group_arb(), collection::btree_set(uref_arb(), 1..10), 0..5)
        .prop_map(Groups::from)
}

pub fn package_arb() -> impl Strategy<Value = Package> {
    (entity_versions_arb(), disabled_versions_arb(), groups_arb()).prop_map(
        |(versions, disabled_versions, groups)| {
            Package::new(
                versions,
                disabled_versions,
                groups,
                PackageStatus::default(),
            )
        },
    )
}

pub(crate) fn delegator_arb() -> impl Strategy<Value = Delegator> {
    (
        public_key_arb_no_system(),
        u512_arb(),
        uref_arb(),
        public_key_arb_no_system(),
    )
        .prop_map(
            |(delegator_pk, staked_amount, bonding_purse, validator_pk)| {
                Delegator::unlocked(delegator_pk, staked_amount, bonding_purse, validator_pk)
            },
        )
}

pub(crate) fn delegator_kind_arb() -> impl Strategy<Value = DelegatorKind> {
    prop_oneof![
        public_key_arb_no_system().prop_map(DelegatorKind::PublicKey),
        array::uniform32(bits::u8::ANY).prop_map(DelegatorKind::Purse)
    ]
}

pub(crate) fn delegator_bid_arb() -> impl Strategy<Value = DelegatorBid> {
    (
        public_key_arb_no_system(),
        u512_arb(),
        uref_arb(),
        public_key_arb_no_system(),
    )
        .prop_map(
            |(delegator_pk, staked_amount, bonding_purse, validator_pk)| {
                DelegatorBid::unlocked(
                    delegator_pk.into(),
                    staked_amount,
                    bonding_purse,
                    validator_pk,
                )
            },
        )
}

fn delegation_rate_arb() -> impl Strategy<Value = DelegationRate> {
    0..=DELEGATION_RATE_DENOMINATOR // Maximum, allowed value for delegation rate.
}

pub(crate) fn reservation_bid_arb() -> impl Strategy<Value = BidKind> {
    reservation_arb().prop_map(|reservation| BidKind::Reservation(Box::new(reservation)))
}

pub(crate) fn reservation_arb() -> impl Strategy<Value = Reservation> {
    (
        public_key_arb_no_system(),
        delegator_kind_arb(),
        delegation_rate_arb(),
    )
        .prop_map(|(validator_pk, delegator_kind, delegation_rate)| {
            Reservation::new(validator_pk, delegator_kind, delegation_rate)
        })
}

pub(crate) fn unified_bid_arb(
    delegations_len: impl Into<SizeRange>,
) -> impl Strategy<Value = BidKind> {
    (
        public_key_arb_no_system(),
        uref_arb(),
        u512_arb(),
        delegation_rate_arb(),
        bool::ANY,
        collection::vec(delegator_arb(), delegations_len),
    )
        .prop_map(
            |(
                validator_public_key,
                bonding_purse,
                staked_amount,
                delegation_rate,
                is_locked,
                new_delegators,
            )| {
                let mut bid = if is_locked {
                    Bid::locked(
                        validator_public_key,
                        bonding_purse,
                        staked_amount,
                        delegation_rate,
                        1u64,
                    )
                } else {
                    Bid::unlocked(
                        validator_public_key,
                        bonding_purse,
                        staked_amount,
                        delegation_rate,
                    )
                };
                let delegators = bid.delegators_mut();
                new_delegators.into_iter().for_each(|delegator| {
                    assert!(delegators
                        .insert(delegator.delegator_public_key().clone(), delegator)
                        .is_none());
                });
                BidKind::Unified(Box::new(bid))
            },
        )
}

pub(crate) fn delegator_bid_kind_arb() -> impl Strategy<Value = BidKind> {
    delegator_bid_arb().prop_map(|delegator| BidKind::Delegator(Box::new(delegator)))
}

pub(crate) fn validator_bid_arb() -> impl Strategy<Value = BidKind> {
    (
        public_key_arb_no_system(),
        uref_arb(),
        u512_arb(),
        delegation_rate_arb(),
        bool::ANY,
    )
        .prop_map(
            |(validator_public_key, bonding_purse, staked_amount, delegation_rate, is_locked)| {
                let validator_bid = if is_locked {
                    ValidatorBid::locked(
                        validator_public_key,
                        bonding_purse,
                        staked_amount,
                        delegation_rate,
                        1u64,
                        0,
                        u64::MAX,
                        0,
                    )
                } else {
                    ValidatorBid::unlocked(
                        validator_public_key,
                        bonding_purse,
                        staked_amount,
                        delegation_rate,
                        0,
                        u64::MAX,
                        0,
                    )
                };
                BidKind::Validator(Box::new(validator_bid))
            },
        )
}

pub(crate) fn credit_bid_arb() -> impl Strategy<Value = BidKind> {
    (public_key_arb_no_system(), era_id_arb(), u512_arb()).prop_map(
        |(validator_public_key, era_id, amount)| {
            BidKind::Credit(Box::new(ValidatorCredit::new(
                validator_public_key,
                era_id,
                amount,
            )))
        },
    )
}

fn withdraw_arb() -> impl Strategy<Value = WithdrawPurse> {
    (
        uref_arb(),
        public_key_arb_no_system(),
        public_key_arb_no_system(),
        era_id_arb(),
        u512_arb(),
    )
        .prop_map(|(bonding_purse, validator_pk, unbonder_pk, era, amount)| {
            WithdrawPurse::new(bonding_purse, validator_pk, unbonder_pk, era, amount)
        })
}

fn withdraws_arb(size: impl Into<SizeRange>) -> impl Strategy<Value = Vec<WithdrawPurse>> {
    collection::vec(withdraw_arb(), size)
}

fn unbonding_arb() -> impl Strategy<Value = UnbondingPurse> {
    (
        uref_arb(),
        public_key_arb_no_system(),
        public_key_arb_no_system(),
        era_id_arb(),
        u512_arb(),
        option::of(public_key_arb_no_system()),
    )
        .prop_map(
            |(
                bonding_purse,
                validator_public_key,
                unbonder_public_key,
                era,
                amount,
                new_validator,
            )| {
                UnbondingPurse::new(
                    bonding_purse,
                    validator_public_key,
                    unbonder_public_key,
                    era,
                    amount,
                    new_validator,
                )
            },
        )
}

fn unbondings_arb(size: impl Into<SizeRange>) -> impl Strategy<Value = Vec<UnbondingPurse>> {
    collection::vec(unbonding_arb(), size)
}

fn message_topic_summary_arb() -> impl Strategy<Value = MessageTopicSummary> {
    (any::<u32>(), any::<u64>(), "test").prop_map(|(message_count, blocktime, topic_name)| {
        MessageTopicSummary {
            message_count,
            blocktime: BlockTime::new(blocktime),
            topic_name,
        }
    })
}

fn message_summary_arb() -> impl Strategy<Value = MessageChecksum> {
    u8_slice_32().prop_map(MessageChecksum)
}

pub fn named_key_value_arb() -> impl Strategy<Value = NamedKeyValue> {
    (key_arb(), "test").prop_map(|(key, string)| {
        let cl_key = CLValue::from_t(key).unwrap();
        let cl_string = CLValue::from_t(string).unwrap();
        NamedKeyValue::new(cl_key, cl_string)
    })
}

pub fn stored_value_arb() -> impl Strategy<Value = StoredValue> {
    prop_oneof![
        cl_value_arb().prop_map(StoredValue::CLValue),
        account_arb().prop_map(StoredValue::Account),
        byte_code_arb().prop_map(StoredValue::ByteCode),
        contract_arb().prop_map(StoredValue::Contract),
        contract_package_arb().prop_map(StoredValue::ContractPackage),
        addressable_entity_arb().prop_map(StoredValue::AddressableEntity),
        package_arb().prop_map(StoredValue::SmartContract),
        transfer_v1_arb().prop_map(StoredValue::LegacyTransfer),
        deploy_info_arb().prop_map(StoredValue::DeployInfo),
        era_info_arb(1..10).prop_map(StoredValue::EraInfo),
        unified_bid_arb(0..3).prop_map(StoredValue::BidKind),
        validator_bid_arb().prop_map(StoredValue::BidKind),
        delegator_bid_kind_arb().prop_map(StoredValue::BidKind),
        reservation_bid_arb().prop_map(StoredValue::BidKind),
        credit_bid_arb().prop_map(StoredValue::BidKind),
        withdraws_arb(1..50).prop_map(StoredValue::Withdraw),
        unbondings_arb(1..50).prop_map(StoredValue::Unbonding),
        message_topic_summary_arb().prop_map(StoredValue::MessageTopic),
        message_summary_arb().prop_map(StoredValue::Message),
        named_key_value_arb().prop_map(StoredValue::NamedKey),
        collection::vec(any::<u8>(), 0..1000).prop_map(StoredValue::RawBytes),
    ]
    .prop_map(|stored_value|
            // The following match statement is here only to make sure
            // we don't forget to update the generator when a new variant is added.
            match stored_value {
                StoredValue::CLValue(_) => stored_value,
                StoredValue::Account(_) => stored_value,
                StoredValue::ContractWasm(_) => stored_value,
                StoredValue::Contract(_) => stored_value,
                StoredValue::ContractPackage(_) => stored_value,
                StoredValue::LegacyTransfer(_) => stored_value,
                StoredValue::DeployInfo(_) => stored_value,
                StoredValue::EraInfo(_) => stored_value,
                StoredValue::Bid(_) => stored_value,
                StoredValue::Withdraw(_) => stored_value,
                StoredValue::Unbonding(_) => stored_value,
                StoredValue::AddressableEntity(_) => stored_value,
                StoredValue::BidKind(_) => stored_value,
                StoredValue::SmartContract(_) => stored_value,
                StoredValue::ByteCode(_) => stored_value,
                StoredValue::MessageTopic(_) => stored_value,
                StoredValue::Message(_) => stored_value,
                StoredValue::NamedKey(_) => stored_value,
                StoredValue::Prepaid(_) => stored_value,
                StoredValue::EntryPoint(_) => stored_value,
                StoredValue::RawBytes(_) => stored_value,
        })
}

pub fn blake2b_hash_arb() -> impl Strategy<Value = Digest> {
    vec(any::<u8>(), 0..1000).prop_map(Digest::hash)
}

pub fn trie_pointer_arb() -> impl Strategy<Value = Pointer> {
    prop_oneof![
        blake2b_hash_arb().prop_map(Pointer::LeafPointer),
        blake2b_hash_arb().prop_map(Pointer::NodePointer)
    ]
}

pub fn trie_merkle_proof_step_arb() -> impl Strategy<Value = TrieMerkleProofStep> {
    const POINTERS_SIZE: usize = 32;
    const AFFIX_SIZE: usize = 6;

    prop_oneof![
        (
            <u8>::arbitrary(),
            vec((<u8>::arbitrary(), trie_pointer_arb()), POINTERS_SIZE)
        )
            .prop_map(|(hole_index, indexed_pointers_with_hole)| {
                TrieMerkleProofStep::Node {
                    hole_index,
                    indexed_pointers_with_hole,
                }
            }),
        vec(<u8>::arbitrary(), AFFIX_SIZE).prop_map(|affix| {
            TrieMerkleProofStep::Extension {
                affix: affix.into(),
            }
        })
    ]
}

pub fn trie_merkle_proof_arb() -> impl Strategy<Value = TrieMerkleProof<Key, StoredValue>> {
    const STEPS_SIZE: usize = 6;

    (
        key_arb(),
        stored_value_arb(),
        vec(trie_merkle_proof_step_arb(), STEPS_SIZE),
    )
        .prop_map(|(key, value, proof_steps)| TrieMerkleProof::new(key, value, proof_steps.into()))
}

pub fn transaction_scheduling_arb() -> impl Strategy<Value = TransactionScheduling> {
    prop_oneof![
        Just(TransactionScheduling::Standard),
        era_id_arb().prop_map(TransactionScheduling::FutureEra),
        any::<u64>().prop_map(
            |timestamp| TransactionScheduling::FutureTimestamp(Timestamp::from(timestamp))
        ),
    ]
}

pub fn json_compliant_transaction_scheduling_arb() -> impl Strategy<Value = TransactionScheduling> {
    prop_oneof![
        Just(TransactionScheduling::Standard),
        era_id_arb().prop_map(TransactionScheduling::FutureEra),
        timestamp_arb().prop_map(TransactionScheduling::FutureTimestamp),
    ]
}

pub fn transaction_invocation_target_arb() -> impl Strategy<Value = TransactionInvocationTarget> {
    prop_oneof![
        addressable_entity_hash_arb().prop_map(TransactionInvocationTarget::new_invocable_entity),
        Just(TransactionInvocationTarget::new_invocable_entity_alias(
            "abcd".to_string()
        )),
        Just(TransactionInvocationTarget::new_package_alias(
            "abcd".to_string(),
            None
        )),
        Just(TransactionInvocationTarget::new_package_alias(
            "abcd".to_string(),
            Some(10)
        )),
        u8_slice_32()
            .prop_map(|addr| { TransactionInvocationTarget::new_package(addr.into(), None) }),
        u8_slice_32()
            .prop_map(|addr| { TransactionInvocationTarget::new_package(addr.into(), Some(150)) }),
    ]
}

pub fn stored_transaction_target() -> impl Strategy<Value = TransactionTarget> {
    (
        transaction_invocation_target_arb(),
        transaction_runtime_arb(),
        any::<u64>(),
    )
        .prop_map(|(target, runtime, transferred_value)| {
            TransactionTarget::new_stored(target, runtime, transferred_value)
        })
}

pub fn session_transaction_target() -> impl Strategy<Value = TransactionTarget> {
    (
        any::<bool>(),
        Just(Bytes::from(vec![1; 10])),
        transaction_runtime_arb(),
        any::<u64>(),
        any::<Option<[u8; 32]>>(),
    )
        .prop_map(|(target, module_bytes, runtime, transferred_value, seed)| {
            TransactionTarget::new_session(target, module_bytes, runtime, transferred_value, seed)
        })
}

pub fn transaction_target_arb() -> impl Strategy<Value = TransactionTarget> {
    prop_oneof![
        Just(TransactionTarget::Native),
        (
            transaction_invocation_target_arb(),
            transaction_runtime_arb(),
            any::<u64>(),
        )
            .prop_map(
                |(target, runtime, transferred_value)| TransactionTarget::new_stored(
                    target,
                    runtime,
                    transferred_value
                )
            ),
        (
            any::<bool>(),
            Just(Bytes::from(vec![1; 10])),
            transaction_runtime_arb(),
            any::<u64>(),
            any::<Option<[u8; 32]>>(),
        )
            .prop_map(
                |(is_install_upgrade, module_bytes, runtime, transferred_value, seed)| {
                    TransactionTarget::new_session(
                        is_install_upgrade,
                        module_bytes,
                        runtime,
                        transferred_value,
                        seed,
                    )
                }
            )
    ]
}

pub fn legal_target_entry_point_calls_arb(
) -> impl Strategy<Value = (TransactionTarget, TransactionEntryPoint)> {
    prop_oneof![
        native_entry_point_arb().prop_map(|s| (TransactionTarget::Native, s)),
        stored_transaction_target()
            .prop_map(|s| (s, TransactionEntryPoint::Custom("ABC".to_string()))),
        session_transaction_target().prop_map(|s| (s, TransactionEntryPoint::Call)),
    ]
}

pub fn native_entry_point_arb() -> impl Strategy<Value = TransactionEntryPoint> {
    prop_oneof![
        Just(TransactionEntryPoint::Transfer),
        Just(TransactionEntryPoint::AddBid),
        Just(TransactionEntryPoint::WithdrawBid),
        Just(TransactionEntryPoint::Delegate),
        Just(TransactionEntryPoint::Undelegate),
        Just(TransactionEntryPoint::Redelegate),
        Just(TransactionEntryPoint::ActivateBid),
        Just(TransactionEntryPoint::ChangeBidPublicKey),
        Just(TransactionEntryPoint::AddReservations),
        Just(TransactionEntryPoint::CancelReservations),
    ]
}
pub fn transaction_entry_point_arb() -> impl Strategy<Value = TransactionEntryPoint> {
    prop_oneof![
        native_entry_point_arb(),
        Just(TransactionEntryPoint::Call),
        Just(TransactionEntryPoint::Custom("custom".to_string())),
    ]
}

pub fn runtime_args_arb() -> impl Strategy<Value = RuntimeArgs> {
    let mut runtime_args_1 = RuntimeArgs::new();
    let semi_random_string_pairs = [
        ("977837db-8dba-48c2-86f1-32f9740631db", "b7b3b3b3-8b3b-48c2-86f1-32f9740631db"),
        ("5de3eecc-b9c8-477f-bebe-937c3a16df85", "2ffd7939-34e5-4660-af9f-772a83011ce0"),
        ("036db036-8b7b-4009-a0d4-c9ce", "515f4fe6-06c8-45c5-8554-f07e727a842d036db036-8b7b-4009-a0d4-c9ce036db036-8b7b-4009-a0d4-c9ce"),
    ];
    for (key, val_str) in semi_random_string_pairs.iter() {
        let _ = runtime_args_1.insert(key.to_string(), Bytes::from(val_str.as_bytes()));
    }
    prop_oneof![Just(runtime_args_1)]
}

fn transaction_args_bytes_arbitrary() -> impl Strategy<Value = TransactionArgs> {
    prop::collection::vec(any::<u8>(), 0..100)
        .prop_map(|bytes| TransactionArgs::Bytesrepr(bytes.into()))
}

pub fn transaction_args_arb() -> impl Strategy<Value = TransactionArgs> {
    prop_oneof![
        runtime_args_arb().prop_map(TransactionArgs::Named),
        transaction_args_bytes_arbitrary()
    ]
}

pub fn fields_arb() -> impl Strategy<Value = BTreeMap<u16, Bytes>> {
    collection::btree_map(
        any::<u16>(),
        any::<String>().prop_map(|s| Bytes::from(s.as_bytes())),
        3..30,
    )
}
pub fn v1_transaction_payload_arb() -> impl Strategy<Value = TransactionV1Payload> {
    (
        any::<String>(),
        timestamp_arb(),
        any::<u64>(),
        pricing_mode_arb(),
        initiator_addr_arb(),
        fields_arb(),
    )
        .prop_map(
            |(chain_name, timestamp, ttl_millis, pricing_mode, initiator_addr, fields)| {
                TransactionV1Payload::new(
                    chain_name,
                    timestamp,
                    TimeDiff::from_millis(ttl_millis),
                    pricing_mode,
                    initiator_addr,
                    fields,
                )
            },
        )
}

pub fn fixed_pricing_mode_arb() -> impl Strategy<Value = PricingMode> {
    (any::<u8>(), any::<u8>()).prop_map(|(gas_price_tolerance, additional_computation_factor)| {
        PricingMode::Fixed {
            gas_price_tolerance,
            additional_computation_factor,
        }
    })
}

pub fn pricing_mode_arb() -> impl Strategy<Value = PricingMode> {
    prop_oneof![
        (any::<u64>(), any::<u8>(), any::<bool>()).prop_map(
            |(payment_amount, gas_price_tolerance, standard_payment)| {
                PricingMode::PaymentLimited {
                    payment_amount,
                    gas_price_tolerance,
                    standard_payment,
                }
            }
        ),
        fixed_pricing_mode_arb(),
        u8_slice_32().prop_map(|receipt| {
            PricingMode::Prepaid {
                receipt: receipt.into(),
            }
        }),
    ]
}

pub fn initiator_addr_arb() -> impl Strategy<Value = InitiatorAddr> {
    prop_oneof![
        public_key_arb_no_system().prop_map(InitiatorAddr::PublicKey),
        u2_slice_32().prop_map(|hash| InitiatorAddr::AccountHash(AccountHash::new(hash))),
    ]
}

pub fn timestamp_arb() -> impl Strategy<Value = Timestamp> {
    //The weird u64 value is the max milliseconds that are bofeore year 10000. 5 digit years are
    // not rfc3339 compliant and will cause an error when trying to serialize to json.
    prop_oneof![Just(0_u64), Just(1_u64), Just(253_402_300_799_999_u64)].prop_map(Timestamp::from)
}

pub fn legal_v1_transaction_arb() -> impl Strategy<Value = TransactionV1> {
    (
        any::<String>(),
        timestamp_arb(),
        any::<u32>(),
        pricing_mode_arb(),
        secret_key_arb_no_system(),
        transaction_args_arb(),
        json_compliant_transaction_scheduling_arb(),
        legal_target_entry_point_calls_arb(),
    )
        .prop_map(
            |(
                chain_name,
                timestamp,
                ttl,
                pricing_mode,
                secret_key,
                args,
                scheduling,
                (target, entry_point),
            )| {
                let public_key = PublicKey::from(&secret_key);
                let initiator_addr = InitiatorAddr::PublicKey(public_key);
                let initiator_addr_with_secret = InitiatorAddrAndSecretKey::Both {
                    initiator_addr,
                    secret_key: &secret_key,
                };
                let container = FieldsContainer::new(args, target, entry_point, scheduling);
                TransactionV1::build(
                    chain_name,
                    timestamp,
                    TimeDiff::from_seconds(ttl),
                    pricing_mode,
                    container.to_map().unwrap(),
                    initiator_addr_with_secret,
                )
            },
        )
}
pub fn v1_transaction_arb() -> impl Strategy<Value = TransactionV1> {
    (
        any::<String>(),
        timestamp_arb(),
        any::<u32>(),
        pricing_mode_arb(),
        secret_key_arb_no_system(),
        runtime_args_arb(),
        transaction_target_arb(),
        transaction_entry_point_arb(),
        transaction_scheduling_arb(),
    )
        .prop_map(
            |(
                chain_name,
                timestamp,
                ttl,
                pricing_mode,
                secret_key,
                args,
                target,
                entry_point,
                scheduling,
            )| {
                let public_key = PublicKey::from(&secret_key);
                let initiator_addr = InitiatorAddr::PublicKey(public_key);
                let initiator_addr_with_secret = InitiatorAddrAndSecretKey::Both {
                    initiator_addr,
                    secret_key: &secret_key,
                };
                let container = FieldsContainer::new(
                    TransactionArgs::Named(args),
                    target,
                    entry_point,
                    scheduling,
                );
                TransactionV1::build(
                    chain_name,
                    timestamp,
                    TimeDiff::from_seconds(ttl),
                    pricing_mode,
                    container.to_map().unwrap(),
                    initiator_addr_with_secret,
                )
            },
        )
}

pub fn transaction_arb() -> impl Strategy<Value = Transaction> {
    (v1_transaction_arb()).prop_map(Transaction::V1)
}

pub fn legal_transaction_arb() -> impl Strategy<Value = Transaction> {
    (legal_v1_transaction_arb()).prop_map(Transaction::V1)
}
pub fn example_u32_arb() -> impl Strategy<Value = u32> {
    prop_oneof![Just(0), Just(1), Just(u32::MAX / 2), Just(u32::MAX)]
}