Example #1
0
class Testcases(unittest.TestCase):
    def setUp(self):
        fixture_data()
        self.chain = Blockchain(mode="head")

    def test_is_irv(self):
        self.assertFalse(self.chain.is_irreversible_mode())

    def test_info(self):
        info = self.chain.info()
        for i in [
                "time",
                "dynamic_flags",
                "head_block_id",
                "head_block_number",
                "last_budget_time",
        ]:
            self.assertIn(i, info)

    def test_parameters(self):
        info = self.chain.chainParameters()
        for i in [
                "worker_budget_per_day",
                "maintenance_interval",
        ]:
            self.assertIn(i, info)

    def test_network(self):
        info = self.chain.get_network()
        for i in [
                "chain_id",
                "core_symbol",
                "prefix",
        ]:
            self.assertIn(i, info)

    def test_props(self):
        info = self.chain.get_chain_properties()
        for i in [
                "id",
                "chain_id",
                "immutable_parameters",
        ]:
            self.assertIn(i, info)

    def test_block_num(self):
        num = self.chain.get_current_block_num()
        self.assertTrue(num > 100)

    def test_block(self):
        block = self.chain.get_current_block()
        self.assertIsInstance(block, Block)
        self.chain.block_time(1)
        self.chain.block_timestamp(1)

    def test_list_accounts(self):
        for account in self.chain.get_all_accounts():
            self.assertIsInstance(account, str)
            # Break already
            break
def get_all_accounts(api_key: hug.types.text, hug_timer=5):
    """Retrieve all Bitshares account names. Takes a while!"""
    if (check_api_token(api_key) == True):  # Check the api key
        # API KEY VALID
        chain = Blockchain()
        chain_get_all_accounts = chain.get_all_accounts()

        list_of_accounts = []

        for account in chain_get_all_accounts:
            list_of_accounts.append(account)

        return {
            'accounts': list_of_accounts,
            'num_accounts': len(list_of_accounts),
            'valid_key': True,
            'took': float(hug_timer)
        }
    else:
        # API KEY INVALID!
        return {'valid_key': False, 'took': float(hug_timer)}
Example #3
0
def get_all_account_balances(api_key: hug.types.text, hug_timer=60):
    """Retrieve all Bitshares account names & balances.
       WARNING: This may take hours to complete! """
    if (check_api_token(api_key) == True):  # Check the api key
        # API KEY VALID
        chain = Blockchain()
        chain_get_all_accounts = chain.get_all_accounts()

        list_of_accounts = []

        for account in chain_get_all_accounts:
            target_account_balances = Account(account).balances
            if (len(target_account_balances) > 0):
                balance_json_list = []
                for balance in target_account_balances:
                    current_balance_target = Amount(balance)
                    balance_json_list.append({
                        current_balance_target.symbol:
                        current_balance_target.amount
                    })

                list_of_accounts.append({
                    'account_name': account,
                    'balances': balance_json_list
                })
            else:
                list_of_accounts.append({
                    'account_name': account,
                    'balances': []
                })

        return {
            'accounts': list_of_accounts,
            'num_accounts': len(list_of_accounts),
            'valid_key': True,
            'took': float(hug_timer)
        }
    else:
        # API KEY INVALID!
        return {'valid_key': False, 'took': float(hug_timer)}
csv = package["transaction_sets"][0]["csv_files"][0]
print(csv)
with open(data_dir + '/' + csv) as f:
    for line in f:
        create_count = create_count + 1
        print(create_count)
        tran = parse_line(line)
        #create "to" account if it doesn't exist
        try:
            Account(tran["to"], bitshares_instance=testnet)
        except:        
            create_account(tran["to"])

#save initial balances
bc = Blockchain(testnet)
users = bc.get_all_accounts()
with open('balances.csv', "w") as f:
    for name in users:
        user = Account(name, bitshares_instance=testnet)
        balance = user.balances[0].amount if user.balances else 0
        f.write("%s;%f\n" % (name, balance))

tran_count = 0
#TODO: make suitable for multiple transaction_sets
for csv in package["transaction_sets"][0]["csv_files"]:
    print(csv)
    with open(data_dir + '/' + csv) as f:
        for line in f:
            tran = parse_line(line)
            tran_count = tran_count + 1
            print(tran_count)
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
        )
        self.bts.set_default_account("init0")
        set_shared_bitshares_instance(self.bts)
        self.chain = Blockchain(mode="head")

    def test_is_irv(self):
        self.assertFalse(self.chain.is_irreversible_mode())

    def test_info(self):
        info = self.chain.info()
        for i in [
                "time", "dynamic_flags", "head_block_id", "head_block_number",
                "last_budget_time"
        ]:
            self.assertIn(i, info)

    def test_parameters(self):
        info = self.chain.chainParameters()
        for i in [
                "worker_budget_per_day",
                "maintenance_interval",
        ]:
            self.assertIn(i, info)

    def test_network(self):
        info = self.chain.get_network()
        for i in [
                "chain_id",
                "core_symbol",
                "prefix",
        ]:
            self.assertIn(i, info)

    def test_props(self):
        info = self.chain.get_chain_properties()
        for i in [
                "id",
                "chain_id",
                "immutable_parameters",
        ]:
            self.assertIn(i, info)

    def test_block_num(self):
        num = self.chain.get_current_block_num()
        self.assertTrue(num > 100)

    def test_block(self):
        block = self.chain.get_current_block()
        self.assertIsInstance(block, Block)
        self.chain.block_time(1)
        self.chain.block_timestamp(1)

    def test_list_accounts(self):
        for account in self.chain.get_all_accounts():
            self.assertIsInstance(account, str)
            # Break already
            break