Version: 0.19.0

Test

Important: The Test module is only available inside the ligo test command. See also Testing LIGO.

type michelson_program
A type for code that's compiled to Michelson.
type ligo_program
A type for code insertions in the test file.
type test_exec_error = ["Rejected", michelson_program, address] | ["Other"]
A test error.
type test_exec_result = ["Success"] | ["Fail", test_exec_error]
A test execution result.
type typed_address <'p, 's>
A type for an address of a contract with parameter `'p` and storage `'s`.
let to_contract = (account: typed_address <'p, 's>) => contract <'p>

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 'p, but this might differ if 'p includes a "default" entrypoint).

let to_entrypoint = (entrypoint: string, account: typed_address <'p, 's>) => 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, init: michelson_program, balance: tez) => [address, michelson_program, int]

Originate a contract with an entrypoint, initial storage and initial balance.

let [addr, program, size] = Test.originate_from_file(testme_test,"main", init_storage, 0 as tez);
let originate = (contract: ('parameter, 'storage) => (list <operation>, 'storage), init: 'storage, balance: tez) => [typed_address <'parameter, 'storage>, michelson_program, int]

Originate a contract with an entrypoint function, initial storage and initial balance.

let set_now = (now: timestamp) => unit
Set the timestamp of the predecessor block.
let set_source = (source: address) => unit
Set the source for `Test.transfer` and `Test.originate`.
let set_baker = (source: address) => unit
Force the baker for `Test.transfer` and `Test.originate`. By default, the first bootstrapped account.
let transfer = (addr: address, parameter: michelson_program, amount: tez) => test_exec_result
Bake a transaction by sending an amount of tez with a parameter from the current source to another account.
let transfer_exn = (addr: address, parameter: michelson_program, amount: tez) => unit
Similar as `Test.transfer`, but fails when anything goes wrong.
let transfer_to_contract = (addr: contract<'p>, parameter: '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.
let transfer_to_contract_exn = (addr: contract<'p>, parameter: 'p, amount: tez) => unit
Similar as `Test.transfer_to_contract`, but fails when anything goes wrong.
let get_storage_of_address = (account: address) => michelson_program
Get the storage of an account in `michelson_program`.
let get_storage = (account: typed_address <'p, 's>) => 's
Get the storage of a typed account.
let get_balance = (account: address) => tez
Get the balance of an account in tez.
let michelson_equal = (a: michelson_program, b: michelson_program) => bool
Compare two Michelson values.
let log = (a: 'a) => unit
Log a value.
let reset_state = (no_of_accounts: nat, amount: list<nat>) => 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 nth_bootstrap_account = (nth: int) => address
Returns the address of the nth bootstrapped account.
let last_originations = (_: unit) => map<address , address list>
Returns the address of the nth bootstrapped account.
let compile_expression = (filepath: option<string>, code: ligo_program) => michelson_program
Compile an expression to Michelson and evaluate it.
let expr = Test.compile_expression(Some("filename"), jsligo`42 as int` as ligo_program);
let compile_expression_subst = (filepath: option<string>, code: ligo_program, subst_list: list<[string, michelson_program]>]) => michelson_program
let example = Test.compile_expression_subst (Some (under_test),
jsligo`{one: $one, two: $two, three: $three, four: $four, five: $five}` as ligo_program,
list([
["one", d_one],
["two", Test.compile_value ((1 as nat) + (2 as nat))] ,
["three", Test.compile_value ("a" + "b")] ,
["four", Test.compile_value (0xFF00)],
["five", Test.compile_value ()]
]));
let compile_value = (value: 'a) => michelson_program
Compile a LIGO value to Michelson.
let eval = (value: 'a) => michelson_program
Compile a LIGO value to Michelson. Currently it is a renaming of `compile_value`.
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 v_mich; c) runs the Michelson interpreter on the code f_mich with starting stack [ v_mich ].