def test_leaderboard_anon(self): s = m.UserSettings(user="******", anon=True) db.session.add(s) start = datetime.datetime.utcnow() now = start - datetime.timedelta(minutes=2) v = m.ShareSlice(time=now, value=101, user="******", worker="", algo="scrypt", span=0, share_type="acc") db.session.add(v) v = m.ShareSlice(time=now, value=100, user="******", worker="", algo="scrypt", span=0, share_type="acc") db.session.add(v) db.session.commit() leaderboard() users = cache.get("leaderboard") self.assertEquals(users[0][0], "Anonymous") self.assertEquals(users[0][1]['scrypt'], 110318.93333333333) self.assertEquals(users[1][0], "DAbhwsnEq5TjtBP5j76TinhUqqLTktDAnD") self.assertEquals(users[1][1]['scrypt'], 109226.66666666667)
def test_payout_unexchangeable(self): """ Payout an unexchangeable currency """ bd = self.test_block_data.copy() bd.update(dict(currency="TCO")) self.app.redis.hmset( "unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f", bd) self.app.redis.rpush("chain_1_slice_17", *["DJCgMCyjBKxok3eEGed5SGhbWaGj5QTcxF:1"] * 30) self.app.redis.rpush("chain_1_slice_17", *["DLePZigvzzvSyoWztctVVsPtDuhzBfqEgd:1"] * 30) user_set = m.UserSettings(user="******") addr = m.PayoutAddress(user='******', address='LbfSCZE1p9A3Yj2JK1n57kxyD2H1ZSXtNG', currency='TCO') db.session.add(user_set) db.session.add(addr) db.session.commit() credit_block("unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f") db.session.rollback() db.session.expunge_all() payouts = m.Credit.query.all() for p in payouts: print((p.id, p.user, p.address, p.block, p.currency, p.block.currency, p.source)) pool_payouts = m.Credit.query.filter_by(address=currencies['TCO'].pool_payout_addr).all() m.Credit.query.filter_by(address='LbfSCZE1p9A3Yj2JK1n57kxyD2H1ZSXtNG').one() self.assertEqual(len(payouts), 3) self.assertEqual(len(pool_payouts), 2)
def test_payout_donation(self): """ Make sure users setting donation percentages work properly """ s = m.UserSettings(user="******", pdonation_perc=Decimal("0.05")) db.session.add(s) self.app.redis.hmset( "unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f", self.test_block_data.copy()) self.app.redis.rpush("chain_1_slice_17", *["DJCgMCyjBKxok3eEGed5SGhbWaGj5QTcxF:1"] * 30) credit_block("unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f") db.session.rollback() db.session.expunge_all() assert m.Credit.query.filter_by(user="******").count() == 1 donation = m.Credit.query.filter_by(source=2).one() assert donation.amount < 3
def test_generate_zero(self): chain_shares = { 1: { 'D5nYTCs9aNg5QAcw35KZj45ZA9iFbN6ZU7': Decimal('381120') } } self.app.redis.rpush( "chain_1_slice_25", *[ "{}:{}".format(user, shares) for user, shares in chain_shares[1].iteritems() ]) self.app.redis.hmset( "unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f", { 'chain_1_solve_index': '45', 'hash': '0dbc436b29e577e7932dd13655179f3c3e06b2940be4e0e04f87069caa0f603f', 'total_subsidy': '13517762478', 'start_time': '1410401945.063338', 'address': 'DMNvCJ33EBQn14S1hb1chBk1XoiBEZ4ScJ', 'worker': 'worker1', 'height': '35630', 'currency': 'SYS', 'algo': 'scrypt', 'fees': '-1', 'chain_1_shares': '56583488', 'hex_bits': '1C008FA7', 'solve_time': '1410412589.175215', 'merged': '1' }) s = m.UserSettings(user="******", spayout_perc=Decimal("1.00"), spayout_addr="1JBDMJWBYgA6Rmp8EUPyzFQp79uNsJb67R", spayout_curr="BTC", pdonation_perc=Decimal("0.05")) db.session.add(s) db.session.commit() db.session.expunge_all() generate_credits() db.session.rollback()
def test_payout_special_split(self): """ Make sure that special payout splits work as expected """ s = m.UserSettings(user="******", spayout_perc=Decimal("0.05"), spayout_addr="DAbhwsnEq5TjtBP5j76TinhUqqLTktDAnD", spayout_curr="DOGE") db.session.add(s) self.app.redis.hmset( "unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f", self.test_block_data.copy()) self.app.redis.rpush( "chain_1_slice_17", *["DJCgMCyjBKxok3eEGed5SGhbWaGj5QTcxF:1"] * 30) credit_block("unproc_block_01c5da46e845868a7ead5eb97d07c4299b6370e65fd4313416772e181c0c756f") db.session.rollback() db.session.expunge_all() assert m.Credit.query.filter_by( user="******").count() == 2 split = m.Credit.query.filter_by( address="DAbhwsnEq5TjtBP5j76TinhUqqLTktDAnD").one() assert split.amount < 3
def test_cache_(self): s = m.UserSettings(user="******", anon=True) db.session.add(s) db.session.commit() assert "185cYTmEaTtKmBZc8aSGCr9v2VCDLqQHgR" in anon_users()