예제 #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
파일: snapshot.py 프로젝트: dpays/dpaygo
 def reset(self):
     """ Resets the arrays not the stored account history
     """
     self.own_vests = [Amount("0 VESTS", dpay_instance=self.dpay)]
     self.own_dpay = [Amount("0 BEX", dpay_instance=self.dpay)]
     self.own_bbd = [Amount("0 BBD", dpay_instance=self.dpay)]
     self.delegated_vests_in = [{}]
     self.delegated_vests_out = [{}]
     self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))]
     import dpaygobase.operationids
     self.ops_statistics = dpaygobase.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_SP_timestamp = []
     self.curation_per_1000_SP = []
     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 = []
예제 #3
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)
예제 #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
파일: test_types.py 프로젝트: dpays/dpaygo
    def test_JsonObj(self):
        j = {"a": 2, "b": "abcde", "c": ["a", "b"]}
        j2 = types.JsonObj(json.dumps(j))
        self.assertEqual(j, j2)

        stm = DPay(offline=True)
        a = Amount("1 BBD", dpay_instance=stm)
        j = a.json()
        j2 = types.JsonObj(json.dumps(j))
        self.assertEqual(j, j2)
예제 #6
0
 def test_json_appbase(self):
     asset = Asset("BBD", dpay_instance=self.appbase)
     amount = Amount("1",
                     asset,
                     new_appbase_format=False,
                     dpay_instance=self.appbase)
     if self.appbase.rpc.get_use_appbase():
         self.assertEqual(
             amount.json(),
             [str(1 * 10**asset.precision), asset.precision, asset.asset])
     else:
         self.assertEqual(amount.json(), "1.000 BBD")
예제 #7
0
    def test_init(self, node_param):
        if node_param == "non_appbase":
            stm = self.bts
        else:
            stm = self.appbase
        # String init
        asset = Asset("BBD", dpay_instance=stm)
        symbol = asset["symbol"]
        precision = asset["precision"]
        amount = Amount("1 {}".format(symbol), dpay_instance=stm)
        self.dotest(amount, 1, symbol)

        # Amount init
        amount = Amount(amount, dpay_instance=stm)
        self.dotest(amount, 1, symbol)

        # blockchain dict init
        amount = Amount({
            "amount": 1 * 10**precision,
            "asset_id": asset["id"]
        },
                        dpay_instance=stm)
        self.dotest(amount, 1, symbol)

        # API dict init
        amount = Amount({
            "amount": 1.3 * 10**precision,
            "asset": asset["id"]
        },
                        dpay_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # Asset as symbol
        amount = Amount(1.3, Asset("BBD"), dpay_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # Asset as symbol
        amount = Amount(1.3, symbol, dpay_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # keyword inits
        amount = Amount(amount=1.3,
                        asset=Asset("BBD", dpay_instance=stm),
                        dpay_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # keyword inits
        amount = Amount(amount=1.3,
                        asset=dict(Asset("BBD", dpay_instance=stm)),
                        dpay_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # keyword inits
        amount = Amount(amount=1.3, asset=symbol, dpay_instance=stm)
        self.dotest(amount, 1.3, symbol)
예제 #8
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)
     with self.assertRaises(Exception):
         a1 += Amount(1, asset=self.asset2)
예제 #9
0
 def test_json_appbase2(self):
     asset = Asset("BBD", dpay_instance=self.appbase)
     amount = Amount("1",
                     asset,
                     new_appbase_format=True,
                     dpay_instance=self.appbase)
     if self.appbase.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 BBD")
예제 #10
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)
예제 #11
0
 def test_amount(self, node_param):
     if node_param == "instance":
         stm = DPay(node="https://abc.d", autoconnect=False, num_retries=1)
         set_shared_dpay_instance(self.bts)
         o = Amount("1 BBD")
         self.assertIn(o.dpay.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Amount("1 BBD", dpay_instance=stm)
     else:
         set_shared_dpay_instance(
             DPay(node="https://abc.d", autoconnect=False, num_retries=1))
         stm = self.bts
         o = Amount("1 BBD", dpay_instance=stm)
         self.assertIn(o.dpay.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Amount("1 BBD")
예제 #12
0
파일: dpayid.py 프로젝트: dpays/dpaygo
    def url_from_tx(self, tx, redirect_uri=None):
        """ Creates a link for broadcasting an operation

            :param dict tx: includes the operation, which should be broadcast
            :param str redirect_uri: Redirects to this uri, when set
        """
        if not isinstance(tx, dict):
            tx = tx.json()
        if "operations" not in tx or not tx["operations"]:
            return ''
        urls = []
        operations = tx["operations"]
        for op in operations:
            operation = op[0]
            params = op[1]
            for key in params:
                value = params[key]
                if isinstance(value, list) and len(value) == 3:
                    try:
                        amount = Amount(value, dpay_instance=self.dpay)
                        params[key] = str(amount)
                    except:
                        amount = None
                elif isinstance(value, bool):
                    if value:
                        params[key] = 1
                    else:
                        params[key] = 0
            urls.append(self.create_hot_sign_url(operation, params, redirect_uri=redirect_uri))
        if len(urls) == 1:
            return urls[0]
        else:
            return urls
예제 #13
0
    def test_sell(self, node_param):
        if node_param == "non_appbase":
            bts = self.bts
        else:
            bts = self.appbase
        bts.txbuffer.clear()
        m = Market(u'BEX:BBD', dpay_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 BBD', dpay_instance=bts)),
                         op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 BEX', dpay_instance=bts)),
                         op["amount_to_sell"])

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

        p = Price(5, u"BBD:BEX", dpay_instance=bts)
        a = Amount(0.1, "BEX", dpay_instance=bts)
        tx = m.sell(p, a, account="test")
        op = tx["operations"][0][1]
        self.assertEqual(str(Amount('0.500 BBD', dpay_instance=bts)),
                         op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 BEX', dpay_instance=bts)),
                         op["amount_to_sell"])
예제 #14
0
 def time_transfer(self):
     self.op = operations.Transfer(
         **{
             "from": "foo",
             "to": "baar",
             "amount": Amount("111.110 BEX", dpay_instance=self.stm),
             "memo": "Fooo",
             "prefix": self.default_prefix
         })
     self.doit()
예제 #15
0
    def test_init(self):
        # self.assertEqual(1, 1)

        Price("0.315 BEX/BBD")
        Price(1.0, "BEX/BBD")
        Price(0.315, base="BEX", quote="BBD")
        Price(0.315, base=Asset("BEX"), quote=Asset("BBD"))
        Price({
            "base": {
                "amount": 1,
                "asset_id": "BBD"
            },
            "quote": {
                "amount": 10,
                "asset_id": "BEX"
            }
        })
        Price("", quote="10 BBD", base="1 BEX")
        Price("10 BBD", "1 BEX")
        Price(Amount("10 BBD"), Amount("1 BEX"))
예제 #16
0
 def test_transfer(self):
     bts = self.bts
     bts.nobroadcast = False
     bts.wallet.unlock("123")
     # bts.prefix ="STX"
     acc = Account("dpaygo", dpay_instance=bts)
     tx = acc.transfer("dpaygo1", 1.33, "BBD", 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"], "dpaygo")
     self.assertEqual(op["to"], "dpaygo1")
     amount = Amount(op["amount"], dpay_instance=bts)
     self.assertEqual(float(amount), 1.33)
     bts.nobroadcast = True
예제 #17
0
    def test_div2(self):
        p1 = Price(10.0, "BEX/BBD")
        p2 = Price(5.0, "BEX/BBD")

        # 10 BEX/BBD / 5 BEX/VESTS = 2 VESTS/BBD
        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 BBD")
        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)
예제 #18
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)
예제 #19
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)
예제 #20
0
    def test_Transfer_broadcast(self):
        nodelist = NodeList()
        stm = DPay(node=nodelist.get_testnet(),
                   keys=[self.active_key],
                   nobroadcast=True,
                   expiration=120,
                   num_retries=10)

        tx = TransactionBuilder(expiration=10, dpay_instance=stm)
        tx.appendOps(
            Transfer(
                **{
                    "from": "dpaygo",
                    "to": "dpaygo1",
                    "amount": Amount("1 BEX", dpay_instance=stm),
                    "memo": ""
                }))
        tx.appendSigner("dpaygo", "active")
        tx.sign()
        tx.broadcast()
예제 #21
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)
예제 #22
0
 def test_TransactionConstructor(self):
     stm = self.bts
     opTransfer = Transfer(
         **{
             "from": "dpaygo",
             "to": "dpaygo1",
             "amount": Amount("1 BEX", dpay_instance=stm),
             "memo": ""
         })
     tx1 = TransactionBuilder(dpay_instance=stm)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, dpay_instance=stm)
     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("dpaygo", dpay_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
예제 #23
0
    def test_transfer_memo(self):
        bts = self.bts
        bts.nobroadcast = False
        bts.wallet.unlock("123")
        acc = Account("dpaygo", dpay_instance=bts)
        tx = acc.transfer("dpaygo1", 1.33, "BBD", memo="#Foobar")
        self.assertEqual(tx["operations"][0][0], "transfer")
        op = tx["operations"][0][1]
        self.assertIn("memo", op)
        self.assertIn("#", op["memo"])
        m = Memo(from_account=op["from"],
                 to_account=op["to"],
                 dpay_instance=bts)
        memo = m.decrypt(op["memo"])
        self.assertEqual(memo, "Foobar")

        self.assertEqual(op["from"], "dpaygo")
        self.assertEqual(op["to"], "dpaygo1")
        amount = Amount(op["amount"], dpay_instance=bts)
        self.assertEqual(float(amount), 1.33)
        bts.nobroadcast = True
예제 #24
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)
예제 #25
0
 def test_appendWif(self):
     nodelist = NodeList()
     stm = DPay(node=nodelist.get_testnet(),
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(dpay_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "dpaygo",
                 "to": "dpaygo1",
                 "amount": Amount("1 BEX", dpay_instance=stm),
                 "memo": ""
             }))
     with self.assertRaises(MissingKeyError):
         tx.sign()
     with self.assertRaises(InvalidWifError):
         tx.appendWif("abcdefg")
     tx.appendWif(self.active_key)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
예제 #26
0
파일: test_dpay.py 프로젝트: dpays/dpaygo
 def test_transfer(self, node_param):
     if node_param == "non_appbase":
         bts = self.bts
         acc = self.account
     elif node_param == "appbase":
         bts = self.appbase
         acc = self.account_appbase
     acc.dpay.txbuffer.clear()
     tx = acc.transfer(
         "test", 1.33, "BBD", 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"], dpay_instance=bts)
     self.assertEqual(float(amount), 1.33)
예제 #27
0
 def test_appendSigner(self):
     nodelist = NodeList()
     stm = DPay(node=nodelist.get_testnet(),
                keys=[self.active_key],
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(dpay_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "dpaygo",
                 "to": "dpaygo1",
                 "amount": Amount("1 BEX", dpay_instance=stm),
                 "memo": ""
             }))
     account = Account("dpaygo", dpay_instance=stm)
     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)
예제 #28
0
 def test_verifyAuthorityException(self):
     nodelist = NodeList()
     stm = DPay(node=nodelist.get_testnet(),
                keys=[self.posting_key],
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(dpay_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "dpaygo",
                 "to": "dpaygo1",
                 "amount": Amount("1 BEX", dpay_instance=stm),
                 "memo": ""
             }))
     account = Account("dpaygo2", dpay_instance=stm)
     tx.appendSigner(account, "active")
     tx.appendWif(self.posting_key)
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     with self.assertRaises(exceptions.MissingRequiredActiveAuthority):
         tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
예제 #29
0
from dpaygo import DPay
import numpy as np
from dpaygo.utils import reputation_to_score
from dpaygo.amount import Amount
from dpaygo.constants import DPAY_100_PERCENT
import matplotlib as mpl
# mpl.use('Agg')
# mpl.use('TkAgg')
import matplotlib.pyplot as plt

if __name__ == "__main__":
    stm = DPay()
    price = Amount(stm.get_current_median_history()["base"])
    reps = [0]
    for i in range(26, 91):
        reps.append(int(10**((i - 25) / 9 + 9)))
    # reps = np.logspace(9, 16, 60)
    used_power = stm._calc_resulting_vote()
    last_bp = 0
    bp_list = []
    rep_score_list = []
    for goal_rep in reps:
        score = reputation_to_score(goal_rep)
        rep_score_list.append(score)
        needed_rshares = int(goal_rep) << 6
        needed_vests = needed_rshares / used_power / 100
        needed_bp = stm.vests_to_bp(needed_vests)
        bp_list.append(needed_bp / 1000)
        # print("| %.1f | %.2f | %.2f  | " % (score, needed_bp / 1000, needed_bp / 1000 - last_bp / 1000))
        last_bp = needed_bp
예제 #30
0
 def test_order(self):
     order = Order(Amount("2 BBD"), Amount("1 BEX"))
     self.assertTrue(repr(order) is not None)