Skip to content

Commit

Permalink
feat(applying): collateral test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicoLeberle committed Jan 2, 2024
1 parent eba4081 commit 32d70bd
Show file tree
Hide file tree
Showing 2 changed files with 668 additions and 28 deletions.
53 changes: 29 additions & 24 deletions pallas-applying/src/alonzo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,37 @@ fn check_collaterals_assets(
prot_pps: &AlonzoProtParams,
) -> ValidationResult {
let fee_percentage: u64 = tx_body.fee * prot_pps.collateral_percent;
for input in tx_body.inputs.iter() {
match utxos.get(&MultiEraInput::from_alonzo_compatible(input)) {
Some(multi_era_output) => match MultiEraOutput::as_alonzo(multi_era_output) {
Some(TransactionOutput {
amount: Value::Coin(n),
..
}) => {
if *n * 100 < fee_percentage {
return Err(Alonzo(CollateralMinLovelace));
}
}
Some(TransactionOutput {
amount: Value::Multiasset(n, multi_assets),
..
}) => {
if *n * 100 < fee_percentage {
return Err(Alonzo(CollateralMinLovelace));
}
if !multi_assets.is_empty() {
return Err(Alonzo(NonLovelaceCollateral));
}
match &tx_body.collateral {
Some(collaterals) => {
for collateral in collaterals {
match utxos.get(&MultiEraInput::from_alonzo_compatible(collateral)) {
Some(multi_era_output) => match MultiEraOutput::as_alonzo(multi_era_output) {
Some(TransactionOutput {
amount: Value::Coin(n),
..
}) => {
if *n * 100 < fee_percentage {
return Err(Alonzo(CollateralMinLovelace));
}
}
Some(TransactionOutput {
amount: Value::Multiasset(n, multi_assets),
..
}) => {
if *n * 100 < fee_percentage {
return Err(Alonzo(CollateralMinLovelace));
}
if !multi_assets.is_empty() {
return Err(Alonzo(NonLovelaceCollateral));
}
}
None => (),
},
None => return Err(Alonzo(CollateralNotInUTxO)),
}
None => (),
},
None => return Err(Alonzo(CollateralNotInUTxO)),
}
}
None => return Err(Alonzo(CollateralMissing)),
}
Ok(())
}
Expand Down
Loading

0 comments on commit 32d70bd

Please sign in to comment.