In this section, we show how to set up a test suite that uses the keydir backend
to run Contract
s and print reports nicely using Mote.
Important note: Blockfrost-based tests also use the keydir test engine. Thus, if you have already done basic setup for Blockfrost-based tests, you don't have to repeat this setup for keydir-based tests.
Follow the Cardano handbook to generate a private payment key, and optionally, a stake key. You can use this script for convenience instead of following the instructions given in this section.
The generated keys should look like this:
{
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment signing key",
"cborHex": "..."
}
Get the address for this payment key (and, optionally, stake key), following the guide above.
If you are using a testnet, replace the --mainnet
flag in the shell command
with --testnet-magic YOUR_NETWORK_MAGIC
, where YOUR_NETWORK_MAGIC
is a
genesis parameter of the network. For public testnets, you can get this value
from the cardano-configurations
repo. You can find
it in network/YOUR_NETWORK_NAME/genesis/shelley.json
, under the networkMagic
key. Common values are 1 for preprod
, and 2 for preview
.
Fund your address using the testnet faucet. Make sure you're sending funds in the correct network.
Point the test suite to your keys by setting PRIVATE_PAYMENT_KEY_FILE
and
PRIVATE_STAKE_KEY_FILE
to the paths of your .skey
files. If you are using an
enterprise address (without a staking credential component), then do not provide
the staking key file. Whether you use a staking credential component or not does
not affect anything, because the test suite will only use this address to
distribute funds to other, temporary addresses.
During testing, the test engine will move funds around according to the UTxO
distribution specifications provided via Contract.Test.withWallets' calls in the test bodies. This will generate private keys as-needed on the fly: these will be stored in a special directory, to prevent loss of funds in case the test suite suddenly exits. This directory will become the
FilePathargument to
runContractTestsWithKeyDir`.
Each test will generate fresh keys that will be stored in this directory indefinitely. It is up to the user to decide when to delete the corresponding directories. We don't dispose of the keys automatically, as there may be some on-chain state that's uniquely tied to them, which the user might not want to lose access to.
- Blockfrost-powered test suite for an example of how to use key-directory-based test suite with Blockfrost.