示例#1
0
    def test_init(self):
        # self.assertEqual(1, 1)

        Price("0.315 USD/DST")
        Price(1.0, "USD/GOLD")
        Price(0.315, base="USD", quote="DST")
        Price(0.315, base=Asset("USD"), quote=Asset("DST"))
        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"))
示例#2
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)
示例#3
0
def fixture_data():
    # Clear tx buffer
    dexstore.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 = list()
        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")
示例#4
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"])
    def test_default_connection2(self):
        b1 = DexStore("ws://127.0.0.1:7738", nobroadcast=True)
        test = Asset("1.3.0", blockchain_instance=b1)
        test.refresh()

        b2 = DexStore("ws://127.0.0.1:7738", nobroadcast=True)
        dst = Asset("1.3.0", blockchain_instance=b2)
        dst.refresh()

        self.assertEqual(test["symbol"], "TEST")
        self.assertEqual(dst["symbol"], "DST")
示例#6
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)
    def test_default_connection(self):
        b1 = DexStore("ws://127.0.0.1:7738", nobroadcast=True)
        set_shared_dexstore_instance(b1)
        test = Asset("1.3.0", blockchain_instance=b1)
        # Needed to clear cache
        test.refresh()

        b2 = DexStore("ws://127.0.0.1:7738", nobroadcast=True)
        set_shared_dexstore_instance(b2)
        dst = Asset("1.3.0", blockchain_instance=b2)
        # Needed to clear cache
        dst.refresh()

        self.assertEqual(test["symbol"], "TEST")
        self.assertEqual(dst["symbol"], "DST")
示例#8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.asset = Asset("DST")
     self.symbol = Asset("DST")["symbol"]
     self.precision = Asset("DST")["precision"]
     self.asset2 = Asset("EUR")
示例#9
0
 def test_assert(self):
     with self.assertRaises(AssetDoesNotExistsException):
         Asset("FOObarNonExisting", full=False)