Transfers
At this point creating and applying a transfer should be relatively straightforward. Simply create
the operation using michelson's TRANSFER_TOKENS
, and apply it with APPLY_OPERATIONS
. For
instance, transfer.techel builds on inspection.techel. It creates an instance of
simpleExample.tz, and creates and applies two operations: the first transfers 7
tokens with a
parameter equal to False
, and the second transfers 13
tokens with True
. (Remember that
simpleExample.tz will count transfers for which the parameter is False
.)
{
PUSH @storage nat 0 ;
PUSH @amount mutez 3 ;
PUSH @delegatable bool True ;
PUSH @spendable bool True ;
NONE @delegate key_hash ;
PUSH key "manager address" ;
SHA512 @manager ;
CREATE_CONTRACT @main @main_op "SimpleExample" ;
... # Omitting code creating the contract.
{ # Making a non-ghost transfer.
DUP ;
PUSH @amount mutez 7 ;
PUSH @ghost bool False ;
TRANSFER_TOKENS ;
} ;
DIP { # Making a ghost transfer.
DUP ;
PUSH @amount mutez 13 ;
PUSH @ghost bool True ;
TRANSFER_TOKENS ;
} ;
{ # Creating the list of all operations.
DIP { DIP {NIL operation } ; CONS } ;
CONS ;
} ;
APPLY_OPERATIONS ;
Finally, it checks that the balance and storage are the ones expected:
GET_BALANCE ;
PRINT_STACK ;
STEP "retrieved the balance of the contract" ;
PUSH mutez 23 ;
IFCMPNEQ {
PUSH string "balance should be 23utz" ;
FAILWITH
} {} ;
GET_STORAGE nat ;
IF_NONE {
PUSH string "unable to retrieve storage of contract" ;
FAILWITH
} {
PRINT_STACK ;
STEP "retrieved the storage of the contract" ;
PUSH nat 1 ;
IFCMPNEQ {
PUSH string "storage should be 1 (nat)" ;
FAILWITH
} {} ;
}
}
The test passes and its output is
$ techelson --contract rsc/simpleExample/contracts/simpleExample.tz -- rsc/simpleExample/okay/transfer.techel
Running test `Transfer`
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
applying operation CREATE[uid:0] (@address[1]@main, "sha512:manager address", None, true, true, 3utz) "SimpleExample"
timestamp: 1970-01-01 00:00:00 +00:00
live contracts: none
=> live contracts: SimpleExample (3utz) address[1]@main
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
applying operation TRANSFER[uid:1] address[0]@Transfer -> address[1]@main 7utz False
timestamp: 1970-01-01 00:00:00 +00:00
live contracts: SimpleExample (3utz) address[1]@main
running TRANSFER[uid:1] address[0]@Transfer -> address[1]@main 7utz False
timestamp: 1970-01-01 00:00:00 +00:00
=> live contracts: SimpleExample (10utz) address[1]@main
applying operation TRANSFER[uid:2] address[0]@Transfer -> address[1]@main 13utz True
timestamp: 1970-01-01 00:00:00 +00:00
live contracts: SimpleExample (10utz) address[1]@main
running TRANSFER[uid:2] address[0]@Transfer -> address[1]@main 13utz True
timestamp: 1970-01-01 00:00:00 +00:00
=> live contracts: SimpleExample (23utz) address[1]@main
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
stack:
|==================================================================================================|
| address[1]@main |
| (contract bool) |
|--------------------------------------------------------------------------------------------------|
| 23utz |
| mutez |
|==================================================================================================|
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
stopping [retrieved the balance of the contract] press `return` to continue
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
stack:
|==================================================================================================|
| 1p |
| nat |
|==================================================================================================|
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
stopping [retrieved the storage of the contract] press `return` to continue
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
Done running test `Transfer`