transact 0.4.7

Transact is a transaction execution platform designed to be used as a library or component when implementing distributed ledgers, including blockchains.
Documentation
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
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
// Copyright 2019 Cargill Incorporated
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;
use std::hash::Hash;
use std::marker::PhantomData;

use crate::contract::address::Addresser;
use crate::contract::context::error::ContractContextError;
use crate::handler::TransactionContext;
use crate::protocol::key_value_state::{
    StateEntry, StateEntryBuilder, StateEntryList, StateEntryListBuilder, StateEntryValue,
    StateEntryValueBuilder, ValueType,
};
use crate::protos::{FromBytes, IntoBytes};

/// KeyValueTransactionContext used to implement a simplified state consisting of natural keys and
/// a ValueType, an enum object used to represent a range of primitive data types. Uses an
/// implementation of the Addresser trait to calculate radix addresses to be stored in the
/// KeyValueTransactionContext's internal transaction context.
pub struct KeyValueTransactionContext<'a, A, K>
where
    A: Addresser<K>,
{
    context: &'a mut dyn TransactionContext,
    addresser: A,
    // PhantomData<K> is necessary for the K generic to be used with the Addresser trait, as K is not
    // used in any other elements of the KeyValueTransactionContext struct.
    _key: PhantomData<K>,
}

impl<'a, A, K> KeyValueTransactionContext<'a, A, K>
where
    A: Addresser<K>,
    K: Eq + Hash,
{
    /// Creates a new KeyValueTransactionContext
    /// Implementations of the TransactionContext trait and Addresser trait must be provided.
    pub fn new(
        context: &'a mut dyn TransactionContext,
        addresser: A,
    ) -> KeyValueTransactionContext<'a, A, K> {
        KeyValueTransactionContext {
            context,
            addresser,
            _key: PhantomData,
        }
    }

    /// Serializes the provided values and attempts to set this object at an address calculated
    /// from the provided natural key.
    ///
    /// Returns an `Ok(())` if the entry is successfully stored.
    ///
    /// # Arguments
    ///
    /// * `key` - The natural key that specifies where to set the state entry
    /// * `values` - The HashMap to be stored in state at the provided natural key
    pub fn set_state_entry(
        &self,
        key: &K,
        values: HashMap<String, ValueType>,
    ) -> Result<(), ContractContextError> {
        let mut new_entries = HashMap::new();
        new_entries.insert(key, values);
        self.set_state_entries(new_entries)
    }

    /// Attempts to retrieve the data from state at the address calculated from the provided
    /// natural key.
    ///
    /// Returns an optional HashMap which represents the value stored in state, returning `None`
    /// if the state entry is not found.
    ///
    /// # Arguments
    ///
    /// * `key` - The natural key to fetch
    pub fn get_state_entry(
        &self,
        key: &K,
    ) -> Result<Option<HashMap<String, ValueType>>, ContractContextError> {
        Ok(self.get_state_entries(vec![key])?.into_values().next())
    }

    /// Attempts to unset the data in state at the address calculated from the provided natural key.
    ///
    /// Returns an optional normalized key of the successfully deleted state entry, returning
    /// `None` if the state entry is not found.
    ///
    /// # Arguments
    ///
    /// * `key` - The natural key to delete
    pub fn delete_state_entry(&self, key: K) -> Result<Option<String>, ContractContextError> {
        Ok(self.delete_state_entries(vec![key])?.into_iter().next())
    }

    /// Serializes each value in the provided map and attempts to set in state each of these objects
    /// at the address calculated from its corresponding natural key.
    ///
    /// Returns an `Ok(())` if the provided entries were successfully stored.
    ///
    /// # Arguments
    ///
    /// * `entries` - HashMap with the map to be stored in state at the associated natural key
    pub fn set_state_entries(
        &self,
        entries: HashMap<&K, HashMap<String, ValueType>>,
    ) -> Result<(), ContractContextError> {
        let keys = entries.keys().map(ToOwned::to_owned).collect::<Vec<&K>>();
        let addresses = keys
            .iter()
            .map(|k| {
                self.addresser
                    .compute(k)
                    .map_err(ContractContextError::AddresserError)
            })
            .collect::<Result<Vec<String>, ContractContextError>>()?;
        // Creating a map of the StateEntryList to the address it is stored at
        let entry_list_map = self.get_state_entry_lists(&addresses)?;

        // Iterating over the provided HashMap to see if there is an existing StateEntryList at the
        // corresponding address. If there is one found, add the new StateEntry to the StateEntryList.
        // If there is none found, creates a new StateEntryList entry for that address. Then,
        // serializes the newly created StateEntryList to be set in the internal context.
        let entries_list = entries
            .iter()
            .map(|(key, values)| {
                let addr = self.addresser.compute(key)?;
                let state_entry = self.create_state_entry(key, values.to_owned())?;
                match entry_list_map.get(&addr) {
                    Some(entry_list) => {
                        let mut existing_entries = entry_list.entries().to_vec();
                        existing_entries.push(state_entry);
                        let entry_list = StateEntryListBuilder::new()
                            .with_state_entries(existing_entries)
                            .build()
                            .map_err(|err| {
                                ContractContextError::ProtocolBuildError(Box::new(err))
                            })?;
                        Ok((addr, entry_list.into_bytes()?))
                    }
                    None => {
                        let entry_list = StateEntryListBuilder::new()
                            .with_state_entries(vec![state_entry])
                            .build()
                            .map_err(|err| {
                                ContractContextError::ProtocolBuildError(Box::new(err))
                            })?;
                        Ok((addr, entry_list.into_bytes()?))
                    }
                }
            })
            .collect::<Result<Vec<(String, Vec<u8>)>, ContractContextError>>()?;
        self.context.set_state_entries(entries_list)?;

        Ok(())
    }

    /// Attempts to retrieve the data from state at the addresses calculated from the provided list
    /// of natural keys.
    ///
    /// Returns a HashMap that links a normalized key with a HashMap. The associated HashMap represents
    /// the data retrieved from state. Only returns the data from addresses that have been set.
    ///
    /// # Arguments
    ///
    /// * `keys` - A list of natural keys to be fetched from state
    pub fn get_state_entries(
        &self,
        keys: Vec<&K>,
    ) -> Result<HashMap<String, HashMap<String, ValueType>>, ContractContextError> {
        let addresses = keys
            .iter()
            .map(|k| {
                self.addresser
                    .compute(k)
                    .map_err(ContractContextError::AddresserError)
            })
            .collect::<Result<Vec<String>, ContractContextError>>()?;
        let normalized_keys = keys
            .iter()
            .map(|k| self.addresser.normalize(k))
            .collect::<Vec<String>>();

        let state_entries: Vec<StateEntry> = self.flatten_state_entries(&addresses)?;

        // Now going to filter the StateEntry objects that actually have a matching normalized key
        // and convert the normalized key and value to be added to the returned HashMap.
        state_entries
            .iter()
            .filter(|entry| normalized_keys.contains(&entry.normalized_key().to_string()))
            .map(|entry| {
                let values = entry
                    .state_entry_values()
                    .iter()
                    .map(|val| (val.key().to_string(), val.value().to_owned()))
                    .collect::<HashMap<String, ValueType>>();
                Ok((entry.normalized_key().to_string(), values))
            })
            .collect::<Result<HashMap<String, HashMap<String, ValueType>>, ContractContextError>>()
    }

    /// Attempts to unset the data in state at the addresses calculated from each natural key in the
    /// provided list.
    ///
    /// Returns a list of normalized keys of successfully deleted state entries.
    ///
    /// # Arguments
    ///
    /// * `keys` - A list of natural keys to be deleted from state
    pub fn delete_state_entries(&self, keys: Vec<K>) -> Result<Vec<String>, ContractContextError> {
        let key_map: HashMap<String, String> = keys
            .iter()
            .map(|k| Ok((self.addresser.normalize(k), self.addresser.compute(k)?)))
            .collect::<Result<HashMap<String, String>, ContractContextError>>()?;
        let state_entry_lists: HashMap<String, StateEntryList> = self.get_state_entry_lists(
            &key_map
                .values()
                .map(ToOwned::to_owned)
                .collect::<Vec<String>>(),
        )?;

        let mut deleted_keys = Vec::new();
        let mut new_entry_lists = Vec::new();
        let mut delete_lists = Vec::new();
        key_map.iter().for_each(|(nkey, addr)| {
            // Fetching the StateEntryList at the corresponding address
            if let Some(list) = state_entry_lists.get(addr) {
                // The StateEntry objects will be filtered out of the StateEntryList if it has the
                // normalized key. This normalized key is added to a list of successfully filtered
                // entries to be returned.
                if list.contains(nkey.to_string()) {
                    let filtered = list
                        .entries()
                        .iter()
                        .filter(|e| e.normalized_key() != nkey)
                        .cloned()
                        .collect::<Vec<StateEntry>>();
                    if filtered.is_empty() {
                        delete_lists.push(addr.to_string());
                    } else {
                        new_entry_lists.push((addr.to_string(), filtered));
                    }
                    deleted_keys.push(nkey.to_string());
                }
            }
        });
        // Delete any StateEntryLists that have an empty list of entries
        self.context.delete_state_entries(delete_lists.as_slice())?;
        // Setting the newly filtered StateEntryLists into state using the internal context
        self.context.set_state_entries(
            new_entry_lists
                .iter()
                .map(|(addr, filtered_list)| {
                    let new_entry_list = StateEntryListBuilder::new()
                        .with_state_entries(filtered_list.to_vec())
                        .build()
                        .map_err(|err| ContractContextError::ProtocolBuildError(Box::new(err)))?;
                    Ok((addr.to_string(), new_entry_list.into_bytes()?))
                })
                .collect::<Result<Vec<(String, Vec<u8>)>, ContractContextError>>()?,
        )?;

        Ok(deleted_keys)
    }

    /// Adds a blob to the execution result for this transaction.
    ///
    /// # Arguments
    ///
    /// * `data` - Transaction-family-specific data which can be interpreted by application clients.
    pub fn add_receipt_data(&self, data: Vec<u8>) -> Result<(), ContractContextError> {
        Ok(self.context.add_receipt_data(data)?)
    }

    /// add_event adds a new event to the execution result for this transaction.
    ///
    /// # Arguments
    ///
    /// * `event_type` -  A globally unique event identifier that is used to subscribe to events.
    ///         It describes what, in general, has occured.
    /// * `attributes` - Additional information about the event. Attributes can be used by
    ///         subscribers to filter the type of events they receive.
    /// * `data` - Transaction-family-specific data which can be interpreted by application clients.
    pub fn add_event(
        &self,
        event_type: String,
        attributes: Vec<(String, String)>,
        data: Vec<u8>,
    ) -> Result<(), ContractContextError> {
        Ok(self.context.add_event(event_type, attributes, data)?)
    }

    /// Collects the StateEntryList objects from state and then uses flat_map to collect the
    /// StateEntry objects held within each StateEntryList.
    fn flatten_state_entries(
        &self,
        addresses: &[String],
    ) -> Result<Vec<StateEntry>, ContractContextError> {
        Ok(self
            .get_state_entry_lists(addresses)?
            .values()
            .flat_map(|entry_list| entry_list.entries().to_vec())
            .collect::<Vec<StateEntry>>())
    }

    /// Collects the StateEntryList objects from the bytes fetched from state, then deserializes
    /// these into the native StateEntryList object.
    fn get_state_entry_lists(
        &self,
        addresses: &[String],
    ) -> Result<HashMap<String, StateEntryList>, ContractContextError> {
        self.context
            .get_state_entries(addresses)?
            .iter()
            .map(|(addr, bytes_entry)| {
                Ok((addr.to_string(), StateEntryList::from_bytes(bytes_entry)?))
            })
            .collect::<Result<HashMap<String, StateEntryList>, ContractContextError>>()
    }

    /// Creates a singular StateEntry object from the provided key and values.
    fn create_state_entry(
        &self,
        key: &K,
        values: HashMap<String, ValueType>,
    ) -> Result<StateEntry, ContractContextError> {
        let state_values: Vec<StateEntryValue> = values
            .iter()
            .map(|(key, value)| {
                StateEntryValueBuilder::new()
                    .with_key(key.to_string())
                    .with_value(value.clone())
                    .build()
                    .map_err(|err| ContractContextError::ProtocolBuildError(Box::new(err)))
            })
            .collect::<Result<Vec<StateEntryValue>, ContractContextError>>()?;
        StateEntryBuilder::new()
            .with_normalized_key(self.addresser.normalize(key.to_owned()))
            .with_state_entry_values(state_values)
            .build()
            .map_err(|err| ContractContextError::ProtocolBuildError(Box::new(err)))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use std::sync::{Arc, Mutex};

    use crate::contract::address::{
        double_key_hash::DoubleKeyHashAddresser, key_hash::KeyHashAddresser,
        triple_key_hash::TripleKeyHashAddresser,
    };

    use crate::handler::ContextError;

    /// Simple state backed by a HashMap.
    struct TestState {
        state: HashMap<String, Vec<u8>>,
    }

    /// Simple state implementation with basic methods to get, set, and delete state values.
    impl TestState {
        pub fn new() -> Self {
            TestState {
                state: HashMap::new(),
            }
        }

        fn get_entries(
            &self,
            addresses: &[String],
        ) -> Result<Vec<(String, Vec<u8>)>, ContextError> {
            let mut values = Vec::new();
            addresses.iter().for_each(|key| {
                if let Some(value) = self.state.get(key) {
                    values.push((key.to_string(), value.to_vec()))
                }
            });
            Ok(values)
        }

        fn set_entries(&mut self, entries: Vec<(String, Vec<u8>)>) -> Result<(), ContextError> {
            entries.iter().for_each(|(key, value)| {
                match self.state.insert(key.to_string(), value.to_vec()) {
                    _ => (),
                }
            });
            Ok(())
        }

        fn delete_entries(&mut self, addresses: &[String]) -> Result<Vec<String>, ContextError> {
            let mut deleted = Vec::new();
            addresses.iter().for_each(|key| {
                if let Some(_) = self.state.remove(key) {
                    deleted.push(key.to_string());
                }
            });
            Ok(deleted)
        }

        fn add_receipt_data(&self, _data: Vec<u8>) -> Result<(), ContextError> {
            Ok(())
        }

        fn add_event(
            &self,
            _event_type: String,
            _attributes: Vec<(String, String)>,
            _data: Vec<u8>,
        ) -> Result<(), ContextError> {
            Ok(())
        }
    }

    /// TestContext using the simple TestState backend to be used as the internal context to
    /// construct a KeyValueTransactionContext for the tests.
    struct TestContext {
        internal_state: Arc<Mutex<TestState>>,
    }

    impl TestContext {
        pub fn new() -> Self {
            TestContext {
                internal_state: Arc::new(Mutex::new(TestState::new())),
            }
        }
    }

    /// TransactionContext trait implementation for the TestContext.
    impl TransactionContext for TestContext {
        fn get_state_entries(
            &self,
            addresses: &[String],
        ) -> Result<Vec<(String, Vec<u8>)>, ContextError> {
            self.internal_state
                .lock()
                .expect("Test lock was poisoned in get method")
                .get_entries(addresses)
        }

        fn set_state_entries(&self, entries: Vec<(String, Vec<u8>)>) -> Result<(), ContextError> {
            self.internal_state
                .lock()
                .expect("Test lock was poisoned in set method")
                .set_entries(entries)
        }

        fn delete_state_entries(&self, addresses: &[String]) -> Result<Vec<String>, ContextError> {
            self.internal_state
                .lock()
                .expect("Test lock was poisoned in delete method")
                .delete_entries(addresses)
        }

        fn add_receipt_data(&self, data: Vec<u8>) -> Result<(), ContextError> {
            self.internal_state
                .lock()
                .expect("Test lock was poisoned in add_receipt_data method")
                .add_receipt_data(data)
        }

        fn add_event(
            &self,
            event_type: String,
            attributes: Vec<(String, String)>,
            data: Vec<u8>,
        ) -> Result<(), ContextError> {
            self.internal_state
                .lock()
                .expect("Test lock was poisoned in add_event method")
                .add_event(event_type, attributes, data)
        }
    }

    /// Function to create a HashMap from `key` and `value` to create a StateEntryValue for a
    /// StateEntry message.
    fn create_entry_value_map(key: String, value: ValueType) -> HashMap<String, ValueType> {
        let mut value_map = HashMap::new();
        value_map.insert(key, value);
        value_map
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a KeyHashAddresser,
    /// will successfully perform the `set_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a KeyHashAddresser, so a key
    ///    is represented by a single string
    /// 2. Create a HashMap, a value to be set in state, with a string key and a ValueType value
    ///
    /// This test then verifies a successful return from the `set_state_entry` when providing a
    /// single string for the `key` argument and the HashMap for the `values` argument
    fn test_simple_set_state_entry() {
        // Create a TestContext and KeyHashAddresser, then construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = KeyHashAddresser::new("prefix".to_string());
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to be set in state
        let value = ValueType::Int32(32);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Verify the `set_state_entry` method returns an `Ok(())` result
        assert!(simple_state
            .set_state_entry(&"a".to_string(), state_value)
            .is_ok());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a KeyHashAddresser,
    /// will successfully perform the `get_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a KeyHashAddresser, so a key
    ///    is represented by a single string
    /// 2. Create a HashMap, a value to be set in state, with a string key and a ValueType value
    /// 3. Set the created HashMap in state at a key, 'a', using the `set_state_entry` method
    ///
    /// This test then verifies the `get_state_entry` returns a Some option and the value of the
    /// returned option is equivalent to the HashMap created, including the key and ValueType
    fn test_simple_get_state_entry() {
        // Create a TestContext and KeyHashAddresser, then construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = KeyHashAddresser::new("prefix".to_string());
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap, with a string key and ValueType value
        let value = ValueType::Int32(32);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Set the HashMap, created above, at the key 'a'
        simple_state
            .set_state_entry(&"a".to_string(), state_value)
            .expect("Unable to set state entry in get_state_entry test");

        // Use the `get_state_entry` method to access the state entry at the 'a' key
        let values = simple_state.get_state_entry(&"a".to_string()).unwrap();

        // Verify the return value is equal to the HashMap used when the entry was originally set
        assert!(values.is_some());
        assert_eq!(
            values.unwrap().get(&"key1".to_string()),
            Some(&ValueType::Int32(32))
        );
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a KeyHashAddresser,
    /// will successfully perform the `delete_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a KeyHashAddresser, so a key
    ///    is represented by a single string
    /// 2. Create a HashMap, a value to be set in state, with a string key and a ValueType value
    /// 3. Set the created HashMap in state at a key, 'a', using the `set_state_entry` method
    ///
    /// This test verifies the `delete_state_entry` successfully deletes the intended state entry
    /// by checking that the initial call returns the correct key wrapped in a Some option
    /// and a subsequent attempt to delete the entry at the same key returns a None option
    fn test_simple_delete_state_entry() {
        // Create a TestContext and KeyHashAddresser, then construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = KeyHashAddresser::new("prefix".to_string());
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap, with a string key and ValueType value
        let value = ValueType::Int32(32);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Set the HashMap, created above, at the key 'a'
        simple_state
            .set_state_entry(&"a".to_string(), state_value)
            .expect("Unable to set state entry in delete_state_entry test");

        // Call `get_state_entry` to ensure the value has been succesfully set
        simple_state
            .get_state_entry(&"a".to_string())
            .expect("Unable to get state entry in delete_state_entry test");

        // Call `delete_state_entry` and verify the return value is a Some option and the value of
        // this option is the correct key, 'a'
        let deleted = simple_state.delete_state_entry("a".to_string()).unwrap();
        assert!(deleted.is_some());
        assert_eq!(deleted, Some("a".to_string()));

        // Call `delete_state_entry` with the same key, 'a', to verify the return value is a None
        // option
        let already_deleted = simple_state.delete_state_entry("a".to_string()).unwrap();
        assert!(already_deleted.is_none());

        // Verify access to the 'a' key using the `get_state_entry` method returns a None option
        let deleted_value = simple_state.get_state_entry(&"a".to_string()).unwrap();
        assert!(deleted_value.is_none());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a KeyHashAddresser,
    /// will successfully perform the `set_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a KeyHashAddresser, so a key
    ///    is represented by a single string
    /// 2. Create two HashMaps, entries to be set in state, with values represented by a ValueType
    ///
    /// This test then verifies a successful return from the `set_state_entries` when provided a
    /// HashMap of a natural key (the key the entry is meant to be set at) associated with a value,
    /// represented by a HashMap (intended to be used in the state entry)
    fn test_simple_set_state_entries() {
        // Create a TestContext and KeyHashAddresser, then construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = KeyHashAddresser::new("prefix".to_string());
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &"a".to_string();
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &"b".to_string();
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map);
        entries.insert(second_key, second_value_map);

        // Verify the `set_state_entries` method returns an `Ok(())` result
        let set_result = simple_state.set_state_entries(entries);
        assert!(set_result.is_ok());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a KeyHashAddresser,
    /// will successfully perform the `get_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a KeyHashAddresser, so a key
    ///    is represented by a single string
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    /// 3. Set these created HashMaps in state using the `set_state_entries` method
    ///
    /// This test then verifies the `get_state_entries` returns a HashMap containing the keys ('a'
    /// and 'b') and each is associated with the unique HashMaps used to originally set the entries
    fn test_simple_get_state_entries() {
        // Create a TestContext and KeyHashAddresser, then construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = KeyHashAddresser::new("prefix".to_string());
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &"a".to_string();
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &"b".to_string();
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map.clone());
        entries.insert(second_key, second_value_map.clone());

        // Use the `set_state_entries` method to place the `entries` HashMap in state
        simple_state
            .set_state_entries(entries)
            .expect("Unable to set state entries in get_state_entries test");

        // Use the `get_state_entries` method to access the state entries at the 'a' and 'b' key
        let values = simple_state
            .get_state_entries([first_key, second_key].to_vec())
            .unwrap();

        // Verify each key has the same associated value as when the entries were originally set
        assert_eq!(values.get("a").unwrap(), &first_value_map);
        assert_eq!(values.get("b").unwrap(), &second_value_map);
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a KeyHashAddresser,
    /// will successfully perform the `delete_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a KeyHashAddresser, so a key
    ///    is represented by a single string
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    /// 3. Set these created HashMaps in state using the `set_state_entries` method
    ///
    /// This test verifies `delete_state_entries` successfully deletes the intended state entries
    /// by checking that the initial call returns a list containing the correct keys and a
    /// subsequent attempt to delete the entries at the same keys returns an empty list
    fn test_simple_delete_state_entries() {
        // Create a TestContext and KeyHashAddresser, then construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = KeyHashAddresser::new("prefix".to_string());
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &"a".to_string();
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &"b".to_string();
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map.clone());
        entries.insert(second_key, second_value_map.clone());

        // Call the `set_state_entries` method to place the `entries` HashMap in state
        simple_state
            .set_state_entries(entries)
            .expect("Unable to set state entries in delete_state_entries test");

        // Call the `get_state_entries` method to ensure the state entries have been set
        simple_state
            .get_state_entries([first_key, second_key].to_vec())
            .expect("Unable to get state entries in delete_state_entries test");

        // Call `delete_state_entries` and verify the return value is a list of the keys 'a' and 'b'
        let deleted = simple_state
            .delete_state_entries(["a".to_string(), "b".to_string()].to_vec())
            .expect("Unable to delete state entries");
        assert!(deleted.contains(&"a".to_string()));
        assert!(deleted.contains(&"b".to_string()));

        // Call `delete_state_entries` with the same keys and verify an empty list is returned
        let already_deleted = simple_state
            .delete_state_entries(["a".to_string(), "b".to_string()].to_vec())
            .unwrap();
        assert!(already_deleted.is_empty());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a DoubleKeyHashAddresser,
    /// will successfully perform the `set_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a DoubleKeyHashAddresser, so
    ///    a key is represented by a tuple of two strings
    /// 2. Create a HashMap, a value to be set in state, with some key and a value represented by a
    ///    ValueType
    ///
    /// This test then verifies a successful return from the `set_state_entry` when providing a
    /// tuple of two strings for the `key` argument and the HashMap for the `values` argument
    fn test_double_set_state_entry() {
        // Create a TestContext and DoubleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = DoubleKeyHashAddresser::new("prefix".to_string(), None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to be set in state
        let value = ValueType::Int64(64);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Verify the `set_state_entry` method returns an `Ok(())` result
        assert!(simple_state
            .set_state_entry(&("a".to_string(), "b".to_string()), state_value)
            .is_ok());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a DoubleKeyHashAddresser,
    /// will successfully perform the `get_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a DoubleKeyHashAddresser, so
    ///    a key is represented by a tuple of two strings
    /// 2. Create a HashMap, a value to be set in state, with a key and a ValueType as the value
    /// 3. Set the created HashMap in state at a key, ('a', 'b'), using the `set_state_entry` method
    ///
    /// This test then verifies the `get_state_entry` returns a Some option and the value of the
    /// returned option is equivalent to the HashMap created, including the key and ValueType
    fn test_double_get_state_entry() {
        // Create a TestContext and DoubleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = DoubleKeyHashAddresser::new("prefix".to_string(), None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap, with a string key and ValueType value
        let value = ValueType::Int64(64);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Use `set_state_entry` to set the state entry at the ('a', 'b') key
        simple_state
            .set_state_entry(&("a".to_string(), "b".to_string()), state_value)
            .expect("Unable to set state entry in get_state_entry test");

        // Use the `get_state_entry` method to access the state entry at the ('a', 'b') key
        let values = simple_state
            .get_state_entry(&("a".to_string(), "b".to_string()))
            .unwrap();

        // Verify the return value is equal to the HashMap used when the entry was originally set
        assert!(values.is_some());
        assert_eq!(
            values.unwrap().get(&"key1".to_string()),
            Some(&ValueType::Int64(64))
        );
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a DoubleKeyHashAddresser,
    /// will successfully perform the `delete_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a DoubleKeyHashAddresser, so
    ///    a key is represented by a tuple of two strings
    /// 2. Create a HashMap, a value to be set in state, with a key and a ValueType as the value
    /// 3. Set the created HashMap in state at a key, ('a', 'b'), using the `set_state_entry` method
    ///
    /// This test verifies the `delete_state_entry` successfully deletes the intended state entry
    /// by checking that the initial call returns the normalized key wrapped in a Some option
    fn test_double_delete_state_entry() {
        // Create a TestContext and DoubleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = DoubleKeyHashAddresser::new("prefix".to_string(), None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap, with a string key and ValueType value
        let value = ValueType::Int64(64);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Set the HashMap, created above, at the key ('a', 'b')
        simple_state
            .set_state_entry(&("a".to_string(), "b".to_string()), state_value)
            .expect("Unable to set state entry in get_state_entry test");

        // Call `get_state_entry` to ensure the value has been succesfully set
        simple_state
            .get_state_entry(&("a".to_string(), "b".to_string()))
            .expect("Unable to get state entry in delete_state_entries test");

        // Call `delete_state_entry` and verify the return value is a Some option and the value of
        // this option is the correct normalized key, 'a_b'
        let deleted = simple_state
            .delete_state_entry(("a".to_string(), "b".to_string()))
            .unwrap();
        assert!(deleted.is_some());
        assert_eq!(deleted, Some(format!("{}_{}", "a", "b")));
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a DoubleKeyHashAddresser,
    /// will successfully perform the `set_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a DoubleKeyHashAddresser, so
    ///    a key is represented by a tuple of two strings
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    ///
    /// This test then verifies a successful return from the `set_state_entries` when provided a
    /// HashMap of a natural key (the key the entry is meant to be set at) associated with a value,
    /// represented by a HashMap (intended to be used in the state entry)
    fn test_double_set_state_entries() {
        // Create a TestContext and DoubleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = DoubleKeyHashAddresser::new("prefix".to_string(), None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &("a".to_string(), "b".to_string());
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &("c".to_string(), "d".to_string());
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map);
        entries.insert(second_key, second_value_map);

        // Verify the `set_state_entries` method returns an `Ok(())` result
        assert!(simple_state.set_state_entries(entries).is_ok());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a DoubleKeyHashAddresser,
    /// will successfully perform the `get_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a DoubleKeyHashAddresser, so
    ///    a key is represented by a tuple of two strings
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    /// 3. Set these created HashMaps in state using the `set_state_entries` method
    ///
    /// This test verifies the `get_state_entries` returns a HashMap containing the keys, ('a', 'b')
    /// and ('c', 'd'), and each is associated with the unique HashMaps used to originally set the entries
    fn test_double_get_state_entries() {
        // Create a TestContext and DoubleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = DoubleKeyHashAddresser::new("prefix".to_string(), None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &("a".to_string(), "b".to_string());
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &("c".to_string(), "d".to_string());
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map.clone());
        entries.insert(second_key, second_value_map.clone());

        // Use the `set_state_entries` method to place the `entries` HashMap in state
        simple_state
            .set_state_entries(entries)
            .expect("Unable to set_state_entries in get_state_entries test");

        // Use the `get_state_entries` method to access the state entries at the ('a', 'b') and
        // ('c', 'd') keys
        let values = simple_state
            .get_state_entries([first_key, second_key].to_vec())
            .expect("Unable to get state entries in get_state_entries test");

        // Verify each normalized key has the same associated value as when the entries were
        // originally set
        assert_eq!(
            values.get(&format!("{}_{}", "a", "b")).unwrap(),
            &first_value_map
        );
        assert_eq!(
            values.get(&format!("{}_{}", "c", "d")).unwrap(),
            &second_value_map
        );
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a DoubleKeyHashAddresser,
    /// will successfully perform the `delete_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a DoubleKeyHashAddresser, so
    ///    a key is represented by a tuple of two strings
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    /// 3. Set these created HashMaps in state using the `set_state_entries` method
    ///
    /// This test verifies `delete_state_entries` successfully deletes the intended state entries
    /// by checking that the call returns a list containing the correct normalized keys
    fn test_double_delete_state_entries() {
        // Create a TestContext and DoubleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = DoubleKeyHashAddresser::new("prefix".to_string(), None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = ("a".to_string(), "b".to_string());
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = ("c".to_string(), "d".to_string());
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(&first_key, first_value_map.clone());
        entries.insert(&second_key, second_value_map.clone());

        // Call the `set_state_entries` method to place the `entries` HashMap in state
        simple_state
            .set_state_entries(entries)
            .expect("Unable to set_state_entries in delete_state_entries test");

        // Call the `get_state_entries` method to ensure the state entries have been set
        simple_state
            .get_state_entries([&first_key, &second_key].to_vec())
            .expect("Unable to get_state_entries in the delete_state_entries test");

        // Call `delete_state_entries` and verify the return value is a list containing the normalized
        // keys 'a_b' and 'c_d'
        let deleted = simple_state
            .delete_state_entries([first_key, second_key].to_vec())
            .expect("Unable to delete state entries");
        assert!(deleted.contains(&format!("{}_{}", "a", "b")));
        assert!(deleted.contains(&format!("{}_{}", "c", "d")));
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a TripleKeyHashAddresser,
    /// will successfully perform the `set_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a KeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a TripleKeyHashAddresser, so
    ///    a key is represented by a tuple of three strings
    /// 2. Create a HashMap, a value to be set in state, with some key and a value represented by a
    ///    ValueType
    ///
    /// This test then verifies a successful return from the `set_state_entry` when providing a
    /// tuple of three strings for the `key` argument and the HashMap for the `values` argument
    fn test_triple_set_state_entry() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to be set in state
        let value = ValueType::Int64(64);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Verify the `set_state_entry` method returns an `Ok(())` result
        assert!(simple_state
            .set_state_entry(
                &("a".to_string(), "b".to_string(), "c".to_string()),
                state_value
            )
            .is_ok());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a TripleKeyHashAddresser,
    /// will successfully perform the `get_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a TripleKeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a TripleKeyHashAddresser, so
    ///    a key is represented by a tuple of three strings
    /// 2. Create a HashMap, a value to be set in state, with a key and a ValueType as the value
    /// 3. Set the created HashMap in state at a key, ('a', 'b', 'c'), using `set_state_entry`
    ///
    /// This test then verifies the `get_state_entry` returns a Some option and the value of the
    /// returned option is equivalent to the HashMap created, including the key and ValueType
    fn test_triple_get_state_entry() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap, with a string key and ValueType value
        let value = ValueType::Int64(64);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Use `set_state_entry` to set the state entry at the ('a', 'b', 'c') key
        simple_state
            .set_state_entry(
                &("a".to_string(), "b".to_string(), "c".to_string()),
                state_value,
            )
            .expect("Unable to set state entry in get_state_entry test");

        // Use the `get_state_entry` method to access the state entry at the ('a', 'b', 'c') key
        let values = simple_state
            .get_state_entry(&("a".to_string(), "b".to_string(), "c".to_string()))
            .unwrap();

        // Verify the return value is equal to the HashMap used when the entry was originally set
        assert!(values.is_some());
        assert_eq!(
            values.unwrap().get(&"key1".to_string()),
            Some(&ValueType::Int64(64))
        );
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a TripleKeyHashAddresser,
    /// will successfully perform the `delete_state_entry` method, after the following steps:
    ///
    /// 1. Create a TestContext and a TripleKeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a TripleKeyHashAddresser, so
    ///    a key is represented by a tuple of three strings
    /// 2. Create a HashMap, a value to be set in state, with a key and a ValueType as the value
    /// 3. Set the created HashMap in state at a key, ('a', 'b', 'c'), using `set_state_entry`
    ///
    /// This test verifies the `delete_state_entry` successfully deletes the intended state entry
    /// by checking that the initial call returns the normalized key wrapped in a Some option
    fn test_triple_delete_state_entry() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap, with a string key and ValueType value
        let value = ValueType::Int64(64);
        let mut state_value = HashMap::new();
        state_value.insert("key1".to_string(), value);

        // Set the HashMap, created above, at the key ('a', 'b', 'c')
        simple_state
            .set_state_entry(
                &("a".to_string(), "b".to_string(), "c".to_string()),
                state_value,
            )
            .expect("Unable to set state entry in get_state_entry test");

        // Call `get_state_entry` to ensure the value has been succesfully set
        simple_state
            .get_state_entry(&("a".to_string(), "b".to_string(), "c".to_string()))
            .expect("Unable to get state entry in delete_state_entries test");

        // Call `delete_state_entry` and verify the return value is a Some option and the value of
        // this option is the correct normalized key, 'a_b_c'
        let deleted = simple_state
            .delete_state_entry(("a".to_string(), "b".to_string(), "c".to_string()))
            .unwrap();
        assert!(deleted.is_some());
        assert_eq!(deleted, Some(format!("{}_{}_{}", "a", "b", "c")));
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a TripleKeyHashAddresser,
    /// will successfully perform the `set_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a TripleKeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a TripleKeyHashAddresser, so
    ///    a key is represented by a tuple of three strings
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    ///
    /// This test then verifies a successful return from the `set_state_entries` when provided a
    /// HashMap of a natural key (the key the entry is meant to be set at) associated with a value,
    /// represented by a HashMap (intended to be used in the state entry)
    fn test_triple_set_state_entries() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &("a".to_string(), "b".to_string(), "c".to_string());
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &("c".to_string(), "d".to_string(), "c".to_string());
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map);
        entries.insert(second_key, second_value_map);

        // Verify the `set_state_entries` method returns an `Ok(())` result
        assert!(simple_state.set_state_entries(entries).is_ok());
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a TripleKeyHashAddresser,
    /// will successfully perform the `get_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a TripleKeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a TripleKeyHashAddresser, so
    ///    a key is represented by a tuple of three strings
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    /// 3. Set these created HashMaps in state using the `set_state_entries` method
    ///
    /// This test verifies the `get_state_entries` returns a HashMap containing the keys, ('a', 'b', 'c')
    /// and ('d', 'e', 'f'), and each is associated with the unique HashMaps used to originally set
    /// the entries
    fn test_triple_get_state_entries() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = &("a".to_string(), "b".to_string(), "c".to_string());
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = &("d".to_string(), "e".to_string(), "f".to_string());
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(first_key, first_value_map.clone());
        entries.insert(second_key, second_value_map.clone());

        // Use the `set_state_entries` method to place the `entries` HashMap in state
        simple_state
            .set_state_entries(entries)
            .expect("Unable to set_state_entries in get_state_entries test");

        // Use the `get_state_entries` method to access the state entries at the ('a', 'b', 'c') and
        // ('d', 'e', 'f') keys
        let values = simple_state
            .get_state_entries([first_key, second_key].to_vec())
            .expect("Unable to get state entries in get_state_entries test");

        // Verify each normalized key has the same associated value as when the entries were
        // originally set
        assert_eq!(
            values.get(&format!("{}_{}_{}", "a", "b", "c")).unwrap(),
            &first_value_map
        );
        assert_eq!(
            values.get(&format!("{}_{}_{}", "d", "e", "f")).unwrap(),
            &second_value_map
        );
    }

    #[test]
    /// This test verifies that a KeyValueTransactionContext, constructed with a TripleKeyHashAddresser,
    /// will successfully perform the `delete_state_entries` method, after the following steps:
    ///
    /// 1. Create a TestContext and a TripleKeyHashAddresser to construct a KeyValueTransactionContext
    ///    Note: This KeyValueTransactionContext is constructed using a TripleKeyHashAddresser, so
    ///    a key is represented by a tuple of three strings
    /// 2. Create two HashMaps, values to be set in state, with values represented by a ValueType
    /// 3. Set these created HashMaps in state using the `set_state_entries` method
    ///
    /// This test verifies `delete_state_entries` successfully deletes the intended state entries
    /// by checking that the call returns a list containing the correct normalized keys
    fn test_triple_delete_state_entries() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Create a HashMap to contain the multiple entries to set in state
        let mut entries = HashMap::new();

        // Create two individual HashMaps, to be associated with unique keys
        let first_key = ("a".to_string(), "b".to_string(), "c".to_string());
        let first_value_map = create_entry_value_map("key1".to_string(), ValueType::Int32(32));
        let second_key = ("d".to_string(), "e".to_string(), "f".to_string());
        let second_value_map =
            create_entry_value_map("key1".to_string(), ValueType::String("String".to_string()));

        // Insert the two HashMaps at unique keys to the HashMap to be set in state
        entries.insert(&first_key, first_value_map.clone());
        entries.insert(&second_key, second_value_map.clone());

        // Call the `set_state_entries` method to place the `entries` HashMap in state
        simple_state
            .set_state_entries(entries)
            .expect("Unable to set_state_entries in delete_state_entries test");

        // Call the `get_state_entries` method to ensure the state entries have been set
        simple_state
            .get_state_entries([&first_key, &second_key].to_vec())
            .expect("Unable to get_state_entries in the delete_state_entries test");

        // Call `delete_state_entries` and verify the return value is a list containing the normalized
        // keys 'a_b_c' and 'd_e_f'
        let deleted = simple_state
            .delete_state_entries([first_key, second_key].to_vec())
            .expect("Unable to delete state entries");
        assert!(deleted.contains(&format!("{}_{}_{}", "a", "b", "c")));
        assert!(deleted.contains(&format!("{}_{}_{}", "d", "e", "f")));
    }

    #[test]
    /// This test verifies the `add_receipt_data` method returns an Ok(()), even though it is
    /// currently not supported in Sawtooth Sabre. This test should return a simple Ok(())
    fn test_add_receipt_data_ok() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Call the `add_receipt_data` method
        let res = simple_state.add_receipt_data(vec![]);

        // Verify this result is an Ok(())
        assert!(res.is_ok());
    }

    #[test]
    /// This test verifies the `add_event` method returns an Ok(()), even though it is currently
    /// not supported in Sawtooth Sabre. This test should return a simple Ok(())
    fn test_add_event_ok() {
        // Create a TestContext and TripleKeyHashAddresser to construct a KeyValueTransactionContext
        let mut context = TestContext::new();
        let addresser = TripleKeyHashAddresser::new("prefix".to_string(), None, None)
            .expect("Unable to construct Addresser");
        let simple_state = KeyValueTransactionContext::new(&mut context, addresser);

        // Call the `add_event` method
        let res = simple_state.add_event("event".to_string(), vec![], vec![]);

        // Verify this result is an Ok(())
        assert!(res.is_ok());
    }
}