templates.shuffle

 1# Shuffle - Example for illustrative purposes only
 2
 3import smartpy as sp
 4
 5
 6@sp.module
 7def main():
 8    class Shuffle(sp.Contract):
 9        def __init__(self):
10            self.data.a = sp.record(x1=-1, x2=-2)
11            self.data.b = sp.record(x1=-3, x2=-4)
12
13        @sp.entrypoint
14        def swap(self):
15            x = self.data.a.x1
16            self.data.a.x1 = self.data.a.x2
17            self.data.a.x2 = x
18
19            self.data.b.x1 = self.data.b.x2
20            # self.data.b.x1 += 1
21            self.data.b.x2 *= 2
22
23
24@sp.add_test()
25def test():
26    scenario = sp.test_scenario("Shuffle", main)
27    scenario.h1("Shuffle")
28    c = main.Shuffle()
29    scenario += c