Extensions

Warning: the following instructions can only be used in contracts, not testcases:

  • SENDER
  • SOURCE

Techelson testcases have access to an extended instruction set to ease the process of writing tests. See rsc/tests/ for more examples. Note that techelson treats #> as whitespace, so you can use extensions in contracts (when legal) while keeping them pure michelson, like in the example below

DIP {
    ...
    CONS ;
    #> PRINT_STACK ;
    #> STEP "after list cons" ;
    PUSH int 3 ;
    ...
}

Unrestricted Extensions

The following instructions are legal in testcases and contracts:

  • STEP and STEP <string>:

    'S -> 'S

    Since 0.7.0, relevant section of this book: First Steps.

    suspends the evaluator and prints a string, if any.

  • PRINT_STACK:

    'S -> 'S

    Since 0.7.0, relevant section of this book: First Steps.

    prints the current state of the stack

Note that Techelson treats #> as whitespaces. You can have #> STEP "important step" ; in your contracts which keeps them pure Michelson, but Techelson will stop when it reaches the STEP.

Testcase-only Extensions

The following instructions are only legal in testcases:

  • CREATE_CONTRACT <string>:

    :: key_hash : option key_hash : bool : bool : mutez : 'g : 'S -> operation : address : 'S

    Since 0.7.0, relevant section of this book: Creating and Calling Contracts.

    Creates an instance of the contract named after the string parameter. The type of the storage of the contract must be 'g.

  • SPAWN_CONTRACT 'g:

    :: string : key_hash : option key_hash : bool : bool : mutez : 'g : 'S -> operation : address : 'S

    Since 0.7.0, relevant section of this book: Creating and Calling Contracts.

    Exactly the same as the CREATE_CONTRACT extension above but the name of the contract is passed as a stack parameter, and the type of the storage is an explicit parameter of the instruction.

  • APPLY_OPERATIONS:

    (list operation) : 'S -> 'S

    Since 0.7.0, relevant section of this book: Creating and Calling Contracts.

    • consumes a list of operations
    • suspends the execution of the testcase
    • applies all the operations in the list (these operations can create operations which will be applied too)
    • resumes the execution of the testcase
  • GET_STORAGE 'storage:

    contract _ : 'S -> (option 'storage) : 'S

    address : 'S -> (option 'storage) : 'S

    Since 0.7.0, relevant section of this book: Live Contract Inspection.

    • consumes a contract
    • pushes Some of the current value of the storage of the contract if its storage has type 'storage, None otherwise
  • GET_BALANCE:

    contract _ : 'S -> mutez : 'S

    address : 'S -> mutez : 'S

    Since 0.7.0, relevant section of this book: Live Contract Inspection.

    Same as GET_STORAGE, but pushes the balance of the contract instead of its storage

  • MUST_FAIL 'a:

    (option 'a) : operation : 'S -> 'S

    Since 0.7.0, relevant section of this book: Testing for Failures.

    Specifies that an operation (or the operation it creates recursively) must fail, and optionaly that it FAILedWITH a certain value. More precisely, the whole testcase will fail if the operation or the operations it creates recursively, when applied, either

    • succeeds, or
    • the (option 'a) parameter is (Some value) and the operation's failure was not caused by a FAILWITH on precisely value

    Note that if the optional value is NONE, then MUST_FAIL accepts any kind of protocol failure, not just FAILWITH. For instance, it will also accept creation/transfer operations that fail because of insufficient balance, because this precise operation already ran (it was DUP-ed), etc.

  • SET_SOURCE code, with code :: [ 'A -> 'B ]

    address :: 'A -> 'B

    Since 0.7.0, relevant section of this book: Usurpation of Identity.

    Sets the source of the testcase. Without this extension, the source of all transfers can only be the testcase. This allows to run code while pretending the testcase is a different live contract.

  • SET_TIMESTAMP

    timestamp :: 'S -> 'S

    Since 0.7.0, relevant section of this book: Timestamp Control.

    Sets the timestamp of the next block to some value. The default timestamp is 1970-01-01T00:00:00Z.