New Release for SmartPy and SmartPy.io: Open Source Version and Syntax, Testing, and Michelson Compiler Improvements SmartPy.io Follow Jan 13 · 3 min read

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.

Snake Case

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 sp.entry_point .

There is an automated translation tool for this part in SmartPy.io that is triggered automatically when evaluating a script.

Local Variables

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.newLocal is renammed sp.local (this is done automatically)

is renammed (this is done automatically) if loc is 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:

@sp.entry_point

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 loc.set(...) anymore.

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)

Test Accounts

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")

Showing Expressions

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)

scenario.show(c1.data.l)

Computing Expressions

In a scenario, we can also compute expressions.

The following command in a script

x = scenario.compute(c1.data.myParameter1 * 12)

computes c1.data.myParameter1 * 12 and stores its value in a variable x .

The variable x can later be used in expressions in the scenario.

Testing Equality

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.

Compiler

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.

Nodes

We’re now managing our own nodes on all networks: mainnet, carthagenet, babylonnet, labnet, zeronet.

https://mainnet.smartpy.io

Documentation

The reference manual has been enhanced. It is visible from the editor by doing Help -> Reference Manual.