コード例 #1
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_user_agent(self):
        """Tests the `user_agent` endpoint."""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            user_agent_response = client.public_api.user_agent()
            self.assertEqual(user_agent_response.status_code, 200)
コード例 #2
0
ファイル: common.py プロジェクト: mobilipia/ibledger
def wait_for_block(network: vegaNetwork, height: int = 1) -> None:
    """Wait for block at specific height"""
    for validator_id in range(network.validators_count()):
        host, public_port, private_port = network.api_address(validator_id)
        client = vegaClient(host, public_port, private_port)
        for _ in range(RETRIES_AMOUNT):
            if client.public_api.get_block(height).status_code == 200:
                break
            time.sleep(0.5)
コード例 #3
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_zero_block(self):
        """Tests the `block` endpoint. Check response for 0 block"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            block_response = client.public_api.get_block(0)
            self.assertEqual(block_response.status_code, 200)
            self.assertEqual(block_response.json()['height'], 0)
コード例 #4
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_nonexistent_block(self):
        """Tests the `block` endpoint. Check response for nonexistent block"""

        nonexistent_height = 999
        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            block_response = client.public_api.get_block(nonexistent_height)
            self.assertEqual(block_response.status_code, 404)
コード例 #5
0
    def test_get_nonexistent_wallet(self):
        """Tests the wallet history is None for nonexistent wallet"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(validator_id)
            client = vegaClient(host, public_port, private_port)
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                wallet_history = crypto_client.get_wallet_info(alice_keys).json()["wallet_history"]
                self.assertIsNone(wallet_history)
コード例 #6
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_only_non_empty_blocks(self):
        """Tests the `blocks` endpoint. Check response for only non empty blocks"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            blocks_response = client.public_api.get_blocks(
                count=5, skip_empty_blocks=True)
            self.assertEqual(blocks_response.status_code, 200)
            self.assertEqual(len(blocks_response.json()['blocks']), 0)
コード例 #7
0
ファイル: common.py プロジェクト: mobilipia/ibledger
def wait_api_to_start(network: vegaNetwork) -> None:
    """Wait for api starting"""
    for validator_id in range(network.validators_count()):
        host, public_port, private_port = network.api_address(validator_id)
        client = vegaClient(host, public_port, private_port)
        for _ in range(RETRIES_AMOUNT):
            try:
                client.public_api.health_info()
                break
            except ConnectionError:
                time.sleep(0.5)
コード例 #8
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_blocks_with_time(self):
        """Tests the `blocks` endpoint. Check response for blocks with time"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            blocks_response = client.public_api.get_blocks(
                count=1, add_blocks_time=True)
            self.assertEqual(blocks_response.status_code, 200)
            self.assertIsNotNone(blocks_response.json()['blocks'][0]['time'])
コード例 #9
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_n_latest_blocks_negative(self):
        """Tests the `blocks` endpoint. Check response for N latest blocks if latest exceeds current height"""

        latest = 999
        number_of_blocks = 6
        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            blocks_response = client.public_api.get_blocks(
                count=number_of_blocks, latest=latest)
            self.assertEqual(blocks_response.status_code, 404)
コード例 #10
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_zero_initial_stats(self):
        """Tests the `stats` endpoint. Check initial stats values"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            stats = client.public_api.stats()
            self.assertEqual(stats.status_code, 200)
            self.assertEqual(stats.json()['tx_count'], 0)
            self.assertEqual(stats.json()['tx_pool_size'], 0)
            self.assertEqual(stats.json()['tx_cache_size'], 0)
コード例 #11
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_health_check(self):
        """Tests the `healthcheck` endpoint."""

        time.sleep(10)
        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            health_info_response = client.public_api.health_info()
            self.assertEqual(health_info_response.status_code, 200)
            self.assertEqual(health_info_response.json()['connected_peers'],
                             self.network.validators_count() - 1)
            self.assertEqual(health_info_response.json()['consensus_status'],
                             'Active')
コード例 #12
0
    def test_add_funds_to_nonexistent_wallet(self):
        """Tests the funds issue is failed if wallet doesn't exist"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(validator_id)
            client = vegaClient(host, public_port, private_port)
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                tx_response = crypto_client.issue(alice_keys, 100)
                with client.create_subscriber("transactions") as subscriber:
                    subscriber.wait_for_new_event()
                    tx_info = client.public_api.get_tx_info(tx_response.json()["tx_hash"]).json()
                    tx_status = tx_info["status"]["type"]
                    self.assertEqual(tx_status, "service_error")
コード例 #13
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_last_n_blocks(self):
        """Tests the `blocks` endpoint. Check response for last N blocks"""

        number_of_blocks = 5
        wait_for_block(self.network, 5)
        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            blocks_response = client.public_api.get_blocks(
                count=number_of_blocks)
            self.assertEqual(blocks_response.status_code, 200)
            self.assertEqual(len(blocks_response.json()['blocks']),
                             number_of_blocks)
コード例 #14
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_unknown_transaction(self):
        """Tests the `transactions` endpoint. Check response for unknown transaction"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            tx_response = client.public_api.get_tx_info(
                "b2d09e1bddca851bee8faf8ffdcfc18cb87fbde167a29bd049fa2eee4a82c1ca"
            )
            self.assertEqual(tx_response.status_code, 404)
            response_info = tx_response.json()
            self.assertEqual(response_info["title"],
                             "Failed to get transaction info")
            self.assertEqual(response_info["detail"], r'{"type":"unknown"}')
コード例 #15
0
    def test_token_issue(self):
        """Tests the token issue"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(validator_id)
            client = vegaClient(host, public_port, private_port)
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                crypto_client.create_wallet(alice_keys, "Alice" + str(validator_id))
                with client.create_subscriber("transactions") as subscriber:
                    subscriber.wait_for_new_event()
                    crypto_client.issue(alice_keys, 100)
                    subscriber.wait_for_new_event()
                    alice_balance = crypto_client.get_balance(alice_keys)
                    self.assertEqual(alice_balance, 200)
コード例 #16
0
 def test_create_wallet_same_name(self):
     """Tests the transaction with the same wallet name is rejected"""
     client = None
     for validator_id in range(self.network.validators_count()):
         host, public_port, private_port = self.network.api_address(validator_id)
         client = vegaClient(host, public_port, private_port)
         with vegaCryptoAdvancedClient(client) as crypto_client:
             alice_keys = KeyPair.generate()
             crypto_client.create_wallet(alice_keys, "Alice" + str(validator_id))
             with client.create_subscriber("transactions") as subscriber:
                 subscriber.wait_for_new_event()
             # create the wallet with the same name again
             crypto_client.create_wallet(alice_keys, "Alice" + str(validator_id))
             with client.create_subscriber("blocks") as subscriber:
                 subscriber.wait_for_new_event()
     # it should contain 4 txs for wallet creation plus 6 services txs
     self.assertEqual(client.public_api.stats().json()["tx_count"], 10)
コード例 #17
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_n_latest_blocks(self):
        """Tests the `blocks` endpoint. Check response for N latest blocks"""

        latest = 5
        number_of_blocks = 15
        wait_for_block(self.network, 5)
        for validator_id in range(self.network.validators_count()):
            height_counter = latest
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            blocks_response = client.public_api.get_blocks(
                count=number_of_blocks, latest=latest)
            self.assertEqual(len(blocks_response.json()['blocks']), latest + 1)
            for block in blocks_response.json()['blocks']:
                self.assertEqual(int(block['height']), height_counter)
                height_counter -= 1
コード例 #18
0
    def test_transfer_funds(self):
        """Tests the transfer funds to another wallet"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(validator_id)
            client = vegaClient(host, public_port, private_port)
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                bob_keys = KeyPair.generate()
                with client.create_subscriber("transactions") as subscriber:
                    crypto_client.create_wallet(alice_keys, "Alice" + str(validator_id))
                    subscriber.wait_for_new_event()
                    crypto_client.create_wallet(bob_keys, "Bob" + str(validator_id))
                    subscriber.wait_for_new_event()
                    crypto_client.transfer(20, alice_keys, bob_keys.public_key)
                    subscriber.wait_for_new_event()
                    alice_balance = crypto_client.get_balance(alice_keys)
                    bob_balance = crypto_client.get_balance(bob_keys)
                    self.assertEqual(alice_balance, 80)
                    self.assertEqual(bob_balance, 120)
コード例 #19
0
ファイル: api.py プロジェクト: mobilipia/ibledger
    def test_get_n_earliest_blocks(self):
        """Tests the `blocks` endpoint. Check response for N earliest blocks"""

        earliest = 20
        number_of_blocks = 15
        wait_for_block(self.network, 20)
        for validator_id in range(self.network.validators_count()):
            height_counter = earliest
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            blocks_response = client.public_api.get_blocks(
                count=number_of_blocks, earliest=earliest)
            latest_height = int(blocks_response.json()['blocks'][0]['height'])
            self.assertEqual(len(blocks_response.json()['blocks']),
                             latest_height - earliest + 1)
            # blocks must be started from 'earliest' height
            for block in reversed(blocks_response.json()['blocks']):
                self.assertEqual(int(block['height']), height_counter)
                height_counter += 1
コード例 #20
0
    def test_create_wallet_unique_for_key_pair(self):
        """Tests the transaction with the same keys for different wallets is failed"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(validator_id)
            client = vegaClient(host, public_port, private_port)
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                tx_response = crypto_client.create_wallet(
                    alice_keys, "Alice" + str(validator_id)
                )
                with client.create_subscriber("transactions") as subscriber:
                    subscriber.wait_for_new_event()
                tx_status = client.public_api.get_tx_info(tx_response.json()["tx_hash"]).json()["status"]["type"]
                self.assertEqual(tx_status, "success")
                # create the wallet with the same keys again
                tx_same_keys = crypto_client.create_wallet(
                    alice_keys, "Alice_Dublicate" + str(validator_id)
                )
                with client.create_subscriber("blocks") as subscriber:
                    subscriber.wait_for_new_event()
                tx_status = client.public_api.get_tx_info(tx_same_keys.json()["tx_hash"]).json()["status"]["type"]
                self.assertEqual(tx_status, "service_error")
コード例 #21
0
    def test_transfer_funds_insufficient(self):
        """Tests the transfer insufficient amount of funds is failed"""

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(validator_id)
            client = vegaClient(host, public_port, private_port)
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                crypto_client.create_wallet(alice_keys, "Alice" + str(validator_id))
                bob_keys = KeyPair.generate()
                crypto_client.create_wallet(bob_keys, "Bob" + str(validator_id))
                with client.create_subscriber("blocks") as subscriber:
                    subscriber.wait_for_new_event()
                    tx_response = crypto_client.transfer(
                        110, alice_keys, bob_keys.public_key
                    )
                    subscriber.wait_for_new_event()
                    tx_info = client.public_api.get_tx_info(tx_response.json()["tx_hash"]).json()
                    tx_status = tx_info["status"]["type"]
                    self.assertEqual(tx_status, "service_error")
                    alice_balance = crypto_client.get_balance(alice_keys)
                    bob_balance = crypto_client.get_balance(bob_keys)
                    self.assertEqual(alice_balance, 100)
                    self.assertEqual(bob_balance, 100)
コード例 #22
0
ファイル: deploy.py プロジェクト: mobilipia/ibledger
    def test_deploy_regular_with_consensus_config(self):
        """Tests the deploy mechanism in regular mode with consensus config."""

        pub_configs = self.network._public_configs().split()
        validator_keys = []
        for pub_config in pub_configs:
            keys = []
            with open(pub_config, 'r') as file:
                data = file.read()
                keys.append(
                    re.search('consensus_key = "(.+?)"', data).group(1))
                keys.append(re.search('service_key = "(.+?)"', data).group(1))
            validator_keys.append(keys)

        cryptocurrency_advanced_config_dict = {
            "networks": launcher_networks(self.network),
            "deadline_height": 10000,
            "consensus": {
                "validator_keys": validator_keys,
                "first_round_timeout": 3000,
                "status_timeout": 5000,
                "peers_timeout": 10000,
                "txs_block_limit": 5000,
                "max_message_len": 1048576,
                "min_propose_timeout": 10,
                "max_propose_timeout": 200,
                "propose_timeout_threshold": 500
            },
            "artifacts": {
                "cryptocurrency": {
                    "runtime": "rust",
                    "name": "vega-cryptocurrency-advanced",
                    "version": "0.1.0",
                }
            },
            "instances": {
                "crypto": {
                    "artifact": "cryptocurrency"
                }
            },
        }

        cryptocurrency_advanced_config = Configuration(
            cryptocurrency_advanced_config_dict)
        with Launcher(cryptocurrency_advanced_config) as launcher:
            explorer = launcher.explorer()

            launcher.deploy_all()
            launcher.wait_for_deploy()
            launcher.start_all()
            launcher.wait_for_start()

            for artifact in launcher.launch_state.completed_deployments():
                deployed = explorer.check_deployed(artifact)
                self.assertEqual(deployed, True)

            self.assertEqual(len(launcher.launch_state.completed_configs()), 1)

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            supervisor_api = client.service_apis("supervisor")
            consensus_config = supervisor_api[0].get_service(
                "consensus-config").json()
            # check that initial config has been applied
            self.assertEqual(consensus_config['txs_block_limit'], 5000)
コード例 #23
0
ファイル: deploy.py プロジェクト: mobilipia/ibledger
    def test_deploy_regular_stop_running_instance(self):
        """Tests the deploy mechanism to stop running instance."""

        cryptocurrency_advanced_config_dict = {
            "networks": launcher_networks(self.network),
            "deadline_height": 10000,
            "artifacts": {
                "cryptocurrency": {
                    "runtime": "rust",
                    "name": "vega-cryptocurrency-advanced",
                    "version": "0.1.0",
                }
            },
            "instances": {
                "crypto": {
                    "artifact": "cryptocurrency"
                }
            },
        }

        cryptocurrency_advanced_config = Configuration(
            cryptocurrency_advanced_config_dict)
        with Launcher(cryptocurrency_advanced_config) as launcher:
            explorer = launcher.explorer()

            launcher.deploy_all()
            launcher.wait_for_deploy()
            launcher.start_all()
            launcher.wait_for_start()

            for artifact in launcher.launch_state.completed_deployments():
                deployed = explorer.check_deployed(artifact)
                self.assertEqual(deployed, True)

            self.assertEqual(len(launcher.launch_state.completed_configs()), 1)

        # stop service
        cryptocurrency_advanced_config_dict = {
            "networks": launcher_networks(self.network),
            "deadline_height": 10000,
            "artifacts": {
                "cryptocurrency": {
                    "runtime": "rust",
                    "name": "vega-cryptocurrency-advanced",
                    "version": "0.1.0",
                }
            },
            "instances": {
                "crypto": {
                    "artifact": "cryptocurrency",
                    "action": "stop"
                }
            },
        }

        cryptocurrency_advanced_config = Configuration(
            cryptocurrency_advanced_config_dict)
        with Launcher(cryptocurrency_advanced_config) as launcher:

            launcher.deploy_all()
            launcher.wait_for_deploy()
            launcher.start_all()
            launcher.wait_for_start()

        for validator_id in range(self.network.validators_count()):
            host, public_port, private_port = self.network.api_address(
                validator_id)
            client = vegaClient(host, public_port, private_port)
            available_services = client.public_api.available_services().json()
            # crypto instance always first element in array
            self.assertEqual(
                available_services['services'][0]['status']['type'], 'stopped')
            with vegaCryptoAdvancedClient(client) as crypto_client:
                alice_keys = KeyPair.generate()
                tx_response = crypto_client.create_wallet(
                    alice_keys, "Alice" + str(validator_id))
                # in case of stopped service its tx will not be processed
                self.assertEqual(tx_response.status_code, 400)
                self.assertIn("Specified service is not active",
                              str(tx_response.content))