Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Added tests for each SubintentStructureError #2013

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions radix-transactions/src/manifest/manifest_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,14 @@ pub struct YieldToParent {
pub args: ManifestValue,
}

impl YieldToParent {
pub fn empty() -> Self {
Self {
args: ManifestValue::unit(),
}
}
}

impl ManifestInstruction for YieldToParent {
const IDENT: &'static str = "YIELD_TO_PARENT";
const ID: u8 = INSTRUCTION_YIELD_TO_PARENT_DISCRIMINATOR;
Expand Down
6 changes: 6 additions & 0 deletions radix-transactions/src/model/v1/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub struct BlobsV1 {
pub blobs: Vec<BlobV1>,
}

impl BlobsV1 {
pub fn none() -> Self {
Self { blobs: Vec::new() }
}
}

impl From<IndexMap<Hash, Vec<u8>>> for BlobsV1 {
fn from(blobs: IndexMap<Hash, Vec<u8>>) -> Self {
let blobs = blobs
Expand Down
6 changes: 6 additions & 0 deletions radix-transactions/src/model/v2/child_subintent_hashes_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ impl ChildSubintentSpecifier {
}
}

impl From<SubintentHash> for ChildSubintentSpecifier {
fn from(hash: SubintentHash) -> Self {
Self { hash }
}
}

/// A new-type representing the index of a referenced intent.
/// The first few of these will be the children of the given intent.
///
Expand Down
12 changes: 12 additions & 0 deletions radix-transactions/src/model/v2/intent_signatures_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ pub struct IntentSignaturesV2 {
pub signatures: Vec<IntentSignatureV1>,
}

impl IntentSignaturesV2 {
pub fn none() -> Self {
Self {
signatures: Vec::new(),
}
}

pub fn new(signatures: Vec<IntentSignatureV1>) -> Self {
Self { signatures }
}
}

impl TransactionPartialPrepare for IntentSignaturesV2 {
type Prepared = PreparedIntentSignaturesV2;
}
Expand Down
2 changes: 1 addition & 1 deletion radix-transactions/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pub use transaction_structure_validator::*;
pub use transaction_validation_configuration::*;
pub use transaction_validator::*;
#[cfg(test)]
pub use validation_test_helpers::*;
pub(crate) use validation_test_helpers::*;
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ impl TransactionValidator {
// We also:
// * Save the unique parent on each subintent which is a child
// * Save the children of an intent into its intent details
//
// After this step, we know that each subintent has at most one parent.
// We determine that every subintent has exactly one parent in step 4.

// STEP 2A - Handle children of the root intent
{
Expand Down Expand Up @@ -186,8 +189,14 @@ impl TransactionValidator {
// We traverse the child relationships from the root, and mark a depth.
// We error if any exceed the maximum depth.
//
// As each child has at most one parent, we can guarantee the work is bounded
// by the total number of subintents.
// The iteration count is guaranteed to be bounded by the number of subintents because:
// * Each subintent has at most one parent from step 2.
// * Each parent -> child relationship is traversed at most once in the iteration.
// Quick proof by contradiction:
// - Assume not. Then some parent A is visited more than once.
// - Take the earliest such A in the iteration.
// - On both of its visits, A can only have been visited from its parent B.
// - But then B must have been visited more than once, contradicting the minimality of A.
let mut work_list = vec![];
for index in root_intent_details.children.iter() {
work_list.push((*index, 1));
Expand Down Expand Up @@ -224,8 +233,8 @@ impl TransactionValidator {
// * Every subintent has a unique parent.
// * Every subintent is reachable from the root.
//
// Therefore there is a unique path from every subintent to the root
// So we have confirmed the subintents form a tree.
// Therefore there is a unique path from every subintent to the root, which implies
// the subintents form a tree.
for (hash, details) in non_root_subintent_details.iter() {
if details.depth == 0 {
return Err(
Expand Down
Loading
Loading