This section presents the main technical elements to setup, write and run tests.
Completium CLI provides the
create project command to set up a simple project with contracts and tests.
The command below creates a project named
This creates the
myproject directory with the following structure:
The project comes with a default contract
hello.arl and its test
package.json contains the declaration of required packages. They are installed with:
Note that there are 2 directories of interest:
contractsto store smart contracts (Archetype or Michelson)
teststo store tests (Typescript)
A contract's binding is generated automatically for each contract found in
contracts directory. A binding is a typescript object that reflects the contract interface to interact with it in read/write modes.
The following command generates one binding file per contract (Archetype or Michelson) found in
In the default setup, this generates the file
tests/binding/ directory from
These values are defined in the
"completium" section of the
Modify these values to adapt to your setup.
Bindings need to be generated with the above command everytime the contract interface is modified (storage, entries, views, error messages)
The following command executes tests found in
This executes tests in
00-test-hello.ts file and generates the following output:
test command is defined in
Note that It is possible to create a new rule in the
scripts section to run a specific test file.
The mockup mode must be initialised with the
completium-cli mockup init command for the
test command to run. More information here.
By default, the global Completium CLI configuration (network, account, quiet mode, ...) is used by a test. It is possible to overwrite the configuration with dedicated functions from
set_mockup function set the mockup mode.
Another network (sandbox, test) may be set with the
Calling a contract's entry point require to specify the caller account. An account is declared with Completium CLI (see here for information). An account is referred to with an alias.
get_account function returns a Completium account from its alias.
The mockup mode comes with a set of 8 predefined accounts ready to use for test purposes:
These utility functions are only available in mockup mode.
set_quiet function switchs on or off the quiet mode. When set to
false, the output of the tezos-client (in mockup mode) is displayed with detailed information, like gas consumption and storage diffs.
In the Mocha testing framework, the
describe function is used to group together related tests. It takes two arguments: a string description of the test group, and a callback function that contains the individual tests or further nested
Here is an example of how
describe is used:
it function is used to define a single test case within a
describe block. It takes two arguments: a string description of the test, and a callback function containing the code for the test.
Here is an example of how
it is used:
it are used to structure and organize your tests in Mocha. The
describe function is used to group together related tests, while the
it function is used to define individual test cases.
For example, the following example from
Then the output looks like:
When the call to a contract's entry point is expected to fail, the function
expect_to_fail catches the contract error and compares it to the expected one passed in parameter. It fails if the actual error is different from the expected one, or if the contract does not fail.
expect_to_fail function takes two arguments: a callback function that executes the call to the entry point expected to fail, and the expected error.
For example, consider the following
mint entry point of
The following expects the call to
bob to fail with error
Note that the
errors field of contract's binding interface is the list of possible errors (here