Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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")
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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")
Beispiel #8
0
    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))