Skip to content

Commit

Permalink
feat(data_structures): allow backwards-compatibility of key data stru…
Browse files Browse the repository at this point in the history
…ctures
  • Loading branch information
aesedepece committed Nov 20, 2023
1 parent a5c9917 commit 14e733e
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 23 deletions.
35 changes: 33 additions & 2 deletions data_structures/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4445,6 +4445,7 @@ mod tests {
};

use crate::{
proto::versioning::{ProtocolVersion, VersionedHashable},
superblock::{mining_build_superblock, ARSIdentities},
transaction::{CommitTransactionBody, RevealTransactionBody, VTTransactionBody},
};
Expand Down Expand Up @@ -4553,7 +4554,22 @@ mod tests {
fn test_block_hashable_trait() {
let block = block_example();
let expected = "70e15ac70bb00f49c7a593b2423f722dca187bbae53dc2f22647063b17608c01";
assert_eq!(block.hash().to_string(), expected);
assert_eq!(
block.versioned_hash(ProtocolVersion::Legacy).to_string(),
expected
);
let expected = "29ef68357a5c861b9dbe043d351a28472ca450edcda25de4c9b80a4560a28c0f";
assert_eq!(
block
.versioned_hash(ProtocolVersion::Transition)
.to_string(),
expected
);
let expected = "29ef68357a5c861b9dbe043d351a28472ca450edcda25de4c9b80a4560a28c0f";
assert_eq!(
block.versioned_hash(ProtocolVersion::Final).to_string(),
expected
);
}

#[test]
Expand Down Expand Up @@ -6625,6 +6641,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let expected_indices = vec![0, 2, 2];
Expand Down Expand Up @@ -6679,6 +6696,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let expected_indices = vec![0, 2, 2, 8, 10, 6, 4, 6];
Expand Down Expand Up @@ -6714,6 +6732,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let result = sb.dr_proof_of_inclusion(&[b1, b2], &dr_txs[2]);
Expand All @@ -6724,7 +6743,14 @@ mod tests {
fn test_dr_merkle_root_no_block() {
let dr_txs = build_test_dr_txs(3);

let sb = mining_build_superblock(&[], &[Hash::default()], 1, Hash::default(), 1);
let sb = mining_build_superblock(
&[],
&[Hash::default()],
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let result = sb.dr_proof_of_inclusion(&[], &dr_txs[2]);
assert!(result.is_none());
Expand All @@ -6750,6 +6776,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let expected_indices = vec![0, 2];
Expand Down Expand Up @@ -6788,6 +6815,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let expected_indices = vec![0, 2, 2];
Expand Down Expand Up @@ -6850,6 +6878,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let expected_indices = vec![0, 2, 2, 8, 10, 6, 4, 6];
Expand Down Expand Up @@ -6885,6 +6914,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let result = sb.tally_proof_of_inclusion(&[b1, b2], &tally_txs[2]);
Expand Down Expand Up @@ -6916,6 +6946,7 @@ mod tests {
1,
Hash::default(),
1,
ProtocolVersion::Legacy,
);

let expected_indices = vec![0, 2, 2];
Expand Down
1 change: 1 addition & 0 deletions data_structures/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::convert::TryFrom;
use std::fmt::Debug;

pub mod schema;
pub mod versioning;

/// Used for establishing correspondence between rust struct
/// and protobuf rust struct
Expand Down
Loading

0 comments on commit 14e733e

Please sign in to comment.