Unit Testing Transaction
The parsed transaction can be used for inspection, primarily in the scenario of unit testing the transaction-building process.
To obtain the TxTester
:
Interpret result
After adding checks, the success case:
If case there is an error, there would be tracing about where it fails the checks:
Testing inputs
Testing inputs starts with locating the inputs you want to test. The filtering will not reset until the filtering methods are called again.
all_inputs
- not apply filtersinputs_at
- filtering inputs with addressinputs_with
- filtering inputs with tokeninputs_with_policy
- filtering inputs with policy idinputs_at_with
- filtering inputs with address and tokeninputs_at_with_policy
- filtering inputs with address and policy id
Then it comes with the checks:
inputs_value
- check the aggregated value of filtered inputsinputs_inline_datum_exist
- check whether any of the filtered inputs with the inline datum
Example
Testing outputs
Testing outputs starts with locating the outputs you want to test. The filtering will not reset until the filtering methods are called again.
all_outputs
- not apply filtersoutputs_at
- filtering outputs with addressoutputs_with
- filtering outputs with tokenoutputs_with_policy
- filtering outputs with policy idoutputs_at_with
- filtering outputs with address and tokenoutputs_at_with_policy
- filtering outputs with address and policy id
Then it comes with the checks:
outputs_value
- check the aggregated value of filtered outputsoutputs_inline_datum_exist
- check whether any of the filtered outputs with the inline datum
Example
Testing mints
Testing mints with below APIs:
token_minted
- checks if a specific token is minted in the transactiononly_token_minted
- checks if a specific token is minted in the transaction and that it is the only mintpolicy_only_minted_token
- checks if a specific token is minted in the transaction, ensuring that it is the only mint for the given policy IDcheck_policy_only_burn
- checks if a specific policy ID is burned in the transaction, ensuring that it is the only minting (i.e. burning item).
Testing time
Testing time with below APIs:
valid_after
- checks if the transaction is valid after a specified timestampvalid_before
- checks if the transaction is valid before a specified timestamp
Testing signature
Testing whether the signature is required in the transaction with below APIs:
key_signed
- checks if a specific key is signed in the transactionone_of_keys_signed
- checks if any one of the specified keys is signed in the transactionall_keys_signed
- checks if all specified keys are signed in the transaction
Last updated