Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Aug 26, 2024
1 parent dd99286 commit cb2b128
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 66 deletions.
7 changes: 3 additions & 4 deletions base_layer/core/src/covenants/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,14 @@ mod test {
}

#[test]
fn test() -> Result<(), Box<dyn std::error::Error>> {
fn test() {
test_case(CovenantArg::Uint(2048), &[ARG_UINT, 0, 8, 0, 0, 0, 0, 0, 0][..]);
test_case(
CovenantArg::Covenant(covenant!(identity())?),
CovenantArg::Covenant(covenant!(identity()).unwrap()),
&[ARG_COVENANT, 0x01, 0x20][..],
);
test_case(
CovenantArg::Bytes(BytesArg::try_from(vec![0x01, 0x02, 0xaa])?),
CovenantArg::Bytes(BytesArg::try_from(vec![0x01, 0x02, 0xaa]).unwrap()),
&[ARG_BYTES, 0x03, 0x00, 0x00, 0x00, 0x01, 0x02, 0xaa][..],
);
test_case(
Expand Down Expand Up @@ -331,7 +331,6 @@ mod test {
CovenantArg::OutputFields(OutputFields::from(vec![OutputField::Features, OutputField::Commitment])),
&[ARG_OUTPUT_FIELDS, 0x02, FIELD_FEATURES, FIELD_COMMITMENT],
);
Ok(())
}
}
}
6 changes: 2 additions & 4 deletions base_layer/core/src/covenants/covenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ mod test {
}

#[tokio::test]
async fn it_executes_the_covenant() -> Result<(), Box<dyn std::error::Error>> {
async fn it_executes_the_covenant() {
let key_manager = create_memory_db_key_manager().unwrap();
let mut outputs = create_outputs(10, UtxoTestParams::default(), &key_manager).await;
outputs[4].features.maturity = 42;
Expand All @@ -223,11 +223,10 @@ mod test {
.unwrap();
let num_matching_outputs = covenant.execute(0, &input, &outputs).unwrap();
assert_eq!(num_matching_outputs, 3);
Ok(())
}

#[tokio::test]
async fn test_borsh_de_serialization() -> Result<(), Box<dyn std::error::Error>> {
async fn test_borsh_de_serialization() {
let key_manager = create_memory_db_key_manager().unwrap();
let mut outputs = create_outputs(10, UtxoTestParams::default(), &key_manager).await;
outputs[4].features.maturity = 42;
Expand All @@ -246,7 +245,6 @@ mod test {
let buf = &mut buf.as_slice();
assert_eq!(covenant, Covenant::deserialize(buf).unwrap());
assert_eq!(buf, &[1, 2, 3]);
Ok(())
}

#[tokio::test]
Expand Down
4 changes: 1 addition & 3 deletions base_layer/core/src/covenants/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod test {
}

#[test]
fn it_decodes_from_well_formed_bytes() -> Result<(), Box<dyn std::error::Error>> {
fn it_decodes_from_well_formed_bytes() {
let hash = FixedHash::from_hex("53563b674ba8e5166adb57afa8355bcf2ee759941eef8f8959b802367c2558bd").unwrap();
let mut bytes = Vec::new();
covenant!(fields_hashed_eq(
Expand Down Expand Up @@ -204,8 +204,6 @@ mod test {
);

assert!(decoder.next().is_none());

Ok(())
}

mod covenant_read_ext {
Expand Down
6 changes: 2 additions & 4 deletions base_layer/core/src/covenants/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,16 @@ mod tests {
}

#[test]
fn it_encodes_tokens_correctly() -> Result<(), Box<dyn std::error::Error>> {
fn it_encodes_tokens_correctly() {
let covenant = covenant!(and(identity(), or(identity()))).unwrap();
let encoder = CovenantTokenEncoder::new(covenant.tokens());
let mut buf = Vec::<u8>::new();
encoder.write_to(&mut buf).unwrap();
assert_eq!(buf, [FILTER_AND, FILTER_IDENTITY, FILTER_OR, FILTER_IDENTITY]);
Ok(())
}

#[test]
fn it_encodes_args_correctly() -> Result<(), Box<dyn std::error::Error>> {
fn it_encodes_args_correctly() {
let dummy = FixedHash::zero();
let covenant = covenant!(field_eq(@field::features, @hash(dummy))).unwrap();
let encoder = CovenantTokenEncoder::new(covenant.tokens());
Expand All @@ -97,7 +96,6 @@ mod tests {
ARG_HASH
]);
assert_eq!(buf[4..], [0u8; 32]);
Ok(())
}

mod covenant_write_ext {
Expand Down
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ mod test {
}

#[tokio::test]
async fn it_returns_false_if_not_eq() -> Result<(), Box<dyn std::error::Error>> {
async fn it_returns_false_if_not_eq() {
let key_manager = create_memory_db_key_manager().unwrap();
let side_chain_features = make_sample_sidechain_feature();
let output = create_outputs(
Expand Down Expand Up @@ -486,7 +486,6 @@ mod test {
assert!(!OutputField::MinimumValuePromise
.is_eq(&output, &MicroMinotari::default())
.unwrap());
Ok(())
}
}

Expand Down
9 changes: 3 additions & 6 deletions base_layer/core/src/covenants/filters/absolute_height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_all_out_if_height_not_reached() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_all_out_if_height_not_reached() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(absolute_height(@uint(100))).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -81,11 +81,10 @@ mod test {
AbsoluteHeightFilter.filter(&mut context, &mut output_set).unwrap();

assert!(output_set.is_empty());
Ok(())
}

#[tokio::test]
async fn it_filters_all_in_if_height_reached() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_all_in_if_height_reached() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(absolute_height(@uint(100))).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -95,11 +94,10 @@ mod test {
AbsoluteHeightFilter.filter(&mut context, &mut output_set).unwrap();

assert_eq!(output_set.len(), 10);
Ok(())
}

#[tokio::test]
async fn it_filters_all_in_if_height_exceeded() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_all_in_if_height_exceeded() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(absolute_height(@uint(42))).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -109,6 +107,5 @@ mod test {
AbsoluteHeightFilter.filter(&mut context, &mut output_set).unwrap();

assert_eq!(output_set.len(), 10);
Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/and.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_outputset_using_intersection() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_outputset_using_intersection() {
let key_manager = create_memory_db_key_manager().unwrap();
let script = script!(CheckHeight(101)).unwrap();
let covenant = covenant!(and(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))).unwrap();
Expand Down Expand Up @@ -84,6 +84,5 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
Ok(())
}
}
21 changes: 7 additions & 14 deletions base_layer/core/src/covenants/filters/field_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_uint() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_uint() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(field_eq(@field::features_maturity, @uint(42))).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -103,11 +103,10 @@ mod test {

assert_eq!(output_set.len(), 1);
assert_eq!(output_set.get(5).unwrap().features.maturity, 42);
Ok(())
}

#[tokio::test]
async fn it_filters_sender_offset_public_key() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_sender_offset_public_key() {
let pk = PublicKey::from_hex("5615a327e1d19da34e5aa8bbd2ecc97addf29b158844b885bfc4efa0dab17052").unwrap();
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(field_eq(
Expand All @@ -126,11 +125,10 @@ mod test {

assert_eq!(output_set.len(), 1);
assert_eq!(output_set.get(5).unwrap().sender_offset_public_key, pk);
Ok(())
}

#[tokio::test]
async fn it_filters_commitment() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_commitment() {
let key_manager = create_memory_db_key_manager().unwrap();
let commitment =
Commitment::from_hex("7ca31ba517d8b563609ed6707fedde5a2be64ac1d67b254cb5348bc2f680557f").unwrap();
Expand All @@ -151,11 +149,10 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
Ok(())
}

#[tokio::test]
async fn it_filters_tari_script() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_tari_script() {
let key_manager = create_memory_db_key_manager().unwrap();
let script = script!(CheckHeight(100)).unwrap();
let covenant = covenant!(field_eq(
Expand All @@ -175,11 +172,10 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
Ok(())
}

#[tokio::test]
async fn it_filters_covenant() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_covenant() {
let key_manager = create_memory_db_key_manager().unwrap();
let next_cov = covenant!(and(identity(), or(field_eq(@field::features_maturity, @uint(42))))).unwrap();
let covenant = covenant!(field_eq(@field::covenant, @covenant(next_cov.clone()))).unwrap();
Expand All @@ -195,11 +191,10 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
Ok(())
}

#[tokio::test]
async fn it_filters_output_type() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_output_type() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(field_eq(@field::features_output_type, @output_type(Coinbase))).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -214,11 +209,10 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
Ok(())
}

#[tokio::test]
async fn it_errors_if_field_has_an_incorrect_type() -> Result<(), Box<dyn std::error::Error>> {
async fn it_errors_if_field_has_an_incorrect_type() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(field_eq(@field::features, @uint(42))).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -229,6 +223,5 @@ mod test {
let mut output_set = OutputSet::new(&outputs);
let err = FieldEqFilter.filter(&mut context, &mut output_set).unwrap_err();
unpack_enum!(CovenantError::InvalidArgument { .. } = err);
Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/fields_hashed_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_outputs_with_fields_that_hash_to_given_hash() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_outputs_with_fields_that_hash_to_given_hash() {
let key_manager = create_memory_db_key_manager().unwrap();
let features = OutputFeatures {
maturity: 42,
Expand Down Expand Up @@ -94,6 +94,5 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
Ok(())
}
}
4 changes: 1 addition & 3 deletions base_layer/core/src/covenants/filters/fields_preserved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_outputs_that_match_input_fields() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_outputs_that_match_input_fields() {
let covenant =
covenant!(fields_preserved(@fields(@field::features_maturity, @field::features_output_type))).unwrap();
let key_manager = create_memory_db_key_manager().unwrap();
Expand Down Expand Up @@ -76,7 +76,5 @@ mod test {

assert_eq!(output_set.get_selected_indexes(), vec![5, 7]);
assert_eq!(output_set.len(), 2);

Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod tests {
};

#[tokio::test]
async fn it_returns_the_outputset_unchanged() -> Result<(), Box<dyn std::error::Error>> {
async fn it_returns_the_outputset_unchanged() {
let key_manager = create_memory_db_key_manager().unwrap();
let covenant = covenant!(identity()).unwrap();
let input = create_input(&key_manager).await;
Expand All @@ -52,6 +52,5 @@ mod tests {
let previous_len = output_set.len();
IdentityFilter.filter(&mut context, &mut output_set).unwrap();
assert_eq!(output_set.len(), previous_len);
Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_compliment_of_filter() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_compliment_of_filter() {
let key_manager = create_memory_db_key_manager().unwrap();
let script = script!(CheckHeight(100)).unwrap();
let covenant = covenant!(not(or(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone()))))).unwrap();
Expand All @@ -72,6 +72,5 @@ mod test {

assert_eq!(output_set.len(), 7);
assert_eq!(output_set.get_selected_indexes(), vec![0, 1, 2, 3, 4, 6, 9]);
Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_outputset_using_union() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_outputset_using_union() {
let key_manager = create_memory_db_key_manager().unwrap();
let script = script!(CheckHeight(100)).unwrap();
let covenant = covenant!(or(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))).unwrap();
Expand All @@ -78,6 +78,5 @@ mod test {

assert_eq!(output_set.len(), 3);
assert_eq!(output_set.get_selected_indexes(), vec![5, 7, 8]);
Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/output_hash_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_output_with_specific_hash() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_output_with_specific_hash() {
let key_manager = create_memory_db_key_manager().unwrap();
let output = create_outputs(1, Default::default(), &key_manager).await.remove(0);
let output_hash = output.hash();
Expand All @@ -74,6 +74,5 @@ mod test {

assert_eq!(output_set.len(), 1);
assert_eq!(output_set.get_selected_indexes(), vec![5]);
Ok(())
}
}
3 changes: 1 addition & 2 deletions base_layer/core/src/covenants/filters/xor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod test {
};

#[tokio::test]
async fn it_filters_outputset_using_symmetric_difference() -> Result<(), Box<dyn std::error::Error>> {
async fn it_filters_outputset_using_symmetric_difference() {
let key_manager = create_memory_db_key_manager().unwrap();
let script = script!(CheckHeight(100)).unwrap();
let covenant = covenant!(and(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))).unwrap();
Expand All @@ -80,6 +80,5 @@ mod test {

assert_eq!(output_set.len(), 2);
assert_eq!(output_set.get_selected_indexes(), vec![7, 8]);
Ok(())
}
}
Loading

0 comments on commit cb2b128

Please sign in to comment.