Example
Let's showcase testgeneration on simpleExample.tz:
storage nat;
parameter bool;
code {
UNPAIR; # Unpair parameter and storage.
IF { # Asked not to count: storage is unchanged, nothing to do.
} {
PUSH nat 1;
ADD
};
NIL operation; # We don't want to perform any operations.
PAIR # Aggregate the operation list and the new storage.
};
Test generation is activated by passing to techelson a testgen
argument triggering the test
generation mode. You can read more about modes in the Usage section. First, let's generate a
single testcase (-n 1
, or --count 1
) and let techelson run it:
$ techelson --contract rsc/simpleExample/contracts/simpleExample.tz testgen -n 1
done generating test for contract SimpleExample
Running test `SimpleExampleTest1`
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
applying operation CREATE[uid:0] (@address[1], "blake2b:11a6ffbc9fb85", None, false, false, 638557938255190utz) "SimpleExample"
timestamp: 1970-01-01 00:00:00 +00:00
live contracts: none
=> live contracts: SimpleExample (638557938255190utz) address[1]
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
applying operation TRANSFER[uid:1] address[0]@SimpleExampleTest1 -> address[1] 120584798270008utz True
timestamp: 1970-01-01 00:00:00 +00:00
live contracts: SimpleExample (638557938255190utz) address[1]
running TRANSFER[uid:1] address[0]@SimpleExampleTest1 -> address[1] 120584798270008utz True
timestamp: 1970-01-01 00:00:00 +00:00
=> live contracts: SimpleExample (759142736525198utz) address[1]
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
Done running test `SimpleExampleTest1`
While this can be useful for simple contracts, usually you want to retrieve the testcase directly
so that you can modify it to suit your needs. So let's still generate one testcase but this time we
will dump it in the current directory (trailing .
in the techelson
command).
$ techelson --contract rsc/simpleExample/contracts/simpleExample.tz testgen -n 1 . ; echo ; echo "testcase:" ; echo ; cat SimpleExampleTest1.techel ; rm SimpleExampleTest1.techel
done generating test for contract SimpleExample
dumping testcases to `.`
testcase:
{
# deploying contract `SimpleExample`
{
# creating contract creation parameters
{
# creating storage for contract `SimpleExample`
PUSH nat 807338681362247 ;
# money transferred
PUSH mutez 638557938255190 ;
# delegatable
PUSH bool False ;
# spendable
PUSH bool False ;
# delegate
NONE key_hash ;
# manager
{
PUSH key "11a6ffbc9fb85" ;
BLAKE2B
}
} ;
CREATE_CONTRACT "SimpleExample"
} ;
# create a list of operations and apply
{
NIL operation ;
SWAP ;
CONS ;
APPLY_OPERATIONS
} ;
# create transfer operation
{
DUP ;
# retrieve contract from address, fail if none
{
CONTRACT bool ;
IF_NONE {
PUSH string "unable to spawn contract `SimpleExample`" ;
FAILWITH
}
{}
} ;
PUSH mutez 120584798270008 ;
PUSH bool True ;
TRANSFER_TOKENS
} ;
# create a list of operations and apply
{
NIL operation ;
SWAP ;
CONS ;
APPLY_OPERATIONS
}
}