mocktail

Mocktail contains a set of functions to build transactions for testing purposes.

To use Mocktail Tx, there are 4 steps

  1. Starts with mocktail_tx() to create a new transaction builder.
  2. Use tx building methods similar to MeshJS lower level APIs to build the transaction.
  3. Call complete to complete building transaction.
  4. Finally, if there is any whole items to be added to the transaction, use the add functions.

Mocktail is built with devex and multiple test cases compatibility in mind.

  1. It is pipable.
  2. For every tx building and adding methods, it takes first param as condition. that function will only run when this condition is True.

Example

let tx: Transaction =
  mocktail_tx()
    |> required_signer_hash(is_signature_provided, mock_pub_key_hash(0))
    |> script_withdrawal(True, mock_script_hash(0), 0)
    |> script_withdrawal(True, mock_script_hash(1), 0)
    |> required_signer_hash(True, mock_pub_key_hash(1))
    |> complete()
    |> add_reference_input(True, mock_oracle_ref_input_1())
    |> add_reference_input(True, mock_oracle_ref_input_2())
    |> add_output(True, mock_pub_key_output(mock_fee_collection_address, mock_fee))

Types

A mock transaction builder. It can be initialized with mocktail_tx().

Constructors

  • MocktailTx {
      tx: Transaction,
      queue_input: Option<Input>,
      queue_output: Option<Output>,
      queue_ref_input: Option<Input>,
    }

Functions

mocktail_tx() -> MocktailTx

Initialize a new mock transaction builder, and output a built transaction wiht .complete().

let tx = mocktail_tx()
  |> ...other tx building methods
  |> complete();

tx_in(
  mocktail_tx: MocktailTx,
  condition: Bool,
  tx_hash: ByteArray,
  tx_index: Int,
  amount: Value,
  address: Address,
) -> MocktailTx

Tx building method - Add an input to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> tx_in(condition, tx_hash, tx_index, amount, address)
  |> ...other tx building methods
  |> complete();

tx_in_inline_datum(
  mocktail_tx: MocktailTx,
  condition: Bool,
  datum: Data,
) -> MocktailTx

Tx building method - Add an input with inline datum to the transaction. This can only be used right after tx_in. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> tx_in(condition, tx_hash, tx_index, amount, address)
  |> tx_in_inline_datum(condition, datum)
  |> ...other tx building methods
  |> complete();

tx_out(
  mocktail_tx: MocktailTx,
  condition: Bool,
  address: Address,
  amount: Value,
) -> MocktailTx

Tx building method - Add an output to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> tx_out(condition, address, amount)
  |> ...other tx building methods
  |> complete();

tx_out_inline_datum(
  mocktail_tx: MocktailTx,
  condition: Bool,
  datum: Data,
) -> MocktailTx

Tx building method - Add an output with inline datum to the transaction. This can only be used right after tx_out. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> tx_out(condition, address, amount)
  |> tx_out_inline_datum(condition, datum)
  |> ...other tx building methods
  |> complete();

mint(
  mocktail_tx: MocktailTx,
  condition: Bool,
  quantity: Int,
  policy_id: ByteArray,
  token_name: ByteArray,
) -> MocktailTx

Tx building method - Add a mint to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> mint(condition, quantity, policy_id, token_name)
  |> ...other tx building methods
  |> complete();

ref_tx_in(
  mocktail_tx: MocktailTx,
  condition: Bool,
  tx_hash: ByteArray,
  tx_index: Int,
  amount: Value,
  address: Address,
) -> MocktailTx

Tx building method - Add a reference input to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ref_tx_in(condition, tx_hash, tx_index, amount, address)
  |> ...other tx building methods
  |> complete();

ref_tx_in_inline_datum(
  mocktail_tx: MocktailTx,
  condition: Bool,
  datum: Data,
) -> MocktailTx

Tx building method - Add an inline datum to last reference input in the transaction. This can only be used right after ref_tx_in. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ref_tx_in(condition, tx_hash, tx_index, amount, address)
  |> ref_tx_in_inline_datum(condition, datum)
  |> ...other tx building methods
  |> complete();

invalid_before(
  mocktail_tx: MocktailTx,
  condition: Bool,
  time: Int,
) -> MocktailTx

Tx building method - Add a a lower bound validity range to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> valid_hereafter(condition, time)
  |> ...other tx building methods
  |> complete();

invalid_hereafter(
  mocktail_tx: MocktailTx,
  condition: Bool,
  time: Int,
) -> MocktailTx

Tx building method - Add a a upper bound validity range to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> valid_hereafter(condition, time)
  |> ...other tx building methods
  |> complete();

required_signer_hash(
  mocktail_tx: MocktailTx,
  condition: Bool,
  key: ByteArray,
) -> MocktailTx

Tx building method - Add a required signer hash to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> required_signer_hash(condition, key)
  |> ...other tx building methods
  |> complete();

script_withdrawal(
  mocktail_tx: MocktailTx,
  condition: Bool,
  script_hash: ByteArray,
  withdrawal_amount: Int,
) -> MocktailTx

Tx building method - Add a script withdrawal to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
 |> script_withdrawal(condition, script_hash, withdrawal_amount)
 |> ...other tx building methods
 |> complete();

complete(mocktail_tx: MocktailTx) -> Transaction

Tx building method - Conclude the transaction building process, and return the built transaction.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete();

add_input(tx: Transaction, condition: Bool, input: Input) -> Transaction

Tx maniputlator - Add an input to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_input(condition, input)
  |> ...other tx maniputlator methods

add_reference_input(
  tx: Transaction,
  condition: Bool,
  input: Input,
) -> Transaction

Tx maniputlator - Add a reference input to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_reference_input(condition, input)
  |> ...other tx maniputlator methods

add_output(tx: Transaction, condition: Bool, output: Output) -> Transaction

Tx maniputlator - Add an output to the transaction. This function will only run when the condition is True.

let t = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_output(condition, output)
  |> ...other tx maniputlator methods

set_fee(tx: Transaction, condition: Bool, lovelace_fee: Int) -> Transaction

Tx maniputlator - Set a fee to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> set_fee(condition, lovelace_fee)
  |> ...other tx maniputlator methods

add_mint(tx: Transaction, condition: Bool, mint: Value) -> Transaction

Tx maniputlator - Add a mint to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_mint(condition, mint)
  |> ...other tx maniputlator methods

add_certificate(
  tx: Transaction,
  condition: Bool,
  certificate: Certificate,
) -> Transaction

Tx maniputlator - Add a certificate to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_certificate(condition, certificate)
  |> ...other tx maniputlator methods

add_withdrawal(
  tx: Transaction,
  condition: Bool,
  withdrawal: Pair<Credential, Int>,
) -> Transaction

Tx maniputlator - Add a withdrawal to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_withdrawal(condition, stake_credential, amount)
  |> ...other tx maniputlator methods

add_extra_signatory(
  tx: Transaction,
  condition: Bool,
  signatory: VerificationKeyHash,
) -> Transaction

Tx maniputlator - Add an extra signatory to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_extra_signatory(condition, signatory)
  |> ...other tx maniputlator methods

add_redeemer(
  tx: Transaction,
  condition: Bool,
  redeemer: Pair<ScriptPurpose, Redeemer>,
) -> Transaction

Tx maniputlator - Add a redeemer to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_redeemer(condition, redeemer)
  |> ...other tx maniputlator methods

add_datum(tx: Transaction, condition: Bool, datum: Data) -> Transaction

Tx maniputlator - Add a datum to the transaction. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> add_datum(condition, datum)
  |> ...other tx maniputlator methods

set_transaction_id(
  tx: Transaction,
  condition: Bool,
  transaction_id: TransactionId,
) -> Transaction

Tx maniputlator - Set the transaction id. This function will only run when the condition is True.

let tx = mocktail_tx()
  |> ...tx building methods
  |> complete()
  |> set_transaction_id(condition, transaction_id)
  |> ...other tx maniputlator methods
Search Document