Esempio n. 1
0
    def test_voting_process(self, a1, b1, c1, a2, b2, c2):
        election_id = a1.create_election(std.timedelta(seconds=30))
        a1.cast_vote(election_id, 2)
        b1.cast_vote(election_id, 2)
        c1.cast_vote(election_id, 3)
        res = a1.tally_votes(election_id)

        election_id = a2.create_election(std.timedelta(seconds=30))
        a2.cast_vote(election_id, ['a'])
        b2.cast_vote(election_id, ['a', 'b'])
        c2.cast_vote(election_id, ['c'])
        res = a2.tally_votes(election_id)
        self.assertEqual(res[0], 'a')
Esempio n. 2
0
 def test_voting_process(self, pm, v1, v2, v3, basic_math):
     election_id = pm.create_election(std.timedelta(seconds=30))
     v1.cast_vote(election_id, 5)
     v2.cast_vote(election_id, 5)
     v3.cast_vote(election_id, 7)
     res = v3.tally_votes(election_id)
     self.assertEqual(res, 5)
Esempio n. 3
0
 def test_is_witness_fail(self, a, b, c, carl):
     election_id = a.create_election(std.timedelta(seconds=30))
     a.cast_vote(election_id, 10000)
     b.cast_vote(election_id, 10000)
     c.cast_vote(election_id, 12000)
     res = a.tally_votes(election_id)
     self.assertFalse(carl.is_witness('DAVIS'))
Esempio n. 4
0
 def test_unlock_coins(self, davis):
     davis.lock_coins(500, std.timedelta(seconds=1))
     self.assertEqual(davis.get_balance('DAVIS'), 3696447)
     self.assertTrue(davis.is_locked('DAVIS'))
     time.sleep(1.5)
     davis.unlock_coins()
     self.assertEqual(davis.get_balance('DAVIS'), 3696947)
     self.assertFalse(davis.is_locked('DAVIS'))
Esempio n. 5
0
 def test_is_witness(self, a, b, c, davis, carl):
     election_id = a.create_election(std.timedelta(seconds=30))
     a.cast_vote(election_id, 10000)
     b.cast_vote(election_id, 10000)
     c.cast_vote(election_id, 12000)
     res = a.tally_votes(election_id)
     davis.stake()
     self.assertTrue(carl.is_witness('DAVIS'))
Esempio n. 6
0
 def test_unstake_fail(self, a, b, c, davis):
     election_id = a.create_election(std.timedelta(seconds=30))
     a.cast_vote(election_id, 10000)
     b.cast_vote(election_id, 10000)
     c.cast_vote(election_id, 12000)
     res = a.tally_votes(election_id)
     davis.stake()
     with self.assertRaises(Exception) as context:
         davis.unstake()
Esempio n. 7
0
 def test_stake(self, a, b, c, davis, davis_currency):
     election_id = a.create_election(std.timedelta(seconds=30))
     a.cast_vote(election_id, 10000)
     b.cast_vote(election_id, 10000)
     c.cast_vote(election_id, 12000)
     res = a.tally_votes(election_id)
     self.assertEqual(davis_currency.get_balance(), 3696947)
     davis.stake()
     self.assertTrue(davis.is_witness())
     self.assertEqual(davis_currency.get_balance(), 3686947)
Esempio n. 8
0
 def test_get_vks(self, a, b, c, davis, carl):
     election_id = a.create_election(std.timedelta(seconds=30))
     a.cast_vote(election_id, 10000)
     b.cast_vote(election_id, 10000)
     c.cast_vote(election_id, 12000)
     res = a.tally_votes(election_id)
     davis.stake()
     carl.stake()
     self.assertEqual(list(carl.get_vks()), [{
         'id': 2,
         'witness_id': 'CARL'
     }, {
         'id': 1,
         'witness_id': 'DAVIS'
     }])
Esempio n. 9
0
 def test_create_election_exhaustion(self, election):
     election_id = election.create_election(std.timedelta(seconds=1), int)
     with self.assertRaises(Exception) as context:
         election.create_election(std.timedelta(seconds=1), int)
Esempio n. 10
0
 def test_get_election(self, election):
     election_id = election.create_election(std.timedelta(seconds=37), int)
     e = election.get_election(election_id)
     self.assertEqual(e['opened_ts'], e['expire_on']-std.timedelta(seconds=37))
Esempio n. 11
0
 def test_create(self, election):
     election_id = election.create_election(std.timedelta(seconds=1), int)
     self.assertEqual(election_id, 1)
Esempio n. 12
0
 def test_lock_coins_negative(self, davis):
     with self.assertRaises(Exception) as context:
         davis.lock_coins(-123, std.timedelta(seconds=1))
Esempio n. 13
0
 def test_unlock_coins(self, davis):
     davis.lock_coins(500, std.timedelta(seconds=1))
     self.assertEqual(davis.get_balance('DAVIS'), 3696447)
     with self.assertRaises(Exception) as context:
         davis.unlock_coins()
Esempio n. 14
0
 def test_lock_coins(self, davis):
     davis.lock_coins(500, std.timedelta(seconds=3))
     davis.is_locked('DAVIS')
     self.assertEqual(davis.get_balance('DAVIS'), 3696447)
Esempio n. 15
0
 def test_pass(self, election):
     election_id = election.create_election(std.timedelta(seconds=10), int)
     election.pass_election(election_id)
Esempio n. 16
0
 def test_cancel(self, election):
     election_id = election.create_election(std.timedelta(seconds=10), int)
     election.cancel_election(election_id)
Esempio n. 17
0
 def test_lock_coins_not_enough(self, davis):
     with self.assertRaises(Exception) as context:
         davis.lock_coins(3696950, std.timedelta(seconds=1))