Testmodule is only available inside the
ligo run testcommand. See also Testing LIGO.
A type for code that is compiled to Michelson.
type test_exec_error = ["Rejected", michelson_program, address] | ["Balance_too_low", \u007b contract_too_low : address , contract_balance : tez , spend_request : tez \u007d] | ["Other", string]
A test error:
Rejectedcase means the called contract or its transitive callees (identified by the address in the second constructor argument) failed with some data (first constructor argument)
Balance_too_lowcase means a contract tried to push an operation but did not have enough balance.
contract_too_lowis the address of the contract,
contract_balanceis the actual balance of the contract and
spend_requestis the amount of tez that was required for the operation
Othercase wraps all the other possible reasons. Its argument is a string representation of the tezos_client error
type test_exec_result = ["Success", nat] | ["Fail", test_exec_error]
A test execution result:
Successcase means the transaction went through without an issue. Its argument represent the total amount of gas consumed by the transaction
- The "Fail reason" case means something went wrong. Its argument encode the causes of the failure (see type
type typed_address <'param, 's>
A type for an address of a contract with parameter
'param and storage
let to_contract = (account: typed_address <'param, 'storage>) => contract <'param>
Get the contract corresponding to the default entrypoint of a typed
address: the contract parameter in the result will be the type of the
default entrypoint (generally
'param, but this might differ if
'param includes a "default" entrypoint).
let to_entrypoint = (entrypoint: string, account: typed_address <'param, 'storage>) => contract <'e>
Get the contract corresponding to an entrypoint of a typed address: the contract parameter in the result will be the type of the entrypoint, it needs to be annotated, entrypoint string should omit the prefix "%".
let originate_from_file = (filepath: string, entrypoint: string, views: list<string>, init: michelson_program, balance: tez) => [address, michelson_program, int]
Originate a contract with a path to the contract file, an entrypoint, an initial storage and an initial balance.
let originate = (contract: ('param, 'storage) => (list <operation>, 'storage), init: 'storage, balance: tez) => [typed_address <'param, 'storage>, michelson_program, int]
Originate a contract with an entrypoint function, initial storage and initial balance.
Set the source for `Test.transfer` and `Test.originate`.let set_source = (source: address) => unit
Force the baker for `Test.transfer` and `Test.originate`. By default, the first bootstrapped account.let set_baker = (source: address) => unit
Bake a transaction by sending an amount of tez with a parameter from the current source to another account. Returns the amount of gas consumed by the execution of the contract.let transfer = (addr: address, param: michelson_program, amount: tez) => test_exec_result
Similar as `Test.transfer`, but fails when anything goes wrong.let transfer_exn = (addr: address, parameter: michelson_program, amount: tez) => nat
Bake a transaction by sending an amount of tez with a parameter from the current source to a contract. Returns the amount of gas consumed by the execution of the contract.let transfer_to_contract = (addr: contract<'p>, param: 'p, amount: tez) => test_exec_result
Similar as `Test.transfer_to_contract`, but fails when anything goes wrong.let transfer_to_contract_exn = (addr: contract<'p>, parameter: 'p, amount: tez) => nat
Get the storage of an account in `michelson_program`.let get_storage_of_address = (account: address) => michelson_program
Get the storage of a typed account.let get_storage = (account: typed_address <'p, 's>) => 's
Get the balance of an account in tez.let get_balance = (account: address) => tez
Return the voting power of a given contract. This voting power coincides with the weight of the contract in the voting listings (i.e., the rolls count) which is calculated at the beginning of every voting period.let get_voting_power = (kh: key_hash) => nat
Return the total voting power of all contracts. The total voting power coincides with the sum of the rolls count of every contract in the voting listings. The voting listings is calculated at the beginning of every voting period.let get_total_voting_power = nat
Compare two Michelson values.let michelson_equal = (a: michelson_program, b: michelson_program) => bool
Log a value.let log = (a: 'a) => unit
Generate a number of random bootstrapped accounts with a default amount of 4000000 tez. The passed list can be used to overwrite the amount. By default, the state only has two bootstrapped accounts.let reset_state = (no_of_accounts: nat, amount: list<tez>) => unit
Notice that since Ithaca, a percentage of an account's balance is
frozen (5% in testing mode) in case the account can be taken to be a
Test.get_balance can show a different amount to the one
being set with
Adds an account `(sk, pk)` as a baker. The change is only effective after `Test.reset_state`.let baker_account = ([string, key], amount : option<tez>) => unit
Registers a `key_hash` corresponding to an account as a delegate.let register_delegate = (account : key_hash) => unit
Registers a global constant `constant`, returns its hash as a string.let register_constant = (constant : michelson_program) => string
See the documentation for global constants for an example of usage.
Turn a constant (as a string) into a `michelson_program`. To be used together with `Test.register_constant`.let constant_to_michelson_program = (constant : string) => michelson_program
Registers the global constants listed in a JSON file. It takes a string (file path) and returns a list of strings corresponding to the hashes of the registered constants.let register_file_constants = (filepath : string) => list<string>
It bakes until a number of cycles pass, so that an account registered as delegate can effectively act as a baker.let bake_until_n_cycle_end = (cycles : nat) => unit
Creates and returns secret key & public key of a new account.let new_account = (_: unit) => (string, key)
Adds an account specfied by secret key & public key to the test contextlet add_account = (sk: string, pk: key) => unit
Returns the address of the nth bootstrapped account.let nth_bootstrap_account = (nth: int) => address
Returns the address corresponding to the nth bootstrapped contract.let nth_bootstrap_contract = (nth: nat) => address
let bootstrap_contract = (balance: tez, contract: ('param, 'storage) => (list <operation>, 'storage), init: 'storage) => unit
Setup a bootstrap contract with an entrypoint function, initial storage and initial balance. Bootstrap contracts will be loaded in order, and they will be available only after reset.
Returns the typed address corresponding to the nth bootstrapped contract currently loaded. The types are inferred from those contracts loaded with `Test.bootstrap_contract` (before reset).let nth_bootstrap_typed_address = (nth: int) => typed_address <'p, 's>
Returns addresses of orginated accounts in the last transfer. It is given in the form of a map binding the address of the source of the origination operation to the addresses of newly originated accounts.let last_originations = (_: unit) => map<address , address list>
Compile a LIGO value to Michelson.let compile_value = (value: 'a) => michelson_program
Compile a LIGO value to Michelson. Currently it is a renaming of `compile_value`.let eval = (value: 'a) => michelson_program
let run = (func: ('a => 'b), value: 'a) => michelson_program
Run a function on an input, all in Michelson. More concretely: a)
compiles the function argument to Michelson
f_mich; b) compiles the
value argument (which was evaluated already) to Michelson
runs the Michelson interpreter on the code
f_mich with starting
[ v_mich ].
Decompile a Michelson value to LIGO, following the (mandatory) type annotation. Note: this operation can fail at run-time, in case that the `michelson_program` given cannot be decompiled to something compatible with the annotated type.let decompile = (value: michelson_program) => 'a
let mutate_value : (index: nat, value: 'a) => option <['a, mutation]>
Mutates a value using a natural number as an index for the available mutations, returns an option for indicating whether mutation was successful or not.
let mutation_test : (value: 'a, tester: ('a -> 'b)) => option <['b, mutation]>
Given a value to mutate (first argument), it will try all the mutations available of it, passing each one to the function (second argument). On the first case of non failure when running the function on a mutation, the value and mutation involved will be returned.
let mutation_test_all : (value: 'a, tester: ('a -> 'b)) => list <['b, mutation]>
Given a value to mutate (first argument), it will try all the mutations of it, passing each one to the function (second argument). In case no failure arises when running the function on a mutation, the failure and mutation involved will be added to the list to be returned.
let save_mutation : (path: string, mutation: mutation) => option <string>
This function reconstructs a file from a mutation (second argument),
and saves it to a file in the directory path (first argument). It
returns an optional string indicating the filename where the mutation
was saved, or
None if there was an error.
let random : (u: unit) => 'a
This function creates a random value for a chosen type.
let cast_address : (addr: adress) => typed_address <'param, 'storage>
This function casts an address to a typed address. You will need to annotate the result with the type you expect.
let set_big_map: (id: 'int, big_map: big_map<'key, 'value>) => unit
The testing framework keeps an internal reference to the values corresponding to big map identifiers. This function allows to override the value of a particular big map identifier. It should not be normally needed, except in particular circumstances such as using custom bootstrap contracts that initialize big maps.
let create_chest : bytes => nat => [chest , chest_key]
Generate a locked value, the RSA parameters and encrypt the payload. Also returns the chest key Exposes tezos timelock library function create_chest_and_chest_key
let create_chest_key : chest => nat => chest_key
Unlock the value and create the time-lock proof. Exposes tezos timelock library function create_chest_key.