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

amoeba piece: 100% test coverage #212

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all 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
106 changes: 104 additions & 2 deletions wardrobe/amoeba/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ fn creation_with_inputs_fails() {
);
}

#[test]
fn creation_with_evictions_fails() {
let example = AmoebaDetails {
generation: 0,
four_bytes: *b"test",
};
let evicted_input_data = vec![example.clone().into()];
let output_data = vec![example.into()];

assert_eq!(
AmoebaCreation.check(&[], &evicted_input_data, &[], &output_data),
Err(ConstraintCheckerError::NoEvictionsAllowed),
);
}

#[test]
fn creation_with_badly_typed_output_fails() {
let input_data = Vec::new();
Expand Down Expand Up @@ -109,7 +124,31 @@ fn mitosis_valid_transaction_works() {
}

#[test]
fn mitosis_wrong_generation() {
fn mitosis_with_evictions_fails() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let d1 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let d2 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let input_data = vec![mother.clone().into()];
let evicted_input_data = vec![mother.into()];
let output_data = vec![d1.into(), d2.into()];

assert_eq!(
AmoebaMitosis.check(&input_data, &evicted_input_data, &[], &output_data),
Err(ConstraintCheckerError::NoEvictionsAllowed)
);
}

#[test]
fn mitosis_wrong_generation_first_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
Expand All @@ -131,6 +170,29 @@ fn mitosis_wrong_generation() {
);
}

#[test]
fn mitosis_wrong_generation_second_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let d1 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let d2 = AmoebaDetails {
generation: 3, // This daughter has the wrong generation
four_bytes: *b"test",
};
let input_data = vec![mother.into()];
let output_data = vec![d1.into(), d2.into()];

assert_eq!(
AmoebaMitosis.check(&input_data, &[], &[], &output_data),
Err(ConstraintCheckerError::WrongGeneration),
);
}

#[test]
fn mitosis_badly_typed_input() {
let mother = Bogus;
Expand Down Expand Up @@ -171,7 +233,27 @@ fn mitosis_no_input() {
}

#[test]
fn mitosis_badly_typed_output() {
fn mitosis_badly_typed_first_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let d1 = Bogus;
let d2 = AmoebaDetails {
generation: 2,
four_bytes: *b"test",
};
let input_data = vec![mother.into()];
let output_data = vec![d1.into(), d2.into()];

assert_eq!(
AmoebaMitosis.check(&input_data, &[], &[], &output_data),
Err(ConstraintCheckerError::BadlyTypedOutput),
);
}

#[test]
fn mitosis_badly_typed_second_daughter() {
let mother = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
Expand Down Expand Up @@ -264,6 +346,26 @@ fn death_no_input() {
);
}

#[test]
fn death_eviction_not_allowed() {
let a1 = AmoebaDetails {
generation: 1,
four_bytes: *b"test",
};
let a2 = AmoebaDetails {
generation: 4,
four_bytes: *b"test",
};
let input_data = vec![a1.into()];
let evicted_input_data = vec![a2.into()];
let output_data = vec![];

assert_eq!(
AmoebaDeath.check(&input_data, &evicted_input_data, &[], &output_data),
Err(ConstraintCheckerError::NoEvictionsAllowed),
);
}

#[test]
fn death_multiple_inputs() {
let a1 = AmoebaDetails {
Expand Down
Loading