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)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.grv = Gravity(nobroadcast=True, ) set_shared_gravity_instance(self.grv) self.asset = Asset("1.3.0") self.symbol = self.asset["symbol"] self.precision = self.asset["precision"] self.asset2 = Asset("1.3.1")
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_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_account(self): Account("witness-account") Account("1.2.3") asset = Asset("1.3.0") symbol = asset["symbol"] account = Account("witness-account", full=True) self.assertEqual(account.name, "witness-account") self.assertEqual(account["name"], account.name) self.assertEqual(account["id"], "1.2.1") self.assertIsInstance(account.balance("1.3.0"), Amount) self.assertIsInstance(account.balance({"symbol": symbol}), Amount) self.assertIsInstance(account.balances, list) for h in account.history(limit=1): pass # BlockchainObjects method account.cached = False self.assertTrue(account.items()) account.cached = False self.assertIn("id", account) account.cached = False self.assertEqual(account["id"], "1.2.1") self.assertEqual(str(account), "<Account 1.2.1>") self.assertIsInstance(Account(account), Account)
def info(ctx, objects): """ Obtain all kinds of information """ if not objects: t = PrettyTable(["Key", "Value"]) t.align = "l" info = ctx.gravity.rpc.get_dynamic_global_properties() for key in info: t.add_row([key, info[key]]) click.echo(t.get_string(sortby="Key")) for obj in objects: # Block if re.match("^[0-9]*$", obj): block = Block(obj, gravity_instance=ctx.gravity) if block: t = PrettyTable(["Key", "Value"]) t.align = "l" for key in sorted(block): value = block[key] if key == "transactions": value = json.dumps(value, indent=4) t.add_row([key, value]) click.echo(t) else: click.echo("Block number %s unknown" % obj) # Object Id elif len(obj.split(".")) == 3: data = ctx.gravity.rpc.get_object(obj) if data: t = PrettyTable(["Key", "Value"]) t.align = "l" for key in sorted(data): value = data[key] if isinstance(value, dict) or isinstance(value, list): value = json.dumps(value, indent=4) t.add_row([key, value]) click.echo(t) else: click.echo("Object %s unknown" % obj) # Asset elif obj.upper() == obj: data = Asset(obj) t = PrettyTable(["Key", "Value"]) t.align = "l" for key in sorted(data): value = data[key] if isinstance(value, dict): value = json.dumps(value, indent=4) t.add_row([key, value]) click.echo(t) # Public Key elif re.match("^ZGV.{48,55}$", obj): account = ctx.gravity.wallet.getAccountFromPublicKey(obj) if account: t = PrettyTable(["Account"]) t.align = "l" t.add_row([account]) click.echo(t) else: click.echo("Public Key not known" % obj) # Account name elif re.match("^[a-zA-Z0-9\-\._]{2,64}$", obj): account = Account(obj, full=True) if account: t = PrettyTable(["Key", "Value"]) t.align = "l" for key in sorted(account): value = account[key] if isinstance(value, dict) or isinstance(value, list): value = json.dumps(value, indent=4) t.add_row([key, value]) click.echo(t) else: click.echo("Account %s unknown" % obj) else: click.echo("Couldn't identify object to read")
def test_assert(self): with self.assertRaises(AssetDoesNotExistsException): Asset("FOObarNonExisting", full=False)