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): 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")