New Release for SmartPy and SmartPy.io: Open Source Version and Syntax, Testing, and Michelson Compiler Improvements
It is our great pleasure to announce the first open source release of SmartPy and SmartPy.io.
Open Source Release
This release is our first Open Source version. It uses an MIT license.
It is available here: https://gitlab.com/SmartPy/smartpy.
In 2019, the development has been very active in a private repository that is expected to remain active while the gitlab repository https://gitlab.com/SmartPy/smartpy will be used to interact with the community.
We expect to make regular releases and fully transition to the public repository sometime this year.
Change of Syntax
This release contains some important changes.
First, we are switching SmartPy commands to snake case for readability and coherence with both Python and Michelson. For example
sp.entryPoint is now called
There is an automated translation tool for this part in SmartPy.io that is triggered automatically when evaluating a script.
Second, we listened to our users and a point of misunderstanding and bugs was related to the syntax of local variables. We changed the syntax and, here, the translation tool cannot work so please expect some work for this part.
sp.local(this is done automatically)
locis a local variables, its value is set and accessed to by using
loc.value. For example, we now write
loc.value = 3 + 2 * loc.value.
A complete example with the new syntax:
def squareRoot(self, x):
sp.verify(x >= 0)
y = sp.local('y', x)
sp.while y.value * y.value > x:
y.value = (x // y.value + y.value) // 2
sp.verify((y.value * y.value <= x)
& (x < (y.value + 1) * (y.value + 1)))
self.data.value = y.value
Remark: we don’t use
Updates in Scenarios
Scenarios are now more powerful than ever.
A typical scenario has this shape.
c1 = MyContract(12, 123)
scenario += c1 # And call some of its entry points
scenario += c1.myEntryPoint(12)
scenario += c1.myEntryPoint(13)
scenario += c1.myEntryPoint(14)
scenario += c1.myEntryPoint(50)
scenario += c1.myEntryPoint(50) # this is expected to fail
scenario += c1.myEntryPoint(50).run(valid = False) # Finally, we check its final storage
scenario.verify(c1.data.myParameter1 == 151)
We can now define test accounts by name in scenarios. A test account is then generated and comes with an address, a public key, a public key hash and a secret key.
admin = sp.test_account("Administrator")
alice = sp.test_account("Alice")
bob = sp.test_account("Robert")
In a scenario, it’s possible to show expressions. It’s useful to follow what is happening.
scenario.show(expression, html = True, stripStrings = False)scenario.show(c1.data)
In a scenario, we can also compute expressions.
The following command in a script
x = scenario.compute(c1.data.myParameter1 * 12)
c1.data.myParameter1 * 12 and stores its value in a variable
x can later be used in expressions in the scenario.
Testing equalities is of paramount importance in tests.
There are two ways to test equalities:
# Verifying a boolean expression that happens to be an equality
scenario.verify(c1.data.myParameter == 51)# Verifying an equality
scenario.verify_equal(c1.data.myList == [2, 3, 5, 7])
The new construction
scenario.verify_equal is useful to test equality on non comparable types.
The Michelson compiler generates Michelson code from SmartPy code. It has witnessed huge improvements in the past months. We are now able to compile many more constructions.
Better exception handling
Exception handling has been an important subject and we are now closer to where we want to be in terms of precision of error messages including location information.
Regular vs Reference Templates
Templates have been split between Regular and Reference templates.
Regular templates are templates that are supposed to do something meaningful. Reference templates are here to document the syntax and show how things can be articulated.
We’re now managing our own nodes on all networks: mainnet, carthagenet, babylonnet, labnet, zeronet.
The reference manual has been enhanced. It is visible from the editor by doing Help -> Reference Manual.
What comes next
Many things are coming for contracts, tests and compiler.
For tests, something that is arriving is the possibility to directly execute the scenarios in the translated Michelson world.
How To Contribute
The open source release means that we need to explain to the community how to contribute.
The code is more stable than it used to be, we expect to refactor huge parts of the code on a less frequent basis so it may be a better timing now to get involved.
There are several possibilities to get involved:
- Providing documentation
- Writing templates
- Reporting bugs and asking for improvements
- Adding features or operators
In general, please bear in mind that the development is quite active so please do not hesitate to contact us prior to working on a feature.