-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(applying): add remaining validations for Byron era (#325)
- Loading branch information
1 parent
ac4aef4
commit 68b46c3
Showing
7 changed files
with
553 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,12 @@ authors = ["Maico Leberle <[email protected]>"] | |
doctest = false | ||
|
||
[dependencies] | ||
pallas-addresses = { path = "../pallas-addresses" } | ||
pallas-codec = { path = "../pallas-codec" } | ||
pallas-crypto = { path = "../pallas-crypto" } | ||
pallas-primitives = { path = "../pallas-primitives" } | ||
pallas-traverse = { path = "../pallas-traverse" } | ||
rand = "0.8" | ||
|
||
[dev-dependencies] | ||
hex = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,51 @@ | ||
//! Base types used for validating transactions in each era. | ||
use std::{borrow::Cow, collections::HashMap}; | ||
use std::collections::HashMap; | ||
|
||
pub use pallas_traverse::{MultiEraInput, MultiEraOutput}; | ||
|
||
pub type UTxOs<'b> = HashMap<MultiEraInput<'b>, MultiEraOutput<'b>>; | ||
|
||
// TODO: add a field for each protocol parameter in the Byron era. | ||
#[derive(Debug, Clone)] | ||
pub struct ByronProtParams; | ||
pub struct ByronProtParams { | ||
pub min_fees_const: u64, | ||
pub min_fees_factor: u64, | ||
pub max_tx_size: u64, | ||
} | ||
|
||
// TODO: add variants for the other eras. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum MultiEraProtParams<'b> { | ||
Byron(Box<Cow<'b, ByronProtParams>>), | ||
pub enum MultiEraProtParams { | ||
Byron(ByronProtParams), | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Environment { | ||
pub prot_params: MultiEraProtParams, | ||
pub prot_magic: u32, | ||
} | ||
|
||
#[non_exhaustive] | ||
pub enum SigningTag { | ||
Tx = 0x01, | ||
RedeemTx = 0x02, | ||
} | ||
|
||
// TODO: replace this generic variant with validation-rule-specific ones. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum ValidationError { | ||
InputMissingInUTxO, | ||
TxInsEmpty, | ||
TxOutsEmpty, | ||
OutputWithoutLovelace, | ||
UnknownTxSize, | ||
UnableToComputeFees, | ||
FeesBelowMin, | ||
MaxTxSizeExceeded, | ||
UnableToProcessWitnesses, | ||
MissingWitness, | ||
WrongSignature, | ||
} | ||
|
||
pub type ValidationResult = Result<(), ValidationError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Testing framework documentation | ||
|
||
## Execution | ||
Starting at the root of the repository, simply go to *pallas-applying* and run `cargo test`. | ||
|
||
|
||
## Explanations | ||
*pallas-applying/tests/byron.rs* contains multiple unit tests for validation on the Byron era. | ||
|
||
The first one, **suceessful_mainnet_tx**, is a positive unit test. It takes the CBOR of a mainnet transaction. Namely, the one whose hash is `a06e5a0150e09f8983be2deafab9e04afc60d92e7110999eb672c903343f1e26`, which can be viewed on Cardano Explorer [here](https://cexplorer.io/tx/a06e5a0150e09f8983be2deafab9e04afc60d92e7110999eb672c903343f1e26). Such a transaction has a single input which is added to the UTxO, prior to validation, by associating it to a transaction output sitting at its real (mainnet) address. This information was taken from Cardano Explorer as well, following the address link of the only input to the transaction, and taking its raw address CBOR content. | ||
|
||
Then comes a series of negative unit tests, namely: | ||
- **empty_ins** takes the mainnet transaction, removes its input, and calls validation on it. | ||
- **empty_outs** is analogous to the **empty_ins** test, removing all outputs instead. | ||
- **unfound_utxo** takes the mainnet transaction and calls validation on it without a proper UTxO containing an entry for its input. | ||
- **output_without_lovelace** takes the mainnet transaction and modifies its output by removing all of its lovelace. | ||
- **not_enough_fees** takes the mainnet transaction and calls validation on it using wrong protocol parameters, which requiere that the transaction pay a higher fee than the one actually paid. | ||
- **tx_size_exceeds_max** takes the mainnet transaction and calls validation on it using wrong protocol parameters, which only allow transactions of a size smaller than that of the transaction. | ||
- **missing_witness** takes the mainnet transaction, removes its witness, and calls validation on it. | ||
- **wrong_signature** takes the mainnet transaction, alters the content of its witness, and calls validation on it. |
Oops, something went wrong.