def test_payout_generation(self): blk1 = self.make_block(mature=True) blk2 = self.make_block(mature=False) tr = m.TradeRequest( quantity=sum(xrange(1, 20)), type="sell", currency="LTC" ) pending = m.CreditExchange( amount="12.2394857987234598723453245", currency="DOGE", block=blk1, address="pending") db.session.add(pending) already_sold = m.CreditExchange( amount="12.2394857987234598723453245", currency="DOGE", block=blk1, sell_req=tr, address="already_sold") db.session.add(pending) immature = m.CreditExchange( amount="12.2394857987234598723453245", currency="DOGE", block=blk2, address="immature") db.session.add(immature) db.session.commit() create_trade_req("sell") db.session.rollback() trs = m.TradeRequest.query.all() assert pending.sell_req is not None assert pending.sell_req != already_sold.sell_req assert immature.sell_req is None assert already_sold.sell_req == tr assert len(trs) == 2 assert trs[1].quantity == Decimal("12.2394857987234598723453245")
def test_push_tr_buy(self): credits = [] tr = m.TradeRequest(quantity=sum(xrange(1, 20)), type="buy", currency="TEST") db.session.add(tr) for i in xrange(1, 20): c = m.CreditExchange(amount=i, sell_amount=i, sell_req=None, buy_req=tr, currency="TEST", address="test{}".format(i)) credits.append(c) db.session.add(c) db.session.commit() push_data = { 'trs': { tr.id: { "status": 6, "quantity": "1000", "fees": "1" } } } db.session.expunge_all() with self.app.test_request_context('/?name=Peter'): flask.g.signer = TimedSerializer(self.app.config['rpc_signature']) flask.g.signed = push_data update_trade_requests() db.session.rollback() db.session.expunge_all() previous = 0 for credit in m.CreditExchange.query.all(): print credit.id, credit.sell_amount, credit.buy_amount assert credit.buy_amount > previous previous = credit.buy_amount assert m.TradeRequest.query.first()._status == 6
def test_payout_generation(self): too_low = m.Credit( amount="0.0000000001", currency="DOGE", payable=True, address="too_low") db.session.add(too_low) grouped = m.Credit( amount="12.2394857987234598723453245", currency="DOGE", payable=True, address="grouped") db.session.add(grouped) double2 = m.Credit( amount="12", currency="DOGE", payable=True, address="double") db.session.add(double2) double1 = m.CreditExchange( buy_amount="12", currency="DOGE", payable=True, address="double") db.session.add(double1) db.session.commit() create_payouts() db.session.rollback() assert too_low.payout is None assert grouped.payout is not None remain = m.Credit.query.filter_by(address="grouped", payout=None).one() grouped_result = m.Payout.query.filter_by(address="grouped").one() double_result = m.Payout.query.filter_by(address="double").one() self.assertEquals(grouped_result.amount, Decimal("12.23948579")) self.assertEquals(remain.amount, Decimal('8.7234598723453245E-9')) self.assertEquals(grouped_result.amount + remain.amount, grouped.amount) self.assertEquals(double_result.amount, double2.amount * 2)