示例#1
0
 def reset(self):
     """ Resets the arrays not the stored account history
     """
     self.own_vests = [Amount(0, self.hive.vests_symbol, hive_instance=self.hive)]
     self.own_steem = [Amount(0, self.hive.steem_symbol, hive_instance=self.hive)]
     self.own_sbd = [Amount(0, self.hive.sbd_symbol, hive_instance=self.hive)]
     self.delegated_vests_in = [{}]
     self.delegated_vests_out = [{}]
     self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))]
     import bhivebase.operationids
     self.ops_statistics = bhivebase.operationids.operations.copy()
     for key in self.ops_statistics:
         self.ops_statistics[key] = 0
     self.reward_timestamps = []
     self.author_rewards = []
     self.curation_rewards = []
     self.curation_per_1000_HP_timestamp = []
     self.curation_per_1000_HP = []
     self.out_vote_timestamp = []
     self.out_vote_weight = []
     self.in_vote_timestamp = []
     self.in_vote_weight = []
     self.in_vote_rep = []
     self.in_vote_rshares = []
     self.vp = []
     self.vp_timestamp = []
     self.rep = []
     self.rep_timestamp = []
示例#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_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)
     self.assertTrue(a1 == 1.0001)
示例#4
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)
示例#5
0
 def test_json_appbase(self):
     asset = Asset("HBD", hive_instance=self.bts)
     amount = Amount("1",
                     asset,
                     new_appbase_format=False,
                     hive_instance=self.bts)
     if self.bts.rpc.get_use_appbase():
         self.assertEqual(
             amount.json(),
             [str(1 * 10**asset.precision), asset.precision, asset.asset])
     else:
         self.assertEqual(amount.json(), "1.000 HBD")
示例#6
0
 def test_json_appbase2(self):
     asset = Asset("HBD", hive_instance=self.bts)
     amount = Amount("1",
                     asset,
                     new_appbase_format=True,
                     hive_instance=self.bts)
     if self.bts.rpc.get_use_appbase():
         self.assertEqual(
             amount.json(), {
                 'amount': str(1 * 10**asset.precision),
                 'nai': asset.asset,
                 'precision': asset.precision
             })
     else:
         self.assertEqual(amount.json(), "1.000 HBD")
示例#7
0
 def test_dict(self):
     self.assertEqual(
         int(Amount({
             'amount': '150',
             'nai': '@@000000021',
             'precision': 3
         })), 150)
示例#8
0
    def test_transfer_2of2_offline(self):
        # Send a 2 of 2 transaction from bhive5 which needs bhive4's cosign to send
        # funds but sign the transaction with bhive5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with bhive4's key.
        hive = self.bts
        hive.nobroadcast = False
        hive.wallet.unlock("123")
        # hive.wallet.removeAccount("bhive4")
        hive.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_bhive4, prefix=core_unit)))

        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

        tx.appendSigner("bhive5", "active")
        tx.addSigningInformation("bhive5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        # hive.wallet.removeAccount("bhive5")
        hive.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_bhive5, prefix=core_unit)))
        hive.wallet.addPrivateKey(self.active_private_key_of_bhive4)
        tx.appendMissingSignatures()
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
        hive.wallet.addPrivateKey(self.active_private_key_of_bhive5)
示例#9
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)
示例#10
0
 def test_amount(self, node_param):
     if node_param == "instance":
         hv = Hive(node="https://abc.d", autoconnect=False, num_retries=1)
         set_shared_hive_instance(self.bts)
         o = Amount("1 HBD")
         self.assertIn(o.hive.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Amount("1 HBD", hive_instance=hv)
     else:
         set_shared_hive_instance(
             Hive(node="https://abc.d", autoconnect=False, num_retries=1))
         hv = self.bts
         o = Amount("1 HBD", hive_instance=hv)
         self.assertIn(o.hive.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Amount("1 HBD")
示例#11
0
 def test_plus(self):
     a1 = Amount(1, self.symbol)
     a2 = Amount(2, self.symbol)
     self.dotest(a1 + a2, 3, self.symbol)
     self.dotest(a1 + 2, 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)
     a2 += Decimal(2)
     self.dotest(a2, 10, self.symbol)
     with self.assertRaises(Exception):
         a1 += Amount(1, asset=self.asset2)
示例#12
0
    def test_sell(self):
        bts = self.bts
        bts.txbuffer.clear()
        m = Market(u'HIVE:HBD', hive_instance=bts)
        tx = m.sell(5, 0.1, account="test")
        self.assertEqual(
            (tx["operations"][0][0]),
            "limit_order_create"
        )
        op = tx["operations"][0][1]
        self.assertIn("test", op["owner"])
        self.assertEqual(str(Amount('0.500 HBD', hive_instance=bts)), op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 HIVE', hive_instance=bts)), op["amount_to_sell"])

        p = Price(5, u"HBD:HIVE")
        tx = m.sell(p, 0.1, account="test")
        op = tx["operations"][0][1]
        self.assertEqual(str(Amount('0.500 HBD', hive_instance=bts)), op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 HIVE', hive_instance=bts)), op["amount_to_sell"])

        p = Price(5, u"HBD:HIVE", hive_instance=bts)
        a = Amount(0.1, "HIVE", hive_instance=bts)
        tx = m.sell(p, a, account="test")
        op = tx["operations"][0][1]
        self.assertEqual(str(Amount('0.500 HBD', hive_instance=bts)), op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 HIVE', hive_instance=bts)), op["amount_to_sell"])
示例#13
0
 def time_transfer(self):
     self.op = operations.Transfer(**{
         "from": "foo",
         "to": "baar",
         "amount": Amount("111.110 HIVE", hive_instance=self.hv),
         "memo": "Fooo",
         "prefix": self.default_prefix
     })
     self.doit()
示例#14
0
 def test_filled_order(self):
     order = {
         "date": "1900-01-01T00:00:00",
         "current_pays": "2 HBD",
         "open_pays": "1 HIVE"
     }
     filledOrder = FilledOrder(order)
     self.assertTrue(repr(filledOrder) is not None)
     self.assertEqual(filledOrder.json()["current_pays"],
                      Amount("2.000 HBD").json())
示例#15
0
    def test_init(self):
        # self.assertEqual(1, 1)

        Price("0.315 HIVE/HBD")
        Price(1.0, "HIVE/HBD")
        Price(0.315, base="HIVE", quote="HBD")
        Price(0.315, base=Asset("HIVE"), quote=Asset("HBD"))
        Price({
            "base": {
                "amount": 1,
                "asset_id": "HBD"
            },
            "quote": {
                "amount": 10,
                "asset_id": "HIVE"
            }
        })
        Price("", quote="10 HBD", base="1 HIVE")
        Price("10 HBD", "1 HIVE")
        Price(Amount("10 HBD"), Amount("1 HIVE"))
示例#16
0
 def test_int(self):
     self.assertEqual(int(Amount("0.9999", self.symbol)), 999)
     self.assertEqual(int(Amount(0.151, self.symbol)), 151)
     self.assertEqual(int(Amount(round(0.1509, 3), self.symbol)), 151)
     self.assertEqual(int(Amount(round(0.1509, 3), self.asset)), 151)
     self.assertEqual(int(Amount(int(1), self.symbol)), 1000)
     self.assertEqual(
         int(Amount(amount=round(0.1509, 3), asset=Asset("HBD"))), 151)
示例#17
0
 def test_verifyAuthority(self):
     hv = self.bts
     hv.wallet.unlock("123")
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1.300 HBD", hive_instance=hv),
                              "memo": "Foobar"}))
     account = Account("bhive", hive_instance=hv)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
示例#18
0
 def test_transfer(self):
     bts = self.bts
     acc = self.account
     acc.hive.txbuffer.clear()
     tx = acc.transfer("test", 1.33, "HBD", memo="Foobar", account="test1")
     self.assertEqual(tx["operations"][0][0], "transfer")
     self.assertEqual(len(tx["operations"]), 1)
     op = tx["operations"][0][1]
     self.assertIn("memo", op)
     self.assertEqual(op["memo"], "Foobar")
     self.assertEqual(op["from"], "test1")
     self.assertEqual(op["to"], "test")
     amount = Amount(op["amount"], hive_instance=bts)
     self.assertEqual(float(amount), 1.33)
示例#19
0
    def test_Transfer_broadcast(self):
        nodelist = NodeList()
        hv = Hive(node=self.nodes,
                    keys=[self.active_key],
                    nobroadcast=True,
                    expiration=120,
                    num_retries=10)

        tx = TransactionBuilder(use_condenser_api=True, expiration=10, hive_instance=hv)
        tx.appendOps(Transfer(**{"from": "bhive",
                                 "to": "bhive1",
                                 "amount": Amount("1 HIVE", hive_instance=hv),
                                 "memo": ""}))
        tx.appendSigner("bhive", "active")
        tx.sign()
        tx.broadcast()
示例#20
0
    def test_div2(self):
        p1 = Price(10.0, "HIVE/HBD")
        p2 = Price(5.0, "HIVE/HBD")

        # 10 HIVE/HBD / 5 HIVE/VESTS = 2 VESTS/HBD
        p3 = p1 / p2
        self.assertTrue(isinstance(p3, (float, int)))
        self.assertEqual(float(p3), 2.0)
        p3 = p1 / 5
        self.assertEqual(float(p3), 2.0)
        p3 = p1 / Amount("1 HBD")
        self.assertEqual(float(p3), 0.1)
        p3 = p1
        p3 /= p2
        self.assertEqual(float(p3), 2.0)
        p3 = p1
        p3 /= 5
        self.assertEqual(float(p3), 2.0)
示例#21
0
 def test_transfer_1of1(self):
     hive = self.bts
     hive.nobroadcast = False
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
     tx.appendOps(Transfer(**{"from": 'bhive',
                              "to": 'bhive1',
                              "amount": Amount("0.01 HIVE", hive_instance=hive),
                              "memo": '1 of 1 transaction'}))
     self.assertEqual(
         tx["operations"][0]["type"],
         "transfer_operation"
     )
     tx.appendWif(self.active_key)
     tx.sign()
     tx.sign()
     self.assertEqual(len(tx['signatures']), 1)
     tx.broadcast()
     hive.nobroadcast = True
示例#22
0
    def test_transfer_2of2_simple(self):
        # Send a 2 of 2 transaction from elf which needs bhive4's cosign to send funds
        hive = self.bts
        hive.nobroadcast = False
        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive1',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 simple transaction'}))

        tx.appendWif(self.active_private_key_of_bhive5)
        tx.sign()
        tx.clearWifs()
        tx.appendWif(self.active_private_key_of_bhive4)
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
示例#23
0
 def test_TransactionConstructor(self):
     hv = self.bts
     opTransfer = Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""})
     tx1 = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, hive_instance=hv)
     self.assertFalse(tx.is_empty())
     self.assertTrue(len(tx.list_operations()) == 1)
     self.assertTrue(repr(tx) is not None)
     self.assertTrue(str(tx) is not None)
     account = Account("bhive", hive_instance=hv)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
示例#24
0
    def test_transfer_2of2_wallet(self):
        # Send a 2 of 2 transaction from bhive5 which needs bhive4's cosign to send
        # priv key of bhive5 and bhive4 are stored in the wallet
        # appendSigner fetches both keys and signs automatically with both keys.
        hive = self.bts
        hive.nobroadcast = False
        hive.wallet.unlock("123")

        tx = TransactionBuilder(use_condenser_api=True, hive_instance=hive)
        tx.appendOps(Transfer(**{"from": 'bhive5',
                                 "to": 'bhive1',
                                 "amount": Amount("0.01 HIVE", hive_instance=hive),
                                 "memo": '2 of 2 serialized/deserialized transaction'}))

        tx.appendSigner("bhive5", "active")
        tx.sign()
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        hive.nobroadcast = True
示例#25
0
 def test_pow(self):
     a1 = Amount(15, self.symbol)
     a2 = Amount(3, self.symbol)
     self.dotest(a1**3, 15**3, self.symbol)
     self.dotest(a1**a2, 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)
示例#26
0
 def test_mod(self):
     a1 = Amount(15, self.symbol)
     a2 = Amount(3, self.symbol)
     self.dotest(a1 % 3, 0, self.symbol)
     self.dotest(a1 % a2, 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)
示例#27
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)
示例#28
0
 def test_transfer(self):
     bts = self.bts
     bts.nobroadcast = False
     bts.wallet.unlock("123")
     # bts.wallet.addPrivateKey(self.active_key)
     # bts.prefix ="STX"
     acc = Account("bhive", hive_instance=bts)
     tx = acc.transfer(
         "bhive1", 1.33, "HBD", memo="Foobar")
     self.assertEqual(
         tx["operations"][0][0],
         "transfer"
     )
     self.assertEqual(len(tx['signatures']), 1)
     op = tx["operations"][0][1]
     self.assertIn("memo", op)
     self.assertEqual(op["from"], "bhive")
     self.assertEqual(op["to"], "bhive1")
     amount = Amount(op["amount"], hive_instance=bts)
     self.assertEqual(float(amount), 1.33)
     bts.nobroadcast = True
示例#29
0
 def test_appendSigner(self):
     nodelist = NodeList()
     hv = Hive(node=self.nodes,
                 keys=[self.active_key],
                 nobroadcast=True,
                 expiration=120,
                 num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, hive_instance=hv)
     tx.appendOps(Transfer(**{"from": "bhive",
                              "to": "bhive1",
                              "amount": Amount("1 HIVE", hive_instance=hv),
                              "memo": ""}))
     account = Account("bhive", hive_instance=hv)
     with self.assertRaises(
         AssertionError
     ):
         tx.appendSigner(account, "abcdefg")
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
示例#30
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)
     a2 = Amount(2, self.symbol)
     a2 *= a1
     self.dotest(a2, 10, self.symbol)
     with self.assertRaises(Exception):
         a1 *= Amount(2, asset=self.asset2)