Flags โ
Several aspects of scenarios and the compilation of contracts can be controlled by the use of flags.
SmartPy supports two sorts of flags:
Boolean Flags โ
Flag | Description | Default Value |
---|---|---|
contract-check-exception | Fail in the interpreter when sp.contract(...) evaluates to none. | True |
view-check-exception | Fail in the interpreter when sp.view(...) evaluates to none. | True |
disable-dup-check | Remove the DUP protection on tickets | False |
dump-michel | Dump Michel intermediate language | False |
erase-comments | Remove compiler comments | False |
erase-var-annots | Remove annotations (with RENAME) after SENDER , BALANCE , etc | False |
initial-cast | Add an initial CAST to remove annotations first in the compiler | False |
pairn | Use PAIR n instruction | True |
simplify | Allow simplification after compilation | True |
simplify-via-michel | Use Michel intermediate language | False |
single-entrypoint-annotation | Emit parameter annotations for single entrypoint contracts | True |
stop-on-error | Scenarios stop on first error | True |
warn-unused | Exceptions for unused entrypoint parameters | True |
decompile | Decompile after compilation (for test purposes) | False |
default-check-no-incoming-transfer | Default value for check-no-incoming-transfer parameter in entrypoints. | False |
Flags with arguments โ
Flag | Description | Options | Default Value |
---|---|---|---|
protocol | Protocol used in the scenario | jakarta , kathmandu , lima | lima |
lazy-entrypoints | Use big maps to store entrypoints | none , single , multiple | none |
exceptions | Control exception generation in the compiler | full-debug , debug-message , verify-or-line , default-line , line , default-unit , unit . See Exception Optimization Levels | verify-or-line |
default_variant_layout | Select default layout for variants | tree , comb | tree |
default_record_layout | Select default layout for records | tree , comb | tree |
Adding flags to a contract โ
Add a flag where flag is a string constant and args are potential arguments.
Boolean flag โ
py
class MyContract(sp.Contract):
def __init__(self, **kargs):
self.init(**kargs)
# Enable flag
self.add_flag("erase-comments")
# Or disable flag
self.add_flag("no-erase-comments")
Flag with arguments โ
py
class MyContract(sp.Contract):
def __init__(self, **kargs):
self.init(**kargs)
self.add_flag("exceptions", "unit")
Adding flags to a scenario โ
Same as in Adding flags to a contract, but instead provided in a test scenario.
py
@sp.add_test(name = "FlagExample")
def test():
scenario = sp.test_scenario()
scenario.add_flag("protocol", "edo")
Exception Optimization Levels โ
Defines the default exception behavior when FAILWITH instructions get called.
See reference Exception Optimization template.
The different levels are:
Level | Description |
---|---|
full-debug | This is extremely costly in terms of size and gas. Useful for debugging purposes. Type of failure, line number, some parameters |
debug-message | This is still very costly in terms of size and gas |
verify-or-line (default) | Puts messages for verify and failwith . Uses line numbers for other failures. |
default-line | Puts messages for verify with custom messages and failwith . Uses line numbers for other failures. |
line | Only puts line numbers everywhere |
default-unit | Puts messages for verify with custom messages, and failwith . Uses unit for other failures. |
unit | Always puts unit |
Configuration Example
py
class MyContract(sp.Contract):
def __init__(self, **kargs):
self.init(**kargs)
# Enable flag
self.add_flag("exceptions", "full-debug")