Beispiel #1
0
    def tet_01(self, number, transtion_id, main_currency_id,
               target_currency_id, buy_price, buy_num, sell_price, sell_num):
        """
        编号:52-1
        市商市价买单,,市商市价卖单,不成交
        做市商不支持市价单,此用例跳过
        """
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用户说明:编号:52-1-%s  市商市价买单,,市商市价卖单,不成交 " % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=main_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=target_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=main_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=target_currency_id,
            balance_value=990000000000000)

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)

        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)
        test_buyer = Base(user=BUYER)
        buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id,
                                                    price=buy_price,
                                                    num=buy_num,
                                                    order_type=1)
        time.sleep(1)
        test_seller = Base(user=SELLER)
        sell_order_id = test_seller.SellOrder(transtion_id=transtion_id,
                                              price=sell_price,
                                              num=sell_num,
                                              order_type=1)

        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id,
            transaction_id=transtion_id,
            order_id=sell_order_id)

        buy_order_status = ConnectMysql(_type=2).get_Order_Status(
            order_id=buy_order_id, order_type=1)
        sell_order_status = ConnectMysql(_type=2).get_Order_Status(
            order_id=sell_order_id, order_type=2)
        logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(
            buy_order_status, sell_order_status))

        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }
        logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format(
            before_buy_main, after_buy_main))
        logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format(
            before_buy_target, after_buy_target))
        logger.info("交易前卖家主币余额:{0}--------交易后卖家主币余额:{1}".format(
            before_sell_main, after_sell_main))
        logger.info("交易前卖家目标币余额:{0}--------交易后卖家目标币余额:{1}".format(
            before_sell_target, after_sell_target))

        self.assertEqual(int(before_buy_main), int(after_buy_main))
        self.assertEqual(int(before_buy_target), int(after_buy_target))
        self.assertEqual(int(before_sell_main), int(after_sell_main))
        self.assertEqual(int(before_sell_target), int(after_sell_target))
Beispiel #2
0
    def test_01(self, number, transtion_id, main_currency_id,
                target_currency_id, buy_price, buy_num, sell_price, sell_num):
        """
        编号:58-1
        限价买单,不收手续费,限价卖单,收取手续费,部分成交
        """
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用例说明:编号:58-1-%s  限价买单,不收手续费,限价卖单,收取手续费,部分成交" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, transtion_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=main_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=target_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=main_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=target_currency_id,
            balance_value=990000000000000)

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)
        logger.info("买入价格:{0}----买入数量:{1}-----卖出价格:{2}-----卖出数量{3}".format(
            buy_price, buy_num, sell_price, sell_num))
        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)
        test_buyer = Base(user=BUYER)
        buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id,
                                                    price=buy_price,
                                                    num=buy_num,
                                                    order_type=0)
        time.sleep(1)
        test_seller = Base(user=SELLER)
        sell_order_id = test_seller.SellOrder(transtion_id=transtion_id,
                                              price=sell_price,
                                              num=sell_num,
                                              order_type=0)
        test_buyer = Base(user=BUYER)
        buy_update_resp = test_buyer.updateRevocationStatus(
            type=1, orderId=buy_order_id)
        buy_assert_list = [
            JMESPathExtractor().extract(query="MSG",
                                        body=buy_update_resp.text),
            JMESPathExtractor().extract(query="STATUS",
                                        body=buy_update_resp.text)
        ]

        test_seller = Base(user=SELLER)
        sell_update_resp = test_seller.updateRevocationStatus(
            type=2, orderId=sell_order_id)
        sell_assert_list = [
            JMESPathExtractor().extract(query="MSG",
                                        body=sell_update_resp.text),
            JMESPathExtractor().extract(query="STATUS",
                                        body=sell_update_resp.text)
        ]
        time.sleep(3)
        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id,
            transaction_id=transtion_id,
            order_id=buy_order_id)

        buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
            order_id=buy_order_id, order_type=1)
        sell_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
            order_id=sell_order_id, order_type=2)
        logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(
            buy_order_status, sell_order_status))

        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }

        logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format(
            before_buy_main, after_buy_main))
        logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format(
            before_buy_target, after_buy_target))
        logger.info("交易前卖家主币余额:{0}--------交易后卖家主币余额:{1}".format(
            before_sell_main, after_sell_main))
        logger.info("交易前卖家目标币余额:{0}--------交易后卖家目标币余额:{1}".format(
            before_sell_target, after_sell_target))
        self.assertListEqual(buy_assert_list, ["SUCCESS", "0"])
        self.assertListEqual(sell_assert_list, ["订单已被成交", "1"])
        self.assertIn(
            int(before_buy_main) - int(after_buy_main) -
            int(buy_price * sell_num / 100000000), [0, 1])
        self.assertIn(
            int(after_buy_target) - int(before_buy_target) - int(sell_num),
            [0, 1])
        self.assertIn(
            int(after_sell_main) - int(before_sell_main) -
            int(buy_price * sell_num / 100000000 * (1 - 2 / 1000)), [0, 1])
        self.assertIn(
            int(before_sell_target) - int(after_sell_target) - int(sell_num),
            [0, 1])
Beispiel #3
0
    def test_01(self, number, transtion_id, main_currency_id, target_currency_id, buy_price, buy_num, sell_price, sell_num):

        logger.info("<<==========================================================================================================================>")

        logger.info("用例说明:  编号:81-1-%s,         随机测试限价买单、限价卖单、成交、撤单,验证订单状态,冻结金额余额" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(get_redis_name(transtion_id))

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(sell_price), int(buy_num), int(sell_num)
        for i in range(2):
            with self.subTest():
                ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=main_currency_id, balance_value=9900000000000000)
                ConnectMysql(_type=mysql_type).update_balance_value(user_mail=BUYER, currency_id=target_currency_id, balance_value=9900000000000000)
                ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=main_currency_id, balance_value=9900000000000000)
                ConnectMysql(_type=mysql_type).update_balance_value(user_mail=SELLER, currency_id=target_currency_id, balance_value=9900000000000000)
                random_price = random.randint(10, 999) * 100000000
                random_num = random.randint(10, 99) * 100000000
                before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
                    buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id
                )
                test_buyer = Base(user=BUYER)
                buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id, price=random_price, num=random_num, order_type=0)
                time.sleep(1)
                test_seller = Base(user=SELLER)
                sell_order_id = test_seller.SellOrder(transtion_id=transtion_id, price=random_price, num=random_num, order_type=0)
                time.sleep(3)
                test_buyer = Base(user=BUYER)
                buy_update_resp = test_buyer.updateRevocationStatus(type=1, orderId=buy_order_id)
                buy_assert_list = [JMESPathExtractor().extract(query="MSG", body=buy_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=buy_update_resp.text)]

                test_seller = Base(user=SELLER)
                sell_update_resp = test_seller.updateRevocationStatus(type=2, orderId=sell_order_id)
                sell_assert_list = [JMESPathExtractor().extract(query="MSG", body=sell_update_resp.text), JMESPathExtractor().extract(query="STATUS", body=sell_update_resp.text)]

                after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
                    buyer=BUYER, seller=SELLER, main_currency_id=main_currency_id, target_currency_id=target_currency_id, transaction_id=transtion_id,
                    order_id=buy_order_id
                )

                buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(order_id=buy_order_id, order_type=1)
                sell_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(order_id=sell_order_id, order_type=2)
                logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(buy_order_status, sell_order_status))

                balance_dict = {
                    "before_buy_main_balance": before_buy_main,
                    "before_buy_target_balance": before_buy_target,
                    "before_sell_main_balance": before_sell_main,
                    "before_sell_target_balance": before_sell_target,
                    "after_buy_main_balance": after_buy_main,
                    "after_buy_target_balance": after_buy_target,
                    "after_sell_main_balance": after_sell_main,
                    "after_sell_target_balance": after_sell_target,
                }
                self.assertListEqual(buy_assert_list, ["订单已被成交", "1"])
                self.assertListEqual(sell_assert_list, ["订单已被成交", "1"])
                flag_list = count_value_single(buy_price=random_price, buy_num=random_num, sell_price=random_price, sell_num=random_num, **balance_dict)
                logger.info("<<==========================================================================================================================>")

                self.assertNotIn(False, flag_list)
Beispiel #4
0
    def test_01(self, number, transtion_id, main_currency_id,
                target_currency_id, buy_price, buy_num, sell_price, sell_num):
        """
        编号:53-1
        市商限价买单,不收手续费,撤单
        """
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用例说明:编号:53-1-%s   市商限价买单,不收手续费,撤单" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=main_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=target_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=main_currency_id,
            balance_value=990000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=target_currency_id,
            balance_value=990000000000000)

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)

        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)

        test_buyer = Base(user=BUYER)
        buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id,
                                                    price=buy_price,
                                                    num=buy_num,
                                                    order_type=0)

        test_buyer = Base(user=BUYER)
        buy_update_resp = test_buyer.updateRevocationStatus(
            type=1, orderId=buy_order_id)
        buy_assert_list = [
            JMESPathExtractor().extract(query="MSG",
                                        body=buy_update_resp.text),
            JMESPathExtractor().extract(query="STATUS",
                                        body=buy_update_resp.text)
        ]

        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id,
            transaction_id=transtion_id,
            order_id=buy_order_id)
        buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
            order_id=buy_order_id, order_type=1)
        logger.info("撤单后买单状态:{0}".format(buy_order_status))
        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }
        logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format(
            before_buy_main, after_buy_main))
        logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format(
            before_buy_target, after_buy_target))
        self.assertListEqual(buy_assert_list, ["SUCCESS", "0"])

        self.assertEqual(int(before_buy_main), int(after_buy_main))
        self.assertEqual(int(before_buy_target), int(after_buy_target))
Beispiel #5
0
    def test_01(self, number, transtion_id, main_currency_id,
                target_currency_id, buy_price, buy_num, sell_price, sell_num):
        """
        编号:45-1
        限价买单,不收手续费,限价卖单,收取手续费
        """
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用例说明:  编号:45-1-%s,        限价买单,不收手续费,限价卖单,收取手续费" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)

        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)
        test_buyer = Base(user=BUYER)
        buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id,
                                                    price=buy_price,
                                                    num=buy_num,
                                                    order_type=0)
        time.sleep(1)
        test_seller = Base(user=SELLER)
        sell_order_id = test_seller.SellOrder(transtion_id=transtion_id,
                                              price=sell_price,
                                              num=sell_num,
                                              order_type=0)
        test_buyer = Base(user=BUYER)
        buy_update_resp = test_buyer.updateRevocationStatus(
            type=1, orderId=buy_order_id)
        buy_assert_list = [
            JMESPathExtractor().extract(query="MSG",
                                        body=buy_update_resp.text),
            JMESPathExtractor().extract(query="STATUS",
                                        body=buy_update_resp.text)
        ]

        test_seller = Base(user=SELLER)
        sell_update_resp = test_seller.updateRevocationStatus(
            type=2, orderId=sell_order_id)
        sell_assert_list = [
            JMESPathExtractor().extract(query="MSG",
                                        body=sell_update_resp.text),
            JMESPathExtractor().extract(query="STATUS",
                                        body=sell_update_resp.text)
        ]

        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id,
            transaction_id=transtion_id,
            order_id=sell_order_id)

        buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
            order_id=buy_order_id, order_type=1)
        sell_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
            order_id=sell_order_id, order_type=2)
        logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(
            buy_order_status, sell_order_status))

        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }
        self.assertListEqual(buy_assert_list, ["订单已被成交", "1"])
        self.assertListEqual(sell_assert_list, ["订单已被成交", "1"])
        flag_list = count_balance(free_type="buy_free",
                                  deal_price=buy_price,
                                  deal_num=buy_num,
                                  **balance_dict)

        self.assertNotIn(False, flag_list)
Beispiel #6
0
    def test_01(self, number, transtion_id, main_currency_id,
                target_currency_id, buy_price, buy_num, sell_price, sell_num):

        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用例说明:  编号:10-1-%s,         随机测试限价买单、限价卖单、成交、撤单" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)
        for i in range(3):
            with self.subTest():
                ConnectMysql(_type=mysql_type).update_balance_value(
                    user_mail=BUYER,
                    currency_id=main_currency_id,
                    balance_value=9900000000000000)
                ConnectMysql(_type=mysql_type).update_balance_value(
                    user_mail=BUYER,
                    currency_id=target_currency_id,
                    balance_value=9900000000000000)
                ConnectMysql(_type=mysql_type).update_balance_value(
                    user_mail=SELLER,
                    currency_id=main_currency_id,
                    balance_value=9900000000000000)
                ConnectMysql(_type=mysql_type).update_balance_value(
                    user_mail=SELLER,
                    currency_id=target_currency_id,
                    balance_value=9900000000000000)
                num_min, price_min = ConnectMysql(
                    _type=mysql_type).query_currency_min(
                        transtion_id=transtion_id)

                random_price = random.randrange(int(price_min),
                                                int(price_min) * 999999,
                                                int(price_min))
                random_num = random.randrange(int(num_min),
                                              int(num_min) * 999999,
                                              int(num_min))
                before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
                    buyer=BUYER,
                    seller=SELLER,
                    main_currency_id=main_currency_id,
                    target_currency_id=target_currency_id)
                test_buyer = Base(user=BUYER)
                buy_order_id = test_buyer.OrderReservations(
                    transtion_id=transtion_id,
                    price=random_price,
                    num=random_num,
                    order_type=0)

                test_seller = Base(user=SELLER)
                sell_order_id = test_seller.SellOrder(
                    transtion_id=transtion_id,
                    price=random_price,
                    num=random_num,
                    order_type=0)

                after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
                    buyer=BUYER,
                    seller=SELLER,
                    main_currency_id=main_currency_id,
                    target_currency_id=target_currency_id,
                    transaction_id=transtion_id,
                    order_id=buy_order_id)

                buy_order_status = ConnectMysql(
                    _type=mysql_type).get_Order_Status(order_id=buy_order_id,
                                                       order_type=1)
                sell_order_status = ConnectMysql(
                    _type=mysql_type).get_Order_Status(order_id=sell_order_id,
                                                       order_type=2)
                logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(
                    buy_order_status, sell_order_status))

                balance_dict = {
                    "before_buy_main_balance": before_buy_main,
                    "before_buy_target_balance": before_buy_target,
                    "before_sell_main_balance": before_sell_main,
                    "before_sell_target_balance": before_sell_target,
                    "after_buy_main_balance": after_buy_main,
                    "after_buy_target_balance": after_buy_target,
                    "after_sell_main_balance": after_sell_main,
                    "after_sell_target_balance": after_sell_target,
                }

                flag_list = count_value_single(buy_price=random_price,
                                               buy_num=random_num,
                                               sell_price=random_price,
                                               sell_num=random_num,
                                               **balance_dict)
                logger.info(
                    "<<==========================================================================================================================>"
                )

                self.assertNotIn(False, flag_list)
Beispiel #7
0
class TestCase(MyTest):

    def test_01(self):
        """
        限价卖\买:while(余额足够){A创建卖单,B买入}, 全部成交 手续费 == 2/1000
        交易对:BTC/USDT
        A卖单等差递增
        UserA_SellOrderPrice = 98
        UserA_SellOrderNum = 1,2,3,4,5
        B买单价格
        UserB_BuyOrderPrice = 100
        UserB_BuyOrderNum= 15
        """
        #  清除redis,mysql中btc/usdt的买卖单数据
        ConnectRedis().clear_redis(name=["1buy", "1sell"])
        ConnectMysql().update_order_status(transtion_id=1, order_type=1, order_status=2)
        ConnectMysql().update_order_status(transtion_id=1, order_type=2, order_status=2)

        self.test_buyer = Base(user="******")
        self.test_seller = Base(user="******")

        logger.info("测试用例说明:".format(TestCase.setUp.__doc__))
        # 下单前查询买卖双发的主币和目标币余额
        self.before_deal_seller_main_balance_value = self.test_seller.User_balance_details(currency_id=1)
        self.before_deal_seller_deputy_balance_value = self.test_seller.User_balance_details(currency_id=2)
        self.before_deal_buyer_main_balance_value = self.test_buyer.User_balance_details(currency_id=1)
        self.before_deal_buyer_deputy_balance_value = self.test_buyer.User_balance_details(currency_id=2)

        logger.info("买入之前买家主币余额:{0}-----买入之前买家目标币余额:{1}".format(self.before_deal_buyer_main_balance_value, self.before_deal_buyer_deputy_balance_value))
        logger.info("买入之前卖家的主币余额:{0}------买入之前卖家的目标币余额{1}".format(self.before_deal_seller_main_balance_value, self.before_deal_seller_deputy_balance_value))

        self.buy_price, self.sell_price = 100, 98
        self.buy_num = 15
        self.sell_num = [1, 2, 3, 4, 5]
        self.sell_id_list = []

        for i in range(len(self.sell_num)):
            self.sell_resp = self.test_seller.SellOrder(transtion_id=1, price=self.sell_price, num=self.sell_num[i], order_type=0)
            self.sell_order_id = JMESPathExtractor().extract(query="OBJECT.sellerOrderId", body=self.sell_resp.text)
            self.sell_id_list.append(self.sell_order_id)
            time.sleep(1)
            logger.info("下卖单返回信息:{0}".format(self.sell_resp.json()))

        self.buy_resp = self.test_buyer.OrderReservations(transtion_id=1, price=self.buy_price, num=self.buy_num, order_type=0)
        buy_order_id = JMESPathExtractor().extract(query="OBJECT.buyerOrderId", body=self.buy_resp.text)
        logger.info("下买单返回信息:{0}".format(self.buy_resp.json()))

        for i in self.sell_id_list:
            order_status = ConnectMysql().get_Order_Status(order_id=i, order_type=2)
            logger.info("卖单Id:{0}----订单状态:{1}".format(i, order_status))

        logger.info("买单ID:{0}----订单状态:{1}".format(buy_order_id, ConnectMysql().get_Order_Status(order_id=buy_order_id, order_type=1)))

        self.after_deal_seller_main_balance_value = self.test_seller.User_balance_details(currency_id=1)
        self.after_deal_seller_deputy_balance_value = self.test_seller.User_balance_details(currency_id=2)
        self.after_deal_buyer_main_balance_value = self.test_buyer.User_balance_details(currency_id=1)
        self.after_deal_buyer_deputy_balance_value = self.test_buyer.User_balance_details(currency_id=2)

        logger.info("买入之后买家主币余额:{0}-------买入之后买家目标币余额:{1}".format(self.after_deal_buyer_main_balance_value, self.after_deal_buyer_deputy_balance_value))
        logger.info("买入之后卖家主币余额:{0}------买入之后卖家目标币余额:{1}".format(self.after_deal_seller_main_balance_value, self.after_deal_seller_deputy_balance_value))
        logger.info("成交金额:{0}".format(self.buy_num*self.sell_price))
Beispiel #8
0
    def test_01(self, number, transtion_id, main_currency_id,
                target_currency_id, buy_price, buy_num, sell_price, sell_num):
        """
        编号:41-1
        限价买单,收手续费,限价卖单不收取手续费
        """
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用例说明:  编号:41-1-%s,        限价买单,收手续费,限价卖单收取手续费" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=main_currency_id,
            balance_value=99000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=target_currency_id,
            balance_value=99000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=main_currency_id,
            balance_value=99000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=target_currency_id,
            balance_value=99000000000000)

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)

        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)
        for i in range(10):
            test_buyer = Base(user=BUYER)
            buy_order_id = test_buyer.OrderReservations(
                transtion_id=transtion_id,
                price=buy_price,
                num=buy_num,
                order_type=0)
            test_seller = Base(user=SELLER)
            time.sleep(1)
            sell_order_id = test_seller.SellOrder(transtion_id=transtion_id,
                                                  price=sell_price,
                                                  num=sell_num,
                                                  order_type=0)

            test_buyer = Base(user=BUYER)
            buy_update_resp = test_buyer.updateRevocationStatus(
                type=1, orderId=buy_order_id)
            buy_assert_list = [
                JMESPathExtractor().extract(query="MSG",
                                            body=buy_update_resp.text),
                JMESPathExtractor().extract(query="STATUS",
                                            body=buy_update_resp.text)
            ]

            test_seller = Base(user=SELLER)
            sell_update_resp = test_seller.updateRevocationStatus(
                type=2, orderId=sell_order_id)
            sell_assert_list = [
                JMESPathExtractor().extract(query="MSG",
                                            body=sell_update_resp.text),
                JMESPathExtractor().extract(query="STATUS",
                                            body=sell_update_resp.text)
            ]

            after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
                buyer=BUYER,
                seller=SELLER,
                main_currency_id=main_currency_id,
                target_currency_id=target_currency_id,
                transaction_id=transtion_id,
                order_id=sell_order_id)

            buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
                order_id=buy_order_id, order_type=1)
            sell_order_status = ConnectMysql(
                _type=mysql_type).get_Order_Status(order_id=sell_order_id,
                                                   order_type=2)
            logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(
                buy_order_status, sell_order_status))
Beispiel #9
0
    def test_01(self):
        """
        限价卖\限价买:while(余额足够){A创建卖单,B买入}, 部分成交 手续费 == 2/1000
        B限价买单
        UserB_BuyOrderPrice = 200,250,300,350,400 ,    UserB_BuyOrderNum =  1, 2, 3, 4, 5
        A限价卖单等差递增
        UserA_SellOrderPrice = 200,250,300,350,400 ,   UserA_SellOrderNum = 1, 2, 3, 4, 6
        """

        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=main_currency_id,
            balance_value=99000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=BUYER,
            currency_id=target_currency_id,
            balance_value=99000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=main_currency_id,
            balance_value=99000000000000)
        ConnectMysql(_type=mysql_type).update_balance_value(
            user_mail=SELLER,
            currency_id=target_currency_id,
            balance_value=99000000000000)
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("测试用例说明:{}".format(TestCase.test_01.__doc__))
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))

        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)
        buy_order_id_list = []
        sell_order_id_list = []

        for i in range(len(buy_price)):
            # 下买单
            test_buyer = Base(user=BUYER)
            buy_order_id = test_buyer.OrderReservations(
                transtion_id=transtion_id,
                price=buy_price[i],
                num=buy_num[i],
                order_type=0)
            buy_order_id_list.append(buy_order_id)

        for v in range(len(sell_price)):
            # 下卖单
            test_seller = Base(user=SELLER)
            sell_order_id = test_seller.SellOrder(transtion_id=transtion_id,
                                                  price=sell_price[v],
                                                  num=sell_num[v],
                                                  order_type=0)
            sell_order_id_list.append(sell_order_id)

        time.sleep(6)
        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)

        time.sleep(3)

        for t in buy_order_id_list:
            test_buyer = Base(user=BUYER)
            test_buyer.updateRevocationStatus(type=1, orderId=t)

        for k in sell_order_id_list:
            test_seller = Base(user=SELLER)
            test_seller.updateRevocationStatus(type=2, orderId=k)

        buy_order_status_list = []
        sell_order_status_list = []

        for _id in buy_order_id_list:
            buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
                order_id=_id, order_type=1)
            buy_order_status_list.append(buy_order_status)
        for sell_id in sell_order_id_list:
            sell_order_status = ConnectMysql(
                _type=mysql_type).get_Order_Status(order_id=sell_id,
                                                   order_type=2)
            sell_order_status_list.append(sell_order_status)
        logger.info("交易后买单状态:{0}-----交易后卖单状态:{1}".format(
            buy_order_status_list, sell_order_status_list))

        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }

        logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format(
            before_buy_main, after_buy_main))
        logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format(
            before_buy_target, after_buy_target))
        logger.info("交易前卖家主币余额:{0}--------交易后卖家主币余额:{1}".format(
            before_sell_main, after_sell_main))
        logger.info("交易前卖家目标币余额:{0}--------交易后卖家目标币余额:{1}".format(
            before_sell_target, after_sell_target))

        buy_value, deal_num, sell_value, sell_num_value = count_value_buy_first(
            buy_price, buy_num, sell_price, sell_num)

        self.assertEqual(
            int(after_buy_main),
            int(int(before_buy_main) - int(buy_value / 100000000)))
        self.assertEqual(
            int(after_buy_target),
            int(before_buy_target) + int(deal_num * (1 - 2 / 1000)))
        self.assertEqual(
            int(after_sell_main),
            int(before_sell_main) + int(sell_value / 100000000 *
                                        (1 - 2 / 1000)))
        self.assertEqual(int(after_sell_target),
                         int(before_sell_target) - int(sell_num_value))
Beispiel #10
0
    def test_02(self, number, transtion_id, main_currency_id,
                target_currency_id, buy_price, buy_num, sell_price, sell_num):
        """
        编号:56-2
        市价买单,普通用户,撤单
        """
        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("用例说明:编号:56-2-%s, 市价买单,普通用户,撤单" % number)
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=1)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=1)
        ConnectRedis(_type=redis_type).clear_redis(
            get_redis_name(transtion_id))

        buy_price, sell_price, buy_num, sell_num = int(buy_price), int(
            sell_price), int(buy_num), int(sell_num)

        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)
        test_buyer = Base(user=BUYER)
        buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id,
                                                    price=buy_price,
                                                    num=buy_num,
                                                    order_type=1)

        test_buyer.updateRevocationStatus(orderId=buy_order_id, type=1)

        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id,
            transaction_id=transtion_id,
            order_id=buy_order_id)
        buy_order_status = ConnectMysql(_type=mysql_type).get_Order_Status(
            order_id=buy_order_id, order_type=1)
        logger.info("撤单后买单状态:{0}-----".format(buy_order_status))
        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }
        logger.info("交易前买家主币余额:{0}--------交易后买家主币余额:{1}".format(
            before_buy_main, after_buy_main))
        logger.info("交易前买家目标币余额:{0}--------交易后买家目标币余额:{1}".format(
            before_buy_target, after_buy_target))
        self.assertEqual(int(before_buy_main), int(after_buy_main))
        self.assertEqual(int(before_buy_target), int(after_buy_target))
Beispiel #11
0
    def test_01(self):
        """
        下买卖单,达不到成交价格,循环撤单,验证余额
        """
        ConnectRedis(_type=redis_type).clear_redis(name=get_redis_name(
            transtion_id=transtion_id))
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=1, order_status=2)
        ConnectMysql(_type=mysql_type).update_order_status(
            transtion_id=transtion_id, order_type=2, order_status=2)

        logger.info(
            "<<==========================================================================================================================>"
        )

        logger.info("测试用例说明:".format(TestCase.test_01.__doc__))
        logger.info("买家账号:{0}--------卖家账号:{1}".format(BUYER, SELLER))
        logger.info("-----交易对ID:{0}-----主币ID:{1}-----目标币ID:{2}".format(
            transtion_id, main_currency_id, target_currency_id))
        # 下单前查询买卖双发的主币和目标币余额
        before_buy_main, before_buy_target, before_sell_main, before_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)

        logger.info("成交之前买家主币余额:{0}-----成交之前买家目标币余额:{1}".format(
            before_buy_main, before_buy_target))
        logger.info("成交之前卖家的主币余额:{0}------成交之前卖家的目标币余额{1}".format(
            before_sell_main, before_sell_target))

        logger.info("买入价格:{0}-----买入数量{1}".format(buy_price, buy_num))
        logger.info("卖出价格:{0}-----卖出数量{1}".format(sell_price, sell_num))

        self.buy_id_list = []

        # 下一个买单
        test_buyer = Base(user=BUYER)
        buy_order_id = test_buyer.OrderReservations(transtion_id=transtion_id,
                                                    price=buy_price,
                                                    num=buy_num,
                                                    order_type=0)

        # 下一个卖单
        test_seller = Base(user=SELLER)
        sell_order_id = test_seller.SellOrder(transtion_id=transtion_id,
                                              price=sell_price,
                                              num=sell_num,
                                              order_type=0)
        time.sleep(5)
        for i in range(10):
            test_buyer.updateRevocationStatus(type=1, orderId=buy_order_id)
            time.sleep(5)
            test_seller.updateRevocationStatus(type=2, orderId=sell_order_id)

        after_buy_main, after_buy_target, after_sell_main, after_sell_target = query_user_balance_value(
            buyer=BUYER,
            seller=SELLER,
            main_currency_id=main_currency_id,
            target_currency_id=target_currency_id)

        balance_dict = {
            "before_buy_main_balance": before_buy_main,
            "before_buy_target_balance": before_buy_target,
            "before_sell_main_balance": before_sell_main,
            "before_sell_target_balance": before_sell_target,
            "after_buy_main_balance": after_buy_main,
            "after_buy_target_balance": after_buy_target,
            "after_sell_main_balance": after_sell_main,
            "after_sell_target_balance": after_sell_target,
        }

        self.assertEqual(int(before_buy_main), int(after_buy_main))
        self.assertEqual(int(before_buy_target), int(after_buy_target))
        self.assertEqual(int(before_sell_main), int(after_sell_main))
        self.assertEqual(int(before_sell_target), int(after_sell_target))