Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Jan 27, 2023
1 parent 8703026 commit d358a3e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions base_layer/core/src/transactions/coinbase_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ mod test {

tx.body.add_output(coinbase2);
tx.body.add_kernel(coinbase_kernel2);
tx.body.sort();

// lets add duplciate coinbase kernel
let mut coinbase2 = tx2.body.outputs()[0].clone();
Expand All @@ -579,6 +580,8 @@ mod test {
tx_kernel_test.body.add_output(coinbase2);
tx_kernel_test.body.add_kernel(coinbase_kernel2);

tx_kernel_test.body.sort();

// test catches that coinbase count on the utxo is wrong
assert!(matches!(
tx.body.check_coinbase_output(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ fn check_cut_through() {
assert_eq!(tx2.body.outputs().len(), 3);
assert_eq!(tx2.body.kernels().len(), 1);

let tx3 = tx + tx2;
let mut tx3 = tx + tx2;
let mut tx3_cut_through = tx3.clone();
// check that all inputs are as we expect them to be
assert_eq!(tx3.body.inputs().len(), 3);
Expand All @@ -376,6 +376,8 @@ fn check_cut_through() {
tx3_cut_through.body.outputs_mut().retain(|x| !input.is_equal_to(x));
tx3_cut_through.body.inputs_mut().retain(|x| *x != input);
}
tx3.body.sort();
tx3_cut_through.body.sort();

// Validate basis transaction where cut-through has not been applied.
validator.validate(&tx3, None, None, u64::MAX).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ impl TransactionBuilder {
) -> Result<Transaction, TransactionError> {
if let (Some(script_offset), Some(offset)) = (self.script_offset, self.offset) {
let (i, o, k) = self.body.dissolve();
let tx = Transaction::new(i, o, k, offset, script_offset);
let mut tx = Transaction::new(i, o, k, offset, script_offset);
tx.body.sort();
let validator = TransactionInternalConsistencyValidator::new(true, rules, factories.clone());
validator
.validate(&tx, self.reward, prev_header, height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,7 @@ impl SenderTransactionProtocol {
.validate()
.and_then(|_| Self::build_transaction(info, rules.clone(), factories));
match result {
Ok(mut transaction) => {
transaction.body.sort();
Ok(transaction) => {
let validator = TransactionInternalConsistencyValidator::new(true, rules, factories.clone());
let result = validator
.validate(&transaction, None, prev_header, height)
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/validation/block_body/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async fn it_limits_the_script_byte_size() {
.add_consensus_constants(
ConsensusConstantsBuilder::new(Network::LocalNet)
.with_coinbase_lockheight(0)
.with_max_script_byte_size(0)
.with_max_script_byte_size(2)
.build(),
)
.build();
Expand Down
8 changes: 3 additions & 5 deletions base_layer/core/tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,8 @@ async fn consensus_validation_large_tx() {
.build()
.unwrap();
let kernels = vec![kernel];
let tx = Transaction::new(inputs, outputs, kernels, offset, script_offset_pvt);
let mut tx = Transaction::new(inputs, outputs, kernels, offset, script_offset_pvt);
tx.body.sort();

let height = blocks.len() as u64;
let constants = consensus_manager.consensus_constants(height);
Expand All @@ -1021,10 +1022,7 @@ async fn consensus_validation_large_tx() {
let factories = CryptoFactories::default();
let validator = TransactionInternalConsistencyValidator::new(true, consensus_manager.clone(), factories);
let err = validator.validate(&tx, None, None, u64::MAX).unwrap_err();
assert!(matches!(
err,
ValidationError::BlockTooLarge { .. }
));
assert!(matches!(err, ValidationError::BlockTooLarge { .. }));

let weighting = constants.transaction_weight();
let weight = tx.calculate_weight(weighting);
Expand Down

0 comments on commit d358a3e

Please sign in to comment.