Exemple #1
0
 def __init__(self,
              wallet: Wallet,
              validator_ip: str,
              network: str = "testnet"):
     """
     """
     TradehubPublicClient.__init__(self, validator_ip=validator_ip)
     self.wallet = wallet
     self.account_blockchain_dict = self.get_account_details()
     self.account_nbr = self.account_blockchain_dict["result"]["value"][
         "account_number"]
     self.account_sequence_nbr = self.account_blockchain_dict["result"][
         "value"]["sequence"]
     self.network_variables = {
         "testnet": {
             "chain_id": "switcheochain",
         },
         "mainnet": {
             "chain_id": "switcheo-tradehub-1",
         },
     }
     self.chain_id = self.network_variables[network]["chain_id"]
     self.fees = self.get_transactions_fees()
     self.mode = "block"  # Need to automate
     self.gas = "100000000000"  # Need to automate
Exemple #2
0
class TestTradeHubGetPrices(APITestCase):

    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_prices_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "last": str,
            "index": str,
            "fair": str,
            "mark": str,
            "mark_avg": str,
            "settlement": str,
            "fair_index_delta_avg": str,
            "market": str,
            "marking_strategy": str,
            "index_updated_at": str,
            "last_updated_at": str,
            "block_height": int
        }

        result: dict = self._client.get_prices("swth_eth1")

        self.assertDictStructure(expect, result)

        # Currently the field market is empty, check if this changed
        self.assertTrue(len(result["market"]) == 0, msg="Expected field 'market' to be empty")

    def test_get_prices_empty_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "last": str,
            "index": str,
            "fair": str,
            "mark": str,
            "mark_avg": str,
            "settlement": str,
            "fair_index_delta_avg": str,
            "market": str,
            "marking_strategy": str,
            "index_updated_at": str,
            "last_updated_at": str,
            "block_height": int
        }

        result: dict = self._client.get_prices("swth_eth1")

        self.assertDictStructure(expect, result)

        # Currently the field market is empty, check if this changed
        self.assertTrue(len(result["market"]) == 0, msg="Expected field 'market' to be empty")
Exemple #3
0
class TestTradeHubGetUsernameCheck(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_username_check_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        result: bool = self._client.get_username_check(USERNAME_DEVEL)

        self.assertIsInstance(
            result,
            bool,
            msg=f"Expected result to be type bool, got {type(result)} instead."
        )
        # TODO need test wallet
        self.assertTrue(result,
                        msg=f"Expected username {USERNAME_DEVEL} to be taken.")

        result: bool = self._client.get_username_check(USERNAME_DEVEL.upper())
        self.assertIsInstance(
            result,
            bool,
            msg=f"Expected result to be type bool, got {type(result)} instead."
        )

        self.assertFalse(
            result,
            msg=f"Expected username {USERNAME_DEVEL.upper()} to be not taken.")
class TestTradeHubGetTransactions(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_transactions_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "id": str,
            "hash": str,
            "address": str,
            "username": str,
            "msg_type": str,
            "msg": str,
            "code": str,
            "gas_used": str,
            "gas_limit": str,
            "memo": str,
            "height": str,
            "block_time": str
        }

        result: list = self._client.get_transactions()

        self.assertEqual(
            200,
            len(result),
            msg="Expected count(200) of transactions are not returned.")

        for transaction in result:
            self.assertDictStructure(expect, transaction)
Exemple #5
0
class TestTradeHubGetMarketStats(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_market_stats_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "day_high": str,
            "day_low": str,
            "day_open": str,
            "day_close": str,
            "day_volume": str,
            "day_quote_volume": str,
            "index_price": str,
            "mark_price": str,
            "last_price": str,
            "market": str,
            "market_type": str,
            "open_interest": str
        }

        result: list = self._client.get_market_stats()

        for market in result:
            self.assertDictStructure(expect, market)
Exemple #6
0
class TestTradeHubGetTransaction(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_transaction_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "id": str,
            "hash": str,
            "address": str,
            "username": str,
            "msgs": [{
                "msg_type": str,
                "msg": str
            }],
            "code": str,
            "gas_used": str,
            "gas_limit": str,
            "memo": str,
            "height": str,
            "block_time": str
        }

        result: dict = self._client.get_transaction(
            "A93BEAC075562D4B6031262BDDE8B9A720346A54D8570A881E3671FEB6E6EFD4")

        self.assertDictStructure(expect, result)
class TestTradeHubGetExternalTransfers(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_external_transfers(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        # TODO need test wallet to be deterministic
        expect: dict = {
            "address": str,
            "amount": str,
            "block_height": int,
            "blockchain": str,
            "contract_hash": str,
            "denom": str,
            "fee_address": Union[str, None],
            "fee_amount": str,
            "id": str,
            "status": str,
            "symbol": str,
            "timestamp": int,
            "token_name": str,
            "transaction_hash": str,
            "transfer_type": str
        }

        result: list = self._client.get_external_transfers(WALLET_DEVEL)

        # Can not check this atm, cause it can change need test wallet
        # self.assertEqual(1, len(result), msg="Expected count(1) of external transfers are not returned.")

        for transfer in result:
            self.assertDictStructure(expect, transfer)
class TestTradeHubGetDelegationRewards(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_delegation_rewards_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "height": str,
            "result": {
                "rewards": [{
                    "validator_address": str,
                    "reward": [{
                        "denom": str,
                        "amount": str
                    }]
                }],
                "total": [
                    {
                        "denom": str,
                        "amount": str
                    },
                ]
            }
        }

        result: dict = self._client.get_delegation_rewards(WALLET_VALIDATOR)

        self.assertDictStructure(expect, result)
class TestTradeHubGetToken(APITestCase):

    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_token_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "name": str,
            "symbol": str,
            "denom": str,
            "decimals": int,
            "blockchain": str,
            "chain_id": int,
            "asset_id": str,
            "is_active": bool,
            "is_collateral": bool,
            "lock_proxy_hash": str,
            "delegated_supply": str,
            "originator": str
        }

        result: dict = self._client.get_token("swth")

        self.assertDictStructure(expect, result)
Exemple #10
0
class TestTradeHubGetBlocks(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_blocks_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "block_height": str,
            "time": str,
            "count": str,
            "proposer_address": str
        }

        result: list = self._client.get_blocks()

        self.assertEqual(
            200,
            len(result),
            msg="Expected count(200) off blocks are not returned.")

        for block in result:
            self.assertDictStructure(expect, block)
Exemple #11
0
class TestTradeHubGetBalance(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_balance_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        expect: dict = {
            "cel1": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            },
            "eth1": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            },
            "nex1": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            },
            "nneo2": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            },
            "swth": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            },
            "usdc1": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            },
            "wbtc1": {
                "available": str,
                "order": str,
                "position": str,
                "denom": str
            }
        }

        result: dict = self._client.get_balance(
            "swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl")
        # if this may fail, check if all denoms are returned. Non zero balances are not returned
        self.assertDictStructure(expect, result)
Exemple #12
0
class TestTradeHubGetStatus(APITestCase):

    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_status_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "jsonrpc": str,
            "id": int,
            "result": {
                "node_info": {
                    "protocol_version": {
                        "p2p": str,
                        "block":  str,
                        "app":  str,
                    },
                    "id": str,
                    "listen_addr": str,
                    "network": str,
                    "version": str,
                    "channels": str,
                    "moniker": str,
                    "other": {
                        "tx_index": str,
                        "rpc_address": str,
                    }
                },
                "sync_info": {
                    "latest_block_hash": str,
                    "latest_app_hash": str,
                    "latest_block_height": str,
                    "latest_block_time": str,
                    "earliest_block_hash": str,
                    "earliest_app_hash": str,
                    "earliest_block_height": str,
                    "earliest_block_time": str,
                    "catching_up": bool
                },
                "validator_info": {
                    "address": str,
                    "pub_key": {
                        "type": str,
                        "value": str,
                    },
                    "voting_power": str,
                }
            }
        }

        result: dict = self._client.get_status()

        self.assertDictStructure(expect, result)
class TestTradeHubGetOrderbook(APITestCase):

    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_get_orderbook_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "asks": [
                {
                    "price": str,
                    "quantity": str
                }
            ],
            "bids": [
                {
                    "price": str,
                    "quantity": str
                }
            ]
        }

        result: dict = self._client.get_orderbook("swth_eth1")

        self.assertDictStructure(expect, result)

    def test_get_orderbook_empty_structure(self):
        expect: dict = {
            "asks": [
            ],
            "bids": [
            ]
        }

        result: dict = self._client.get_orderbook("unknown")
        self.assertDictStructure(expect, result)
Exemple #14
0
class TestTradeHubGetMarkets(APITestCase):

    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_markets_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        expect: dict = {
            "type": str,
            "name": str,
            "display_name": str,
            "description": str,
            "market_type": str,
            "base": str,
            "base_name": str,
            "base_precision": int,
            "quote": str,
            "quote_name": str,
            "quote_precision": int,
            "lot_size": str,
            "tick_size": str,
            "min_quantity": str,
            "maker_fee": str,
            "taker_fee": str,
            "risk_step_size": str,
            "initial_margin_base": str,
            "initial_margin_step": str,
            "maintenance_margin_ratio": str,
            "max_liquidation_order_ticket": str,
            "max_liquidation_order_duration": int,
            "impact_size": str,
            "mark_price_band": int,
            "last_price_protected_band": int,
            "index_oracle_id": str,
            "expiry_time": str,
            "is_active": bool,
            "is_settled": bool,
            "closed_block_height": int,
            "created_block_height": int
        }

        result: list = self._client.get_markets()

        for market in result:
            self.assertDictStructure(expect, market)
Exemple #15
0
class TestTradeHubGetAddress(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_address_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        expect: str = "swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz"

        result: str = self._client.get_address("devel484")

        # Check type
        self.assertIsInstance(result, str)
        # Check value
        self.assertEqual(result, expect)
Exemple #16
0
class TestTradeHubGetOrders(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_get_orders_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        expect: dict = {
            "order_id": str,
            "block_height": int,
            "triggered_block_height": int,
            "address": str,
            "market": str,
            "side": str,
            "price": str,
            "quantity": str,
            "available": str,
            "filled": str,
            "order_status": str,
            "order_type": str,
            "initiator": str,
            "time_in_force": str,
            "stop_price": str,
            "trigger_type": str,
            "allocated_margin_denom": str,
            "allocated_margin_amount": str,
            "is_liquidation": bool,
            "is_post_only": bool,
            "is_reduce_only": bool,
            "type": str,
            "block_created_at": str,
            "username": str,
            "id": str
        }

        result: list = self._client.get_orders()

        self.assertEqual(200,
                         len(result),
                         msg="Expected count(200) of orders are not returned.")

        for order in result:
            self.assertDictStructure(expect, order)
class TestTradeHubGetAllValidators(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_all_validators_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        expect: dict = {
            "OperatorAddress": str,
            "ConsPubKey": str,
            "Jailed": bool,
            "Status": int,
            "Tokens": str,
            "DelegatorShares": str,
            "Description": {
                "moniker": str,
                "identity": str,
                "website": str,
                "security_contact": str,
                "details": str
            },
            "UnbondingHeight": int,
            "UnbondingCompletionTime": str,
            "Commission": {
                "commission_rates": {
                    "rate": str,
                    "max_rate": str,
                    "max_change_rate": str
                },
                "update_time": str
            },
            "MinSelfDelegation": str,
            "ConsAddress": str,
            "ConsAddressByte": str,
            "WalletAddress": str,
            "BondStatus": str
        }

        result: list = self._client.get_all_validators()

        for item in result:
            self.assertDictStructure(expect, item)
class TestTradeHubGetOrder(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_get_order_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "order_id": str,
            "block_height": int,
            "triggered_block_height": int,
            "address": str,
            "market": str,
            "side": str,
            "price": str,
            "quantity": str,
            "available": str,
            "filled": str,
            "order_status": str,
            "order_type": str,
            "initiator": str,
            "time_in_force": str,
            "stop_price": str,
            "trigger_type": str,
            "allocated_margin_denom": str,
            "allocated_margin_amount": str,
            "is_liquidation": bool,
            "is_post_only": bool,
            "is_reduce_only": bool,
            "type": str,
            "block_created_at": str,
            "username": str,
            "id": str
        }

        result: dict = self._client.get_order(
            "4F54D2AE0D793F833806109B4278335BF3D392D4096B682B9A27AF9F8A8BCA58")

        self.assertDictStructure(expect, result)
Exemple #19
0
class TestTradeHubGetBlockTime(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_block_time_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: str = "HH:MM:SS.ZZZZZZ"

        result: str = self._client.get_block_time()

        self.assertIsInstance(result, str)

        self.assertAlmostEqual(
            len(result),
            len(expect),
            msg=f"Check if expected length matches actual length failed.",
            delta=3)
class TestTradeHubGetTrades(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_trades_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """

        expect: dict = {
            "id": str,
            "block_created_at": str,
            "taker_id": str,
            "taker_address": str,
            "taker_fee_amount": str,
            "taker_fee_denom": str,
            "taker_side": str,
            "maker_id": str,
            "maker_address": str,
            "maker_fee_amount": str,
            "maker_fee_denom": str,
            "maker_side": str,
            "market": str,
            "price": str,
            "quantity": str,
            "liquidation": str,
            "taker_username": str,
            "maker_username": str,
            "block_height": str,
        }

        result: list = self._client.get_trades()

        self.assertEqual(200,
                         len(result),
                         msg="Expected count(200) of trades are not returned.")

        for trade in result:
            self.assertDictStructure(expect, trade)
class TestTradeHubGetAccount(APITestCase):
    def setUp(self) -> None:
        self._client = PublicClient(DEVEL_AND_CO_SENTRY)

    def test_get_account_structure(self):
        """
        Check if response match expected dict structure.
        :return:
        """
        expect: dict = {
            'height': str,
            'result': {
                'type': str,
                'value': {
                    'address':
                    str,
                    'coins':
                    [  # Because it is a list, all entries will be checked
                        {
                            'denom': str,
                            'amount': str
                        }
                    ],
                    'public_key': {
                        'type': str,
                        'value': str
                    },
                    'account_number':
                    str,
                    'sequence':
                    str
                }
            }
        }

        result = self._client.get_account(
            "swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz")
        self.assertDictStructure(expect, result)
Exemple #22
0
 def setUp(self) -> None:
     self._client = PublicClient(DEVEL_AND_CO_SENTRY)