Api

MultiTest provides three implementations of the Api trait:

Additionally, MockApi, MockApiBech32 and MockApiBech32m implement addr_make method, allowing for convenient creation of user addresses in tests. You can find multiple examples of addr_make method usage in the Addresses chapter. Depending on your needs, you can use any implementation of the Api trait in your tests by utilizing the AppBuilder::with_api method to create a chain simulator.

Api trait

The table below summarizes all methods of the Api trait with short descriptions:

Methods of Api traitDescription
addr_canonicalizeConverts a human-readable address into its canonical binary representation.
addr_humanizeConverts a canonical address into human-readable address.
addr_validateChecks if the human-readable address is valid.
secp256k1_verifyVerifies a message hash against a signature, with the public key of the signer, using the secp256k1 elliptic curve digital signature algorithm.
secp256k1_recover_pubkeyRecovers a public key from a message hash and a signature in compressed form, which can be used in secp256k1_verify directly.
secp256r1_verifyVerifies a message hash against a signature, with the public key of the signer, using the secp256r1 elliptic curve digital signature algorithm.
secp256r1_recover_pubkeyRecovers a public key from a message hash and a signature in compressed form, which can be used in secp256r1_verify directly.
ed25519_verifyVerifies message against a signature, with the public key of the signer, using the ed25519 elliptic curve digital signature algorithm.
ed25519_batch_verifyPerforms batch ed25519 signature verification.
bls12_381_aggregate_g1Adds up points (48 bytes each) of the G1 subgroup on the BLS12-381 curve.
bls12_381_aggregate_g2Adds up points (96 bytes each) of the G2 subgroup on the BLS12-381 curve.
bls12_381_pairing_equalityChecks the pairing equality of the BLS12-381 curve.
bls12_381_hash_to_g1Takes some arbitrary data and hashes it to a point (48 bytes long) on the G1 subgroup of the BLS12-381 curve.
bls12_381_hash_to_g2Takes some arbitrary data and hashes it to a point (96 bytes long) on the G2 subgroup of the BLS12-381 curve.
debugEmits a debugging message.

Api trait implementations

A concise comparison of different Api trait implementations is shown in the table below:

MockApiMockApiBech32MockApiBech32m
Implements Api traitYesYesYes
Implements addr_make functionYesYesYes
Address formatBech32Bech32Bech32m
Default prefix (HRP)cosmwasmNoNo
Supports custom prefixesYesYesYes