Пример #1
0
 def test_refresh(self):
     asset = Asset("1.3.0", full=False)
     asset.ensure_full()
     self.assertIn("dynamic_asset_data", asset)
     self.assertIn("flags", asset)
     self.assertIn("permissions", asset)
     self.assertIsInstance(asset["flags"], dict)
     self.assertIsInstance(asset["permissions"], dict)
Пример #2
0
def fixture_data():
    # Clear tx buffer
    deex.clear()

    Account.clear_cache()

    with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid:
        data = yaml.safe_load(fid)

    for account in data.get("accounts"):
        Account.cache_object(account, account["id"])
        Account.cache_object(account, account["name"])

    for asset in data.get("assets"):
        Asset.cache_object(asset, asset["symbol"])
        Asset.cache_object(asset, asset["id"])

    proposals = []
    for proposal in data.get("proposals", []):
        ops = []
        for _op in proposal["operations"]:
            for opName, op in _op.items():
                ops.append([operations[opName], op])
        # Proposal!
        proposal_id = proposal["proposal_id"]
        proposal_data = {
            "available_active_approvals": [],
            "available_key_approvals": [],
            "available_owner_approvals": [],
            "expiration_time": "2018-05-29T10:23:13",
            "id": proposal_id,
            "proposed_transaction": {
                "expiration": "2018-05-29T10:23:13",
                "extensions": [],
                "operations": ops,
                "ref_block_num": 0,
                "ref_block_prefix": 0,
            },
            "proposer": "1.2.7",
            "required_active_approvals": ["1.2.1"],
            "required_owner_approvals": [],
        }
        proposals.append(Proposal(proposal_data))

    Proposals.cache_objects(proposals, "1.2.1")
    Proposals.cache_objects(proposals, "witness-account")
Пример #3
0
 def test_properties(self):
     asset = Asset("1.3.0", full=False)
     self.assertIsInstance(asset.symbol, str)
     self.assertIsInstance(asset.precision, int)
     self.assertIsInstance(asset.is_bitasset, bool)
     self.assertIsInstance(asset.permissions, dict)
     self.assertEqual(asset.permissions, asset["permissions"])
     self.assertIsInstance(asset.flags, dict)
     self.assertEqual(asset.flags, asset["flags"])
Пример #4
0
    def test_default_connection2(self):
        b1 = DeEx("wss://node.testnet.deex.eu", nobroadcast=True)
        test = Asset("1.3.0", blockchain_instance=b1)
        test.refresh()

        b2 = DeEx("wss://node.deex.eu", nobroadcast=True)
        bts = Asset("1.3.0", blockchain_instance=b2)
        bts.refresh()

        self.assertEqual(test["symbol"], "TEST")
        self.assertEqual(bts["symbol"], "DX")
Пример #5
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)
Пример #6
0
    def test_default_connection(self):
        b1 = DeEx("wss://node.testnet.deex.eu", nobroadcast=True)
        set_shared_deex_instance(b1)
        test = Asset("1.3.0", blockchain_instance=b1)
        # Needed to clear cache
        test.refresh()

        b2 = DeEx("wss://node.deex.eu", nobroadcast=True)
        set_shared_deex_instance(b2)
        bts = Asset("1.3.0", blockchain_instance=b2)
        # Needed to clear cache
        bts.refresh()

        self.assertEqual(test["symbol"], "TEST")
        self.assertEqual(bts["symbol"], "DX")
Пример #7
0
    def test_init(self):
        # self.assertEqual(1, 1)

        Price("0.315 USD/DX")
        Price(1.0, "USD/GOLD")
        Price(0.315, base="USD", quote="DX")
        Price(0.315, base=Asset("USD"), quote=Asset("DX"))
        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"))
Пример #8
0
 def _issue_asset(asset, amount, to):
     asset = Asset(asset, deex_instance=deex)
     asset.issue(amount, to)
Пример #9
0
 def test_assert(self):
     with self.assertRaises(AssetDoesNotExistsException):
         Asset("FOObarNonExisting", full=False)
Пример #10
0
import unittest
import os
from pprint import pprint
from itertools import cycle
from deexbase.account import BrainKey, Address, PublicKey, PrivateKey
from deexbase import transactions, memo, account, operations, objects
from deexbase.objects import Operation
from deexbase.signedtransactions import Signed_Transaction

from deex.transactionbuilder import TransactionBuilder
from deexbase.operations import Transfer

from deex import DeEx, storage
from deex.instance import set_shared_blockchain_instance
from deex.account import Account
from deex.asset import Asset

from deexbase.memo import (get_shared_secret, _pad, _unpad, encode_memo,
                           decode_memo)

deex = DeEx(["wss://node4p.deexnet.com/ws"])
set_shared_blockchain_instance(deex)

asset = Asset("1.3.0", full=False)
print(asset['id'])
print(asset['precision'])
Пример #11
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.asset = Asset("DX")
     self.symbol = Asset("DX")["symbol"]
     self.precision = Asset("DX")["precision"]
     self.asset2 = Asset("EUR")