Skip to main content
Version: 1.3.0

Test.Next

Note: This module/namespace exists inside the Test module/namespace.
To use this experimental lib :

import Test = Test.Next

By default functions from module Typed_address are accessible at this top-level. Also the function Originate.contract can be accessed directly as originate.

Module Mutation

const func<a, b> : (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.

Former Test.mutation_test.

const from_file<b> : (filepath: string, entrypoint: string, views: list<string>, init: michelson_program, balance: tez, (tester: (originated_address: address, code: michelson_contract, size: int) => b)) => option<[b, mutation]>

Given a contract from a file (passed by filepath, entrypoint and views), an initial storage and balance, it will originate mutants of the contract and pass the result to the function (last argument). On the first case of non failure when running the function on a mutation, the value and mutation involved will be returned.

Former Test.originate_from_file_and_mutate.

const contract<p, s, b> : (contract: module_contract<p, s>, init: s, balance: tez, (tester: (originated_address: typed_address<p, s>, code: michelson_contract, size: int) => b)) => option<[b, mutation]>

Given a contract as a module/namespace, an initial storage and balance, it will originate mutants of the contract and pass the result to the function (last argument). On the first case of non failure when running the function on a mutation, the value and mutation involved will be returned.

Former Test.originate_module_and_mutate.

const value<a> : (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.

Former Test.mutate_value.

let save : (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.

Former Test.save_mutation.

Sub-module All

let func<a, b> : (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.

Former Test.mutation_test_all.

let from_file<b> : (filepath: string, entrypoint: string, views: list<string>, init: michelson_program, balance: tez, (tester: (originated_address: address, code: michelson_contract, size: int) => b)) => list<[b, mutation]>

Given a contract from a file (passed by filepath, entrypoint and views), an initial storage and balance, it will originate mutants of the contract and pass the result to the function (last 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.

Former Test.originate_from_file_and_mutate_all.

let contract<s, p, b> : (contract: module_contract<p, s>, init: s, balance: tez, (tester: (originated_address: typed_address<p, s>, code: michelson_contract, size: int) => b)) => list<[b, mutation]>

Given a contract as a module/namespace, an initial storage and balance, it will originate mutants of the contract and pass the result to the function (last 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.

Former Test.originate_module_and_mutate_all.

Module State

let save: (u: unit) => unit

Takes current testing framework context and saves it, pushing it into a stack of contexts.

Former Test.save_context.

let restore: (u: unit) => unit

Pops a testing framework context from the stack of contexts, and sets it up as the new current context. In case the stack was empty, the current context is kept.

Former Test.restore_context.

let drop: (u: unit) => unit

Drops a testing framework context from the stack of contexts. In case the stack was empty, nothing is done.

Former Test.drop_context.

let reset = (no_of_accounts: nat, amount: list<tez>) => 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.

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 validator (see here), and thus Test.get_balance can show a different amount to the one being set with Test.reset_state.

Former Test.reset_state.

let reset_at = (initial_timestamp : timestamp, no_of_accounts: nat, amount: list<tez>) => unit

Same as reset but accepts a timestamp which is set as the initial timestamp of the genesis block.

Former Test.reset_state_at.

let register_delegate = (account : key_hash) => unit

Registers a key_hash corresponding to an account as a delegate.

Former Test.register_delegate.

let register_constant = (constant : michelson_program) => string

Registers a global constant constant, returns its hash as a string.

See the documentation for global constants for an example of usage.

Former Test.register_constant.

Module Account

let alice = (_: unit) => address

let bob = (_: unit) => address

let carol = (_: unit) => address

let dan = (_: unit) => address

Returns the address of the bootstrapped accounts: number 0 for alice, 1 for bob, 2 for carol and 3 for dan.

type info = { addr : address , pk : key , sk : string }

A type representing the data corresponding to an account.

let info = (nth: nat) => info

Returns the address, key and secret key of the nth bootstrapped account.

let add = (sk: string, pk: key) => unit

Adds an account specfied by secret key & public key to the test context.

Former Test.add_account.

let address = (nth: nat) => address

Returns the address of the nth bootstrapped account.

Former Test.nth_bootstrap_account (but takes a nat instead of an int).

Module Compare

This module is used for comparison of values. It is different from regular comparison operators as these are expected to be more general: things which are not comparable on Michelson can still be compared with this primitive (in the context of the testing framework).

const eq<a> : (l: a, r: a) => bool

Former Test.equal.

const neq<a> : (l: a, r: a) => bool

Former Test.not_equal.

const gt<a> : (l: a, r: a) => bool

Former Test.greater.

const lt<a> : (l: a, r: a) => bool

Former Test.less.

const ge<a> : (l: a, r: a) => bool

Former Test.greater_or_equal.

const le<a> : (l: a, r: a) => bool

Former Test.less_or_equal.

Module Michelson

const run<a, b> : (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 v_mich; c) runs the Michelson interpreter on the code f_mich with starting stack [v_mich].

Former Test.run.

const eval<a> : (value: a) => michelson_program

Compile a LIGO value to Michelson. Currently it is a renaming of `compile_value`.

Former Test.eval.

const decompile<a> : (value: michelson_program) => a

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.

Former Test.decompile.

const parse : (constant : string) => michelson_program

Parses Michelson (as string) into a michelson_program.

Sub-module Contract

const compile<p, s> : (contract: (p, s) => (list <operation>, s)) => michelson_contract

Compiles a contract from an entrypoint function.

Former Test.compile_contract.

const size : (contract: michelson_contract) => int

Measure the size of a contract.

Former Test.size.

const from_file : (filepath: string, entrypoint: string, views: list<string>) => michelson_contract

Compiles a contract with a path to the contract file, an entrypoint, and a list of views.

Former Test.compile_contract_from_file.

Module IO

const print : (s: string) => unit

Prints an string to stdout.

Former Test.print.

const println : (s: string) => unit

Prints an string to stdout, ended with a newline.

Former Test.println.

const eprint : (s: string) => unit

Prints an string to stderr.

Former Test.eprint.

const log<a> : (a: a) => unit

Log a value.

Former Test.log.

const set_test_print : (u: unit) => unit

Turns on the printing of test prefixed values at the end of tests. This is the default behaviour.

Former Test.set_print_values.

const unset_test_print : (u: unit) => unit

Turns off the printing of test prefixed values at the end of tests.

Former Test.unset_print_values.

Module Assert

const assert: (condition: bool) => unit

Check if a certain condition has been met. If not the testing framework will fail.

Former Test.assert.

const some<a>: (v: option<a>) => unit

Check if an option value is Some. If not the testing framework will fail.

Former Test.some.

const none<a>: (v: option<a>) => unit

Check if an option value is None. If not the testing framework will fail.

Former Test.none.

Sub-module Error

const assert: (condition: bool, message: string) => unit

Check if a certain condition has been met. If not the testing framework will fail with the string passed as message.

Former Test.assert_with_error.

const some<a>: (v: option<a>, message: string) => unit

Check if an option value is Some. If not the testing framework will fail with the string passed as message.

Former Test.some_with_error.

const none<a>: (v: option<a>, message: string) => unit

Check if an option value is None. If not the testing framework will fail with the string passed as message.

Former Test.none_with_error.

Module String

const chr : (c: nat) => option<string>

String consisting of the character represented by a nat in the interval [0, 255].

Former Test.chr.

const nl : string

String consisting of only a newline.

Former Test.nl.

const show<a> = (a: a) => string

Convert a value to a string (same conversion as used by log).

Former Test.to_string.

const json<a> = (a: a) => string

Convert a value to its JSON representation (as a string). A JSON schema is available here.

Former Test.to_json.

Module Ticket

This module only contains the following sub-module.

Sub-module Proxy

This module is the same as the former Test.Proxy_ticket module.

Module Originate

type origination_result<p, s> = { taddr : typed_address<p, s> , code : michelson_contract<p, s> , size : int }

A type representing the data corresponding to the origination of a contract.

const contract<p, s> : (contract: module_contract<p, s>, init: s, balance: tez) => origination_result<p, s>

Originate a contract from a module/namespace. To obtain a module_contract from a module, use the contract_of keyword.

Former Test.originate_module.

const from_file<p, s> : (filepath: string, init: s, balance: tez) => origination_result<p, s>

Originate a contract with a path to the contract file, together with an initial storage and an initial balance.

Former Test.originate_from_file.

Module Contract

const transfer<p> : (addr: contract<p>, param: p, amount: tez) => test_exec_result

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.

Former Test.transfer_to_contract.

const transfer_exn<p> : (addr: contract<p>, parameter: p, amount: tez) => nat

Similar as transfer, but fails when anything goes wrong.

Former Test.transfer_to_contract_exn.

Module Typed_address

const transfer<p, s> : (addr: typed_address<p, s>, param: p, amount: tez) => test_exec_result

Bake a transaction by sending an amount of tez with a parameter from the current source to a contract given as typed_address. Returns the amount of gas consumed by the execution of the contract.

Former Test.transfer.

const transfer_exn<p, s> : (addr: typed_address<p, s>, parameter: p, amount: tez) => nat

Similar as transfer, but fails when anything goes wrong.

Former Test.transfer_exn.

const get_storage<p, s> : (account: typed_address<p, s>) => s

Get the storage of a typed address.

Former Test.get_storage.

Module Address

const get_balance : (account: address) => tez

Get the balance of an account in tez.

Former Test.get_balance.

const to_typed_address<p, s> : (addr: adress) => typed_address<p, s>

This function casts an address to a typed address. You will need to annotate the result with the type you expect.

Former Test.cast_address.