def test_offer_requirements(self):
     # (based on current protocol constraints)
     self.assertEqual(TradeOffer.MinimumBuyOfferWithRate(500000000),
                      Constraints.minimumSwapBillBalance)
     self.assertEqual(TradeOffer.MinimumSellOfferWithRate(500000000),
                      Constraints.minimumSwapBillBalance // 2)
     self.assertEqual(TradeOffer.MinimumBuyOfferWithRate(62500000),
                      Constraints.minimumExchangeLTC * 16)
     self.assertEqual(TradeOffer.MinimumSellOfferWithRate(62500000),
                      Constraints.minimumExchangeLTC)
     # deposit is rounded up
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(500000000, 1 * e(7)),
         1 * e(7) * 2 // Constraints.depositDivisor)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(250000000, 1 * e(7)),
         1 * e(7) * 4 // Constraints.depositDivisor)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(62500000, 1 * e(7)),
         1 * e(7) * 16 // Constraints.depositDivisor)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(500000000, 1 * e(7) + 1),
         1 * e(7) * 2 // Constraints.depositDivisor + 1)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(250000000, 1 * e(7) + 1),
         1 * e(7) * 4 // Constraints.depositDivisor + 1)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(500000000, 1 * e(7) - 1),
         1 * e(7) * 2 // Constraints.depositDivisor)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(250000000, 1 * e(7) - 1),
         1 * e(7) * 4 // Constraints.depositDivisor)
     # (based on current protocol constraints)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(rate=500000000, ltcOffered=0),
         0)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(rate=500000000, ltcOffered=1),
         1)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(rate=500000000, ltcOffered=7),
         1)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(rate=500000000, ltcOffered=8),
         1)
     self.assertEqual(
         TradeOffer.DepositRequiredForLTCSell(rate=500000000, ltcOffered=9),
         2)
 def test_offer_creation(self):
     self.assertRaises(OfferIsBelowMinimumExchange, TradeOffer.BuyOffer,
                       5000, 375000000)
     self.assertRaises(OfferIsBelowMinimumExchange, TradeOffer.BuyOffer,
                       2 * e(6), 437500000)
     self.assertRaises(OfferIsBelowMinimumExchange, TradeOffer.BuyOffer,
                       2 * e(6),
                       500000000)  # swapbill offered below minimum balance
     self.assertRaises(OfferIsBelowMinimumExchange, TradeOffer.BuyOffer,
                       1 * e(7) - 1, 500000000)
     buy = TradeOffer.BuyOffer(1 * e(7), 500000000)
     self.assertDictEqual(buy.__dict__, {
         'rate': 500000000,
         '_swapBillOffered': 1 * e(7)
     })
     self.assertRaises(OfferIsBelowMinimumExchange, TradeOffer.SellOffer,
                       100, Constraints.minimumExchangeLTC - 1, 437500000)
     self.assertRaises(
         OfferIsBelowMinimumExchange, TradeOffer.SellOffer, 2 * e(6) // 16,
         1 * e(6), 500000000)  # swapbill equivalent below minimum balance
     rate = 437500000
     ltcOffered = TradeOffer.MinimumSellOfferWithRate(rate)
     deposit = TradeOffer.DepositRequiredForLTCSell(rate=rate,
                                                    ltcOffered=ltcOffered)
     sell = TradeOffer.SellOffer(deposit, ltcOffered, rate)
     self.assertDictEqual(sell.__dict__, {
         '_swapBillDeposit': deposit,
         'rate': rate,
         '_ltcOffered': ltcOffered
     })
     self.assertRaises(OfferIsBelowMinimumExchange, TradeOffer.SellOffer,
                       deposit, ltcOffered - 1, rate)
 def MinimumSellOffer(self, rate):
     ltcOffered = TradeOffer.MinimumSellOfferWithRate(rate)
     deposit = TradeOffer.DepositRequiredForLTCSell(rate, ltcOffered)
     return TradeOffer.SellOffer(deposit, ltcOffered, rate)