templates.voting

 1# Simple Vote - Example for illustrative purposes only.
 2
 3import smartpy as sp
 4
 5
 6@sp.module
 7def main():
 8    class SimpleVote(sp.Contract):
 9        def __init__(self):
10            self.data.votes = []
11
12        @sp.entrypoint
13        def vote(self, params):
14            sp.cast(params.vote, sp.string)
15            self.data.votes.push(sp.record(sender=sp.sender, vote=params.vote))
16
17
18@sp.add_test()
19def test():
20    scenario = sp.test_scenario("Voting", main)
21    scenario.h1("Voting")
22    voter1 = sp.test_account("Voter1")
23    # define a contract
24    c1 = main.SimpleVote()
25    # show its representation
26    scenario.h2("Contract")
27    scenario += c1
28    c1.vote(vote="aaa", _sender=voter1)