예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 def test_transfer(self):
     grv = self.grv
     tx = grv.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)
예제 #10
0
    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)
예제 #11
0
 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)
예제 #12
0
def fees(ctx):
    """ List fees
    """
    from gravitybase.operationids import getOperationNameForId

    chain = Blockchain(gravity_instance=ctx.gravity)
    feesObj = chain.chainParameters().get("current_fees")
    fees = feesObj["parameters"]

    t = PrettyTable(["Operation", "Type", "Fee"])
    t.align = "l"
    t.align["Fee"] = "r"

    for fee in fees:
        for f in fee[1]:
            t.add_row([
                getOperationNameForId(fee[0]), f,
                str(Amount({
                    "amount": fee[1].get(f, 0),
                    "asset_id": "1.3.0"
                }))
            ])
    click.echo(t)
예제 #13
0
 def test_float(self):
     self.assertEqual(float(Amount("1", self.symbol)), 1.00000)
예제 #14
0
 def test_int(self):
     self.assertEqual(int(Amount("1", self.symbol)), 100000)
예제 #15
0
 def test_string(self):
     self.assertEqual(str(Amount("1", self.symbol)),
                      "1.00000 {}".format(self.symbol))
예제 #16
0
 def test_json(self):
     amount = Amount("1", self.symbol)
     self.assertEqual(amount.json(), {
         "asset_id": self.asset["id"],
         "amount": 1 * 10**self.precision
     })
예제 #17
0
 def test_tuple(self):
     amount = Amount("1", self.symbol)
     self.assertEqual(amount.tuple(), (1.0, self.symbol))
예제 #18
0
 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)
예제 #19
0
 def test_copy(self):
     amount = Amount("1", self.symbol)
     self.dotest(amount.copy(), 1, self.symbol)