def test_leeq(self): a1 = Amount(1, self.symbol) a2 = Amount(1, self.symbol) self.assertTrue(a1 <= a2) self.assertTrue(a1 >= a2) self.assertTrue(a1 <= 1) self.assertTrue(a1 >= 1)
def test_ltge(self): a1 = Amount(1, self.symbol) a2 = Amount(2, self.symbol) self.assertTrue(a1 < a2) self.assertTrue(a2 > a1) self.assertTrue(a2 > 1) self.assertTrue(a1 < 5)
def test_init(self): # self.assertEqual(1, 1) Price("0.315 USD/BTS") Price(1.0, "USD/GOLD") Price(0.315, base="USD", quote="BTS") Price(0.315, base=Asset("USD"), quote=Asset("BTS")) Price({ "base": { "amount": 1, "asset_id": "1.3.0" }, "quote": { "amount": 10, "asset_id": "1.3.106" } }) Price( { "receives": { "amount": 1, "asset_id": "1.3.0" }, "pays": { "amount": 10, "asset_id": "1.3.106" }, }, base_asset=Asset("1.3.0")) Price(quote="10 GOLD", base="1 USD") Price("10 GOLD", "1 USD") Price(Amount("10 GOLD"), Amount("1 USD"))
def test_ne(self): a1 = Amount(1, self.symbol) a2 = Amount(2, self.symbol) self.assertTrue(a1 != a2) self.assertTrue(a1 != 5) a1 = Amount(1, self.symbol) a2 = Amount(1, self.symbol) self.assertTrue(a1 == a2) self.assertTrue(a1 == 1)
def test_pow(self): a1 = Amount(15, self.symbol) self.dotest(a1**3, 15**3, self.symbol) self.dotest(a1**2, 15**2, self.symbol) with self.assertRaises(Exception): a1**Amount(1, asset=self.asset2) # inline a2 = a1.copy() a2 **= 3 self.dotest(a2, 15**3, self.symbol) with self.assertRaises(Exception): a1 **= Amount(2, asset=self.asset2)
def test_mod(self): a1 = Amount(15, self.symbol) self.dotest(a1 % 3, 0, self.symbol) self.dotest(a1 % 2, 1, self.symbol) with self.assertRaises(Exception): a1 % Amount(1, asset=self.asset2) # inline a2 = a1.copy() a2 %= 3 self.dotest(a2, 0, self.symbol) with self.assertRaises(Exception): a1 %= Amount(2, asset=self.asset2)
def test_mul(self): a1 = Amount(5, self.symbol) a2 = Amount(2, self.symbol) self.dotest(a1 * a2, 10, self.symbol) self.dotest(a1 * 3, 15, self.symbol) with self.assertRaises(Exception): a1 * Amount(1, asset=self.asset2) # inline a2 = Amount(2, self.symbol) a2 *= 5 self.dotest(a2, 10, self.symbol) with self.assertRaises(Exception): a1 *= Amount(2, asset=self.asset2)
def test_plus(self): a1 = Amount(1, self.symbol) a2 = Amount(2, self.symbol) self.dotest(a1 + a2, 3, self.symbol) with self.assertRaises(Exception): a1 + Amount(1, asset=self.asset2) # inline a2 = Amount(2, self.symbol) a2 += a1 self.dotest(a2, 3, self.symbol) a2 += 5 self.dotest(a2, 8, self.symbol) with self.assertRaises(Exception): a1 += Amount(1, asset=self.asset2)
def test_minus(self): a1 = Amount(1, self.symbol) a2 = Amount(2, self.symbol) self.dotest(a1 - a2, -1, self.symbol) self.dotest(a1 - 5, -4, self.symbol) with self.assertRaises(Exception): a1 - Amount(1, asset=self.asset2) # inline a2 = Amount(2, self.symbol) a2 -= a1 self.dotest(a2, 1, self.symbol) a2 -= 1 self.dotest(a2, 0, self.symbol) self.dotest(a2 - 2, -2, self.symbol) with self.assertRaises(Exception): a1 -= Amount(1, asset=self.asset2)
def test_transfer(self): bts = self.bts tx = bts.transfer( "1.2.8", 1.33, core_unit, memo="Foobar", account="1.2.7") self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "transfer" ) op = tx["operations"][0][1] self.assertIn("memo", op) self.assertEqual(op["from"], "1.2.7") self.assertEqual(op["to"], "1.2.8") amount = Amount(op["amount"]) self.assertEqual(float(amount), 1.33)
def test_init(self): # String init amount = Amount("1 {}".format(self.symbol)) self.dotest(amount, 1, self.symbol) # Amount init amount = Amount(amount) self.dotest(amount, 1, self.symbol) # blockchain dict init amount = Amount({ "amount": 1 * 10**self.precision, "asset_id": self.asset["id"] }) self.dotest(amount, 1, self.symbol) # API dict init amount = Amount({ "amount": 1.3 * 10**self.precision, "asset": self.asset["id"] }) self.dotest(amount, 1.3, self.symbol) # Asset as symbol amount = Amount(1.3, Asset("1.3.0")) self.dotest(amount, 1.3, self.symbol) # Asset as symbol amount = Amount(1.3, self.symbol) self.dotest(amount, 1.3, self.symbol) # keyword inits amount = Amount(amount=1.3, asset=Asset("1.3.0")) self.dotest(amount, 1.3, self.symbol) # keyword inits amount = Amount(amount=1.3, asset=dict(Asset("1.3.0"))) self.dotest(amount, 1.3, self.symbol) # keyword inits amount = Amount(amount=1.3, asset=self.symbol) self.dotest(amount, 1.3, self.symbol)
def test_div(self): a1 = Amount(15, self.symbol) self.dotest(a1 / 3, 5, self.symbol) self.dotest(a1 // 2, 7, self.symbol) with self.assertRaises(Exception): a1 / Amount(1, asset=self.asset2) # inline a2 = a1.copy() a2 /= 3 self.dotest(a2, 5, self.symbol) a2 = a1.copy() a2 //= 2 self.dotest(a2, 7, self.symbol) with self.assertRaises(Exception): a1 *= Amount(2, asset=self.asset2)
def test_float(self): self.assertEqual(float(Amount("1", self.symbol)), 1.00000)
def test_int(self): self.assertEqual(int(Amount("1", self.symbol)), 100000)
def test_string(self): self.assertEqual(str(Amount("1", self.symbol)), "1.00000 {}".format(self.symbol))
def test_json(self): amount = Amount("1", self.symbol) self.assertEqual(amount.json(), { "asset_id": self.asset["id"], "amount": 1 * 10**self.precision })
def test_tuple(self): amount = Amount("1", self.symbol) self.assertEqual(amount.tuple(), (1.0, self.symbol))
def test_properties(self): amount = Amount("1", self.symbol) self.assertEqual(amount.amount, 1.0) self.assertEqual(amount.symbol, self.symbol) self.assertIsInstance(amount.asset, Asset) self.assertEqual(amount.asset["symbol"], self.symbol)
def test_copy(self): amount = Amount("1", self.symbol) self.dotest(amount.copy(), 1, self.symbol)