-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path31_1_variant_without_parameter.py
More file actions
39 lines (32 loc) · 1.24 KB
/
31_1_variant_without_parameter.py
File metadata and controls
39 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import smartpy as sp
@sp.module
def main():
drink_type:type = sp.variant(Coca = sp.unit, Fanta = sp.unit, SevenUp = sp.unit, Water = sp.unit)
class Restaurant(sp.Contract):
def __init__(self):
self.data.items = []
@sp.entrypoint
def orderDrink(self, drink):
sp.cast(drink, drink_type)
price = sp.tez(0)
with sp.match(drink):
with sp.case.Coca:
price = sp.tez(1)
with sp.case.Fanta:
price = sp.tez(2)
with sp.case.Water:
price = sp.tez(0)
# etc.
assert sp.amount == price
self.data.items.push(drink)
@sp.add_test()
def test():
scenario = sp.test_scenario("Test", main)
c1 = main.Restaurant()
scenario += c1
scenario.h3("J'ai faim")
c1.orderDrink(sp.variant("Water", ()))
c1.orderDrink(sp.variant("Coca", ()), _valid = False)
c1.orderDrink(sp.variant("Coca", ()), _amount = sp.tez(1), _valid = True)
c1.orderDrink(sp.variant("Fanta", ()), _valid = False)
c1.orderDrink(sp.variant("Fanta", ()), _amount = sp.tez(2), _valid = True)