Пример #1
0
    def test_gateway_handler(self):
        bitshares = BitShares(settings.BITSHARES_NODE_URL,
                              nobroadcast=settings.BLOCKCHAIN_NOBROADCAST,
                              keys=[settings.BITSHARES_GATEWAY_WIF])
        bitshares.set_default_account(settings.BITSHARES_GATEWAY_ACCOUNT)

        transnet = Transnet(settings.TRANSNET_NODE_URL,
                            nobroadcast=settings.BLOCKCHAIN_NOBROADCAST,
                            keys={
                                'active': settings.TRANSNET_GATEWAY_WIF,
                                'memo': settings.TRANSNET_GATEWAY_WIF_MEMO
                            })
        transnet.set_default_account(settings.TRANSNET_GATEWAY_ACCOUNT)

        transaction = BitsharesTransnetTransaction.objects.create(
            trx_id='test',
            trx_in_block=3,
            op_in_trx=3,
            asset='UTECH.UTCORE',
            amount=pow(10, 5),
            account_external='superpchelka23',
            account_internal='superpchelka23')

        handler = BitsharesGatewayHandler(bitshares,
                                          settings.BITSHARES_GATEWAY_ACCOUNT,
                                          transnet,
                                          settings.TRANSNET_GATEWAY_ACCOUNT,
                                          settings.TRANSNET_GATEWAY_WIF_MEMO,
                                          {'UTECH.UTCORE': 'UTECH.UTCORE'})

        handler.handle([transaction], lambda: True)

        self.assertTrue(transaction.closed,
                        'Transaction must be properly processed')
Пример #2
0
class Testcases(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
            # We want to bundle many operations into a single transaction
            bundle=True,
            # Overwrite wallet to use this list of wifs only
            wif={"active": wif}
        )
        self.bts.set_default_account("init0")
        set_shared_bitshares_instance(self.bts)

    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 test_account_upgrade(self):
        account = Account("witness-account")
        tx = account.upgrade()
        ops = tx["operations"]
        op = ops[0][1]
        self.assertEqual(len(ops), 1)
        self.assertEqual(
            getOperationNameForId(ops[0][0]),
            "account_upgrade"
        )
        self.assertTrue(
            op["upgrade_to_lifetime_member"]
        )
        self.assertEqual(
            op["account_to_upgrade"],
            "1.2.1",
        )
Пример #3
0
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            nobroadcast=True,
            # We want to bundle many operations into a single transaction
            bundle=True,
            # Overwrite wallet to use this list of wifs only
            wif=[wif])
        self.bts.set_default_account("init0")
        set_shared_bitshares_instance(self.bts)
Пример #4
0
class BitsharesBasedGateway(BaseGateway):
    def __init__(self):
        self.site_settings = SettingsModel.load()
        self.bitshares = BitShares(
            self.site_settings.bitshares_transnet_node_url,
            nobroadcast=settings.BLOCKCHAIN_NOBROADCAST,
            keys={
                'active': self.site_settings.bitshares_transnet_active_wif,
            },
        )
        self.bitshares.set_default_account(
            self.site_settings.bitshares_transnet_gateway_address)

        super(BitsharesBasedGateway, self).__init__()
Пример #5
0
class Testcases(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            nobroadcast=True,
            # We want to bundle many operations into a single transaction
            bundle=True,
            # Overwrite wallet to use this list of wifs only
            wif=[wif]
        )
        set_shared_blockchain_instance(self.bts)
        self.bts.set_default_account("init0")

    def test_fee_on_transfer(self):
        tx = self.bts.transfer("init1", 1, "1.3.0", account="init0", fee_asset="1.3.121")
        op = tx["operations"][0][1]
        self.assertEqual(op["fee"]["asset_id"], "1.3.121")
Пример #6
0
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)

    def test_block(self):
        block = Block(1)
        self.assertEqual(block["previous"], "0000000000000000000000000000000000000000")
        self.assertEqual(block.time(), parse_time('2016-01-18T10:59:20'))

    def test_blockheader(self):
        header = BlockHeader(1)
        self.assertEqual(header["previous"], "0000000000000000000000000000000000000000")
        self.assertEqual(header.time(), parse_time('2016-01-18T10:59:20'))
Пример #7
0
# default wifs key for testing
wifs = [
    "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3",
    "5KCBDTcyDqzsqehcb52tW5nU6pXife6V2rX9Yf7c3saYSzbDZ5W",
]
wif = wifs[0]

# bitshares instance
bitshares = BitShares("wss://node.bitshares.eu",
                      keys=wifs,
                      nobroadcast=True,
                      num_retries=1)
config = bitshares.config

# Set defaults
bitshares.set_default_account("init0")
set_shared_blockchain_instance(bitshares)

# Ensure we are not going to transaction anythin on chain!
assert bitshares.nobroadcast


def fixture_data():
    # Clear tx buffer
    bitshares.clear()

    Account.clear_cache()

    with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid:
        data = yaml.safe_load(fid)
Пример #8
0
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
            keys={"active": wif},
        )
        # from getpass import getpass
        # self.bts.wallet.unlock(getpass())
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")

    def test_finalizeOps_proposal(self):
        bts = self.bts
        # proposal = bts.new_proposal(bts.tx())
        proposal = bts.proposal()
        self.bts.transfer("init1", 1, "TEST", append_to=proposal)
        tx = bts.tx().json()  # default tx buffer
        ops = tx["operations"]
        self.assertEqual(len(ops), 1)
        self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create")
        prop = ops[0][1]
        self.assertEqual(len(prop["proposed_ops"]), 1)
        self.assertEqual(
            getOperationNameForId(prop["proposed_ops"][0]["op"][0]),
            "transfer")

    def test_finalizeOps_proposal2(self):
        bts = self.bts
        proposal = bts.new_proposal()
        # proposal = bts.proposal()
        self.bts.transfer("init1", 1, "TEST", append_to=proposal)
        tx = bts.tx().json()  # default tx buffer
        ops = tx["operations"]
        self.assertEqual(len(ops), 1)
        self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create")
        prop = ops[0][1]
        self.assertEqual(len(prop["proposed_ops"]), 1)
        self.assertEqual(
            getOperationNameForId(prop["proposed_ops"][0]["op"][0]),
            "transfer")

    def test_finalizeOps_combined_proposal(self):
        bts = self.bts
        parent = bts.new_tx()
        proposal = bts.new_proposal(parent)
        self.bts.transfer("init1", 1, "TEST", append_to=proposal)
        self.bts.transfer("init1", 1, "TEST", append_to=parent)
        tx = parent.json()
        ops = tx["operations"]
        self.assertEqual(len(ops), 2)
        self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create")
        self.assertEqual(getOperationNameForId(ops[1][0]), "transfer")
        prop = ops[0][1]
        self.assertEqual(len(prop["proposed_ops"]), 1)
        self.assertEqual(
            getOperationNameForId(prop["proposed_ops"][0]["op"][0]),
            "transfer")

    def test_finalizeOps_changeproposer_new(self):
        bts = self.bts
        proposal = bts.proposal(proposer="init5")
        bts.transfer("init1", 1, "TEST", append_to=proposal)
        tx = bts.tx().json()
        ops = tx["operations"]
        self.assertEqual(len(ops), 1)
        self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create")
        prop = ops[0][1]
        self.assertEqual(len(prop["proposed_ops"]), 1)
        self.assertEqual(prop["fee_paying_account"], "1.2.11")
        self.assertEqual(
            getOperationNameForId(prop["proposed_ops"][0]["op"][0]),
            "transfer")

    """
    def test_finalizeOps_changeproposer_legacy(self):
        bts = self.bts
        bts.proposer = "init5"
        tx = bts.transfer("init1", 1, "TEST")
        ops = tx["operations"]
        self.assertEqual(len(ops), 1)
        self.assertEqual(
            getOperationNameForId(ops[0][0]),
            "proposal_create")
        prop = ops[0][1]
        self.assertEqual(len(prop["proposed_ops"]), 1)
        self.assertEqual(prop["fee_paying_account"], "1.2.11")
        self.assertEqual(
            getOperationNameForId(prop["proposed_ops"][0]["op"][0]),
            "transfer")
    """

    def test_new_proposals(self):
        bts = self.bts
        p1 = bts.new_proposal()
        p2 = bts.new_proposal()
        self.assertIsNotNone(id(p1), id(p2))

    def test_new_txs(self):
        bts = self.bts
        p1 = bts.new_tx()
        p2 = bts.new_tx()
        self.assertIsNotNone(id(p1), id(p2))
Пример #9
0
class Testcases(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
            keys={"active": wif, "owner": wif, "memo": wif},
        )
        # from getpass import getpass
        # self.bts.wallet.unlock(getpass())
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")

    def test_connect(self):
        self.bts.connect()

    def test_set_default_account(self):
        self.bts.set_default_account("init0")

    def test_info(self):
        info = self.bts.info()
        for key in ['current_witness',
                    'head_block_id',
                    'head_block_number',
                    'id',
                    'last_irreversible_block_num',
                    'next_maintenance_time',
                    'recently_missed_count',
                    'time']:
            self.assertTrue(key in info)

    def test_finalizeOps(self):
        bts = self.bts
        tx1 = bts.new_tx()
        tx2 = bts.new_tx()
        self.bts.transfer("init1", 1, core_unit, append_to=tx1)
        self.bts.transfer("init1", 2, core_unit, append_to=tx2)
        self.bts.transfer("init1", 3, core_unit, append_to=tx1)
        tx1 = tx1.json()
        tx2 = tx2.json()
        ops1 = tx1["operations"]
        ops2 = tx2["operations"]
        self.assertEqual(len(ops1), 2)
        self.assertEqual(len(ops2), 1)

    def test_transfer(self):
        bts = self.bts
        tx = bts.transfer(
            "1.2.8", 1.33, core_unit, memo="Foobar", account="1.2.7")
        self.assertEqual(
            getOperationNameForId(tx["operations"][0][0]),
            "transfer"
        )
        op = tx["operations"][0][1]
        self.assertIn("memo", op)
        self.assertEqual(op["from"], "1.2.7")
        self.assertEqual(op["to"], "1.2.8")
        amount = Amount(op["amount"])
        self.assertEqual(float(amount), 1.33)

    def test_create_account(self):
        bts = self.bts
        name = ''.join(random.choice(string.ascii_lowercase) for _ in range(12))
        key1 = PrivateKey()
        key2 = PrivateKey()
        key3 = PrivateKey()
        key4 = PrivateKey()
        tx = bts.create_account(
            name,
            registrar="init0",   # 1.2.7
            referrer="init1",    # 1.2.8
            referrer_percent=33,
            owner_key=format(key1.pubkey, core_unit),
            active_key=format(key2.pubkey, core_unit),
            memo_key=format(key3.pubkey, core_unit),
            additional_owner_keys=[format(key4.pubkey, core_unit)],
            additional_active_keys=[format(key4.pubkey, core_unit)],
            additional_owner_accounts=["committee-account"],  # 1.2.0
            additional_active_accounts=["committee-account"],
            proxy_account="init0",
            storekeys=False
        )
        self.assertEqual(
            getOperationNameForId(tx["operations"][0][0]),
            "account_create"
        )
        op = tx["operations"][0][1]
        role = "active"
        self.assertIn(
            format(key4.pubkey, core_unit),
            [x[0] for x in op[role]["key_auths"]])
        self.assertIn(
            format(key4.pubkey, core_unit),
            [x[0] for x in op[role]["key_auths"]])
        self.assertIn(
            "1.2.0",
            [x[0] for x in op[role]["account_auths"]])
        role = "owner"
        self.assertIn(
            format(key4.pubkey, core_unit),
            [x[0] for x in op[role]["key_auths"]])
        self.assertIn(
            format(key4.pubkey, core_unit),
            [x[0] for x in op[role]["key_auths"]])
        self.assertIn(
            "1.2.0",
            [x[0] for x in op[role]["account_auths"]])
        self.assertEqual(
            op["options"]["voting_account"],
            "1.2.6")
        self.assertEqual(
            op["registrar"],
            "1.2.6")
        self.assertEqual(
            op["referrer"],
            "1.2.7")
        self.assertEqual(
            op["referrer_percent"],
            33 * 100)

    def test_weight_threshold(self):
        bts = self.bts

        auth = {'account_auths': [['1.2.0', '1']],
                'extensions': [],
                'key_auths': [
                    ['TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1],
                    ['TEST7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]],
                'weight_threshold': 3}  # threshold fine
        bts._test_weights_treshold(auth)
        auth = {'account_auths': [['1.2.0', '1']],
                'extensions': [],
                'key_auths': [
                    ['TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1],
                    ['TEST7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]],
                'weight_threshold': 4}  # too high

        with self.assertRaises(ValueError):
            bts._test_weights_treshold(auth)

    def test_allow(self):
        bts = self.bts
        tx = bts.allow(
            "TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
            weight=1,
            threshold=1,
            permission="owner"
        )
        self.assertEqual(
            getOperationNameForId(tx["operations"][0][0]),
            "account_update"
        )
        op = tx["operations"][0][1]
        self.assertIn("owner", op)
        self.assertIn(
            ["TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", '1'],
            op["owner"]["key_auths"])
        self.assertEqual(op["owner"]["weight_threshold"], 1)

    def test_disallow(self):
        bts = self.bts
        with self.assertRaisesRegex(ValueError, ".*Changes nothing.*"):
            bts.disallow(
                "TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
                weight=1,
                threshold=1,
                permission="owner"
            )
        with self.assertRaisesRegex(ValueError, ".*Changes nothing!.*"):
            bts.disallow(
                "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
                weight=1,
                threshold=1,
                permission="owner"
            )

    def test_update_memo_key(self):
        bts = self.bts
        tx = bts.update_memo_key("TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
        self.assertEqual(
            getOperationNameForId(tx["operations"][0][0]),
            "account_update"
        )
        op = tx["operations"][0][1]
        self.assertEqual(
            op["new_options"]["memo_key"],
            "TEST55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")

    def test_approvewitness(self):
        bts = self.bts
        tx = bts.approvewitness("init0")
        self.assertEqual(
            getOperationNameForId(tx["operations"][0][0]),
            "account_update"
        )
        op = tx["operations"][0][1]
        self.assertIn(
            "1:0",
            op["new_options"]["votes"])

    def test_approvecommittee(self):
        bts = self.bts
        tx = bts.approvecommittee("init0")
        self.assertEqual(
            getOperationNameForId(tx["operations"][0][0]),
            "account_update"
        )
        op = tx["operations"][0][1]
        self.assertIn(
            "0:11",
            op["new_options"]["votes"])

    def test_sign_message(self):
        def new_refresh(self):
            dict.__init__(
                self, {"name": "init0",
                 "options": {
                     "memo_key": "TEST6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
                 }})

        with mock.patch(
            "bitshares.account.Account.refresh",
            new=new_refresh
        ):
            p = Message("message foobar").sign()
            Message(p).verify()
Пример #10
0
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares("wss://node.testnet.bitshares.eu",
                             nobroadcast=True,
                             keys={"active": wif})
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")

    def test_add_one_proposal_one_op(self):
        bts = self.bts
        tx1 = bts.new_tx()
        proposal1 = bts.new_proposal(tx1, proposer="init0")
        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": "1.2.0",
                "to": "1.2.0",
                "amount": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "prefix": "TEST"
            })
        proposal1.appendOps(op)
        tx = tx1.json()
        self.assertEqual(tx["operations"][0][0], 22)
        self.assertEqual(len(tx["operations"]), 1)
        ps = tx["operations"][0][1]
        self.assertEqual(len(ps["proposed_ops"]), 1)
        self.assertEqual(ps["proposed_ops"][0]["op"][0], 0)

    def test_add_one_proposal_two_ops(self):
        bts = self.bts
        tx1 = bts.new_tx()
        proposal1 = bts.new_proposal(tx1, proposer="init0")
        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": "1.2.0",
                "to": "1.2.0",
                "amount": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "prefix": "TEST"
            })
        proposal1.appendOps(op)
        proposal1.appendOps(op)
        tx = tx1.json()
        self.assertEqual(tx["operations"][0][0], 22)
        self.assertEqual(len(tx["operations"]), 1)
        ps = tx["operations"][0][1]
        self.assertEqual(len(ps["proposed_ops"]), 2)
        self.assertEqual(ps["proposed_ops"][0]["op"][0], 0)
        self.assertEqual(ps["proposed_ops"][1]["op"][0], 0)

    def test_have_two_proposals(self):
        bts = self.bts
        tx1 = bts.new_tx()

        # Proposal 1
        proposal1 = bts.new_proposal(tx1, proposer="init0")
        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": "1.2.0",
                "to": "1.2.0",
                "amount": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "prefix": "TEST"
            })
        for i in range(0, 3):
            proposal1.appendOps(op)

        # Proposal 1
        proposal2 = bts.new_proposal(tx1, proposer="init0")
        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": "1.2.0",
                "to": "1.2.0",
                "amount": {
                    "amount": 5555555,
                    "asset_id": "1.3.0"
                },
                "prefix": "TEST"
            })
        for i in range(0, 2):
            proposal2.appendOps(op)
        tx = tx1.json()

        self.assertEqual(len(tx["operations"]), 2)  # 2 proposals

        # Test proposal 1
        prop = tx["operations"][0]
        self.assertEqual(prop[0], 22)
        ps = prop[1]
        self.assertEqual(len(ps["proposed_ops"]), 3)
        for i in range(0, 3):
            self.assertEqual(ps["proposed_ops"][i]["op"][0], 0)

        # Test proposal 2
        prop = tx["operations"][1]
        self.assertEqual(prop[0], 22)
        ps = prop[1]
        self.assertEqual(len(ps["proposed_ops"]), 2)
        for i in range(0, 2):
            self.assertEqual(ps["proposed_ops"][i]["op"][0], 0)
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
Пример #12
0
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(nobroadcast=True, wif=[wif])
        set_shared_bitshares_instance(self.bts)
        self.bts.set_default_account("init0")

        cache = ObjectCache(default_expiration=5, no_overwrite=True)
        init0 = {
            'active': {
                'account_auths': [],
                'address_auths': [],
                'key_auths': [[str(PrivateKey(wif).pubkey), 1]],
                'weight_threshold': 1
            },
            'active_special_authority': [0, {}],
            'blacklisted_accounts': [],
            'blacklisting_accounts': [],
            'cashback_vb': '1.13.102',
            'id': '1.2.90742',
            'lifetime_referrer': '1.2.90742',
            'lifetime_referrer_fee_percentage': 8000,
            'membership_expiration_date': '1969-12-31T23:59:59',
            'name': 'init0',
            'network_fee_percentage': 2000,
            'options': {
                'extensions': [],
                'memo_key': str(PrivateKey(wif).pubkey),
                'num_committee': 0,
                'num_witness': 0,
                'votes': [],
                'voting_account': '1.2.5'
            },
            'owner': {
                'account_auths': [],
                'address_auths': [],
                'key_auths': [[str(PrivateKey(wif).pubkey), 1]],
                'weight_threshold': 1
            },
            'owner_special_authority': [0, {}],
            'referrer': '1.2.90742',
            'referrer_rewards_percentage': 0,
            'registrar': '1.2.90742',
            'statistics': '2.6.90742',
            'top_n_control_flags': 0,
            'whitelisted_accounts': [],
            'whitelisting_accounts': []
        }
        cache[init0["id"]] = init0
        cache[init0["name"]] = init0
        BlockchainObject._cache = cache

    def test_sign_message(self):
        p = Message("message foobar").sign()
        Message(p).verify()

    def test_verify_message(self):
        Message(
            "-----BEGIN BITSHARES SIGNED MESSAGE-----\n"
            "message foobar\n"
            "-----BEGIN META-----\n"
            "account=init0\n"
            "memokey=BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\n"
            "block=23814223\n"
            "timestamp=2018-01-24T11:42:33\n"
            "-----BEGIN SIGNATURE-----\n"
            "2034f601e175a25cf9f60a828650301f57c9efab53929b6a82fb413feb8a786fcb3ba4238dd8bece03aee38526ee363324d43944d4a3f9dc624fbe53ef5f0c9a5e\n"
            "-----END BITSHARES SIGNED MESSAGE-----\n").verify()

        Message(
            "-----BEGIN BITSHARES SIGNED MESSAGE-----"
            "message foobar\n"
            "-----BEGIN META-----"
            "account=init0\n"
            "memokey=BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\n"
            "block=23814223\n"
            "timestamp=2018-01-24T11:42:33"
            "-----BEGIN SIGNATURE-----"
            "2034f601e175a25cf9f60a828650301f57c9efab53929b6a82fb413feb8a786fcb3ba4238dd8bece03aee38526ee363324d43944d4a3f9dc624fbe53ef5f0c9a5e\n"
            "-----END BITSHARES SIGNED MESSAGE-----").verify()
Пример #13
0
class Testcases(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.bts = BitShares(
            "wss://node.testnet.bitshares.eu",
            nobroadcast=True,
            # We want to bundle many operations into a single transaction
            bundle=True,
            # Overwrite wallet to use this list of wifs only
            wif={"active": wif}
        )
        self.bts.set_default_account("init0")
        set_shared_bitshares_instance(self.bts)

    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 test_account_upgrade(self):
        account = Account("witness-account")
        tx = account.upgrade()
        ops = tx["operations"]
        op = ops[0][1]
        self.assertEqual(len(ops), 1)
        self.assertEqual(
            getOperationNameForId(ops[0][0]),
            "account_upgrade"
        )
        self.assertTrue(
            op["upgrade_to_lifetime_member"]
        )
        self.assertEqual(
            op["account_to_upgrade"],
            "1.2.1",
        )

    def test_openorders(self):
        account = Account("witness-account")
        self.assertIsInstance(account.openorders, list)

    def test_calls(self):
        account = Account("witness-account")
        self.assertIsInstance(account.callpositions, dict)

    def test_whitelist(self):
        from bitsharesbase.operations import Account_whitelist
        account = Account("witness-account")
        tx = account.whitelist("committee-account")
        self.assertEqual(len(tx["operations"]), 1)
        self.assertEqual(tx["operations"][0][0], 7)
        self.assertEqual(tx["operations"][0][1]["authorizing_account"], account["id"])
        self.assertEqual(tx["operations"][0][1]["new_listing"], Account_whitelist.white_listed)

    def test_blacklist(self):
        from bitsharesbase.operations import Account_whitelist
        account = Account("witness-account")
        tx = account.blacklist("committee-account")
        self.assertEqual(len(tx["operations"]), 1)
        self.assertEqual(tx["operations"][0][0], 7)
        self.assertEqual(tx["operations"][0][1]["authorizing_account"], account["id"])
        self.assertEqual(tx["operations"][0][1]["new_listing"], Account_whitelist.black_listed)

    def test_unlist(self):
        from bitsharesbase.operations import Account_whitelist
        account = Account("witness-account")
        tx = account.nolist("committee-account")
        self.assertEqual(len(tx["operations"]), 1)
        self.assertEqual(tx["operations"][0][0], 7)
        self.assertEqual(tx["operations"][0][1]["authorizing_account"], account["id"])
        self.assertEqual(tx["operations"][0][1]["new_listing"], Account_whitelist.no_listing)

    def test_accountupdate(self):
        from bitshares.account import AccountUpdate
        t = {'id': '2.6.29',
             'lifetime_fees_paid': '44261516129',
             'most_recent_op': '2.9.0',
             'owner': '1.2.29',
             'pending_fees': 0,
             'pending_vested_fees': 16310,
             'total_core_in_orders': '6788845277634',
             'total_ops': 0}
        update = AccountUpdate(t)
        self.assertEqual(update["owner"], "1.2.29")
        self.assertIsInstance(update.account, Account)
        update.__repr__()

        update = AccountUpdate("committee-account")
        self.assertEqual(update["owner"], "1.2.0")
        self.assertIsInstance(update.account, Account)
        update.__repr__()