Anonymous Contracts
Techelson accepts contracts through its --contract
option. These contracts are named as discussed
in Creating and Calling Contracts. Contracts defined at michelson level in testcases and
contracts however are considered anonymous. Anonymous contracts can also be deployed and
inspected. In fact, they are not really different from named contracts apart from their lack of
name, which (currently) prevent techelson from mentioning where they really come from in its debug
output.
The following anonymous.techel testcase is similar to the one from the Live Contract Inspection except that the contract deployed is not given to the environment, it is inlined in the testcase.
{
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 {
storage nat;
parameter bool;
code {
UNPAIR ;
IF {
} {
PUSH nat 1;
ADD
} ;
NIL operation ;
PAIR
};
} ;
DIP { NIL operation } ;
CONS ;
APPLY_OPERATIONS ;
# Takes the address on the top of the stack, retrieves a contract of parameter `bool`.
CONTRACT bool ;
IF_NONE { # There is no hope, failing.
PUSH @err_msg string "failed to retrieve contract" ;
FAILWITH
} {} ;
DUP ;
GET_BALANCE ;
PRINT_STACK ;
STEP "retrieved the balance of the contract" ;
PUSH mutez 3 ;
IFCMPNEQ {
PUSH string "balance should be 3utz" ;
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 0 ;
IFCMPNEQ {
PUSH string "storage should be 0 (nat)" ;
FAILWITH
} {} ;
}
}
This produces the exact same output (modulo the testcase's name, and as long as we do not increase verbosity) as for inspection.techel:
$ techelson rsc/no_contract/okay/anonymous.techel
Running test `Anonymous`
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)
{
storage nat ;
parameter bool ;
code ...;
}
timestamp: 1970-01-01 00:00:00 +00:00
live contracts: none
=> live contracts: <anonymous> (3utz) address[1]@main
running test script...
timestamp: 1970-01-01 00:00:00 +00:00
stack:
|==================================================================================================|
| address[1]@main |
| (contract bool) |
|--------------------------------------------------------------------------------------------------|
| 3utz |
| 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:
|==================================================================================================|
| 0p |
| 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 `Anonymous`