1import smartpy as sp
2
3
4@sp.module
5def main():
6 class Voting_Power(sp.Contract):
7 def __init__(self, a, b):
8 self.data.a = a
9 self.data.b = b
10
11 @sp.entrypoint
12 def validate(self, key):
13 self.data.a = sp.voting_power(sp.hash_key(key))
14 self.data.b = sp.total_voting_power
15
16
17@sp.add_test()
18def test():
19 scenario = sp.test_scenario("Voting_Power", main)
20 scenario.h1("Voting Power")
21
22 account = sp.test_account("tz1")
23
24 c1 = main.Voting_Power(a=0, b=0)
25 scenario += c1
26
27 c1.validate(
28 account.public_key,
29 _voting_powers={account.public_key_hash: 1, sp.key_hash("tz2"): 4},
30 )