Пример #1
0
def TIMED_CHECK_CREATE_TX(j):
    garbage_input_str1 = xbridge_utils.generate_garbage_input(j)
    garbage_input_str2 = xbridge_utils.generate_garbage_input(j)
    garbage_input_str3 = xbridge_utils.generate_garbage_input(j)
    garbage_input_str4 = xbridge_utils.generate_garbage_input(j)
    source_nb = xbridge_utils.generate_random_number(-9999999999999,
                                                     999999999999)
    dest_nb = xbridge_utils.generate_random_number(-9999999999999,
                                                   999999999999)
    ts = time.time()
    CHECK_CREATE_TX(garbage_input_str1, garbage_input_str2, source_nb,
                    garbage_input_str3, garbage_input_str4, dest_nb)
    # assert type(CHECK_ACCEPT_TX(garbage_input_str1, garbage_input_str2, garbage_input_str3)) == None
    te = time.time()
    return te - ts
 def test_getblockhash_invalid(self):
     try:
         regular_negative_int = xbridge_utils.generate_random_int(-1000, -1)
         large_negative_int = xbridge_utils.generate_random_int(
             -50000, -10000)
         very_large_positive_int = xbridge_utils.generate_random_int(
             100000000000000, 999999999999999999999999999)
         self.assertRaises(JSONRPCException,
                           xbridge_rpc.rpc_connection.getblockhash,
                           regular_negative_int)
         self.assertRaises(JSONRPCException,
                           xbridge_rpc.rpc_connection.getblockhash,
                           large_negative_int)
         self.assertRaises(JSONRPCException,
                           xbridge_rpc.rpc_connection.getblockhash,
                           very_large_positive_int)
         self.assertRaises(JSONRPCException,
                           xbridge_rpc.rpc_connection.getblockhash,
                           -0.0000000000001)
         self.assertRaises(JSONRPCException,
                           xbridge_rpc.rpc_connection.getblockhash,
                           0.0000000000001)
         random_negative_number = xbridge_utils.generate_random_number(
             -9999999999999999999999999999999999999999999999999999,
             -0.0000000000000000000000000000000000000000000000000000000000001
         )
         self.assertRaises(JSONRPCException,
                           xbridge_rpc.rpc_connection.getblockhash,
                           random_negative_number)
         xbridge_logger.XLOG("test_getblockhash_invalid", 0)
     except AssertionError as ass_err:
         xbridge_logger.XLOG("test_getblockhash_invalid", 1, ass_err, [
             regular_negative_int, large_negative_int,
             very_large_positive_int, random_negative_number
         ])
 def test_invalid_gettradehistory_v7(self):
     for i in range(subTest_count):
         with self.subTest("random garbage"):
             try:
                 if random.choice([True, False]) is True:
                     src_Token = self.valid_src_Token
                 else:
                     src_Token = random.choice(
                         xbridge_utils.set_of_invalid_parameters)
                 if random.choice([1, 2, 3, 4, 5]) == 5:
                     dest_Token = src_Token
                 else:
                     dest_Token = random.choice(
                         xbridge_utils.set_of_invalid_parameters)
                 if random.choice([True, False]) is True:
                     unix_starttime = time.time()
                 else:
                     unix_starttime = xbridge_utils.generate_random_number(
                         -9999999999999999999999999999999999999999999999, 0)
                 if random.choice([True, False]) is True:
                     unix_endtime = time.time()
                 else:
                     unix_endtime = xbridge_utils.generate_random_number(
                         -9999999999999999999999999999999999999999999999, 0)
                 showTxids_Type = random.choice([1, 2, 3, 4])
                 if showTxids_Type == 1:
                     showTxids = "txids"
                 if showTxids_Type == 2:
                     showTxids = None
                 # We do this so that the probability of having an invalid parameter is 1/2
                 if showTxids_Type == 3 or showTxids_Type == 4:
                     showTxids = random.choice(
                         xbridge_utils.set_of_invalid_parameters)
                 self.assertIsInstance(
                     xbridge_rpc.dxGetTradeHistory(src_Token, dest_Token,
                                                   unix_starttime,
                                                   unix_endtime), list)
                 xbridge_logger.XLOG("test_invalid_gettradehistory_v7", 0)
             except AssertionError as ass_err:
                 xbridge_logger.XLOG(
                     "test_invalid_gettradehistory_v7", 1, ass_err,
                     [src_Token, dest_Token, unix_starttime, unix_endtime])
             except JSONRPCException as json_excpt:
                 xbridge_logger.XLOG(
                     "test_invalid_gettradehistory_v7", 2, json_excpt,
                     [src_Token, dest_Token, unix_starttime, unix_endtime])
 def setUp(self):
     xbridge_utils.generate_new_set_of_data(
         data_nature=xbridge_utils.INVALID_DATA,
         char_min_size=1,
         char_max_size=10000)
     # Valid data
     self.valid_src_Token = xbridge_utils.generate_random_valid_token()
     self.valid_dest_Token = xbridge_utils.generate_random_valid_token()
     # Common pools from which parameters will be randomnly picked
     self.valid_token = xbridge_utils.generate_random_valid_token()
     self.token_pool = [self.valid_token, xbridge_utils.c_src_Token]
     self.invalid_short_str = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 40))
     self.invalid_med_str = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_long_str = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(5000, 15000))
 def setUp(self):
     xbridge_utils.generate_new_set_of_data(
         data_nature=xbridge_utils.INVALID_DATA,
         char_min_size=1,
         char_max_size=10000)
     # Valid data
     self.valid_txid = xbridge_utils.generate_random_valid_txid()
     self.valid_src_Address = xbridge_utils.generate_random_valid_address()
     self.valid_dest_Address = xbridge_utils.generate_random_valid_address()
     # Invalid data from garbage character classes
     self.invalid_txid = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_src_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_dest_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.long_txid = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(10000, 12000))
     self.long_src_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(10000, 12000))
     self.long_dest_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(10000, 12000))
     # Invalid data from random character classes
     self.input_str_from_random_classes_1 = xbridge_utils.generate_input_from_random_classes_combinations(
         1, 4000)
     self.input_str_from_random_classes_2 = xbridge_utils.generate_input_from_random_classes_combinations(
         9000, 12000)
     self.input_str_from_random_classes_3 = xbridge_utils.generate_input_from_random_classes_combinations(
         1, 100)
     valid_token = xbridge_utils.generate_random_valid_token()
     self.token_pool = [valid_token, xbridge_utils.c_src_Token]
     valid_address = xbridge_utils.generate_random_valid_address()
     invalid_address_short = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 40))
     invalid_address_med = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     invalid_address_long = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(5000, 15000))
     self.address_pool = [
         valid_address, invalid_address_short, invalid_address_med,
         invalid_address_long
     ]
     # Test many combinations of 0 to 10 000 white spaces
     self.simple_whitespace = ""
     self.whitespace_str_1 = StringGenerator('[\s]{1:10000}').render()
     self.whitespace_str_2 = StringGenerator('[\s]{1:10000}').render()
     self.whitespace_str_3 = StringGenerator('[\s]{1:10000}').render()
     self.whitespace_pool = [
         self.simple_whitespace, self.whitespace_str_1,
         self.whitespace_str_2, self.whitespace_str_3
     ]
 def setUp(self):
     # Valid data
     self.valid_txid = xbridge_utils.generate_random_valid_txid()
     self.valid_src_Token = xbridge_utils.generate_random_valid_token()
     self.valid_dest_Token = xbridge_utils.generate_random_valid_token()
     self.valid_src_Address = xbridge_utils.generate_random_valid_address()
     self.valid_dest_Address = xbridge_utils.generate_random_valid_address()
     self.valid_positive_nb_1 = xbridge_utils.generate_random_number(
         1, 10000)
     self.valid_positive_nb_2 = xbridge_utils.generate_random_number(
         1, 10000)
     # Invalid data
     self.invalid_neg_nb = xbridge_utils.generate_random_number(
         -99999999999999999999999999999999999999999999999,
         -0.0000000000000000000000000000000000000000000000000001)
     self.invalid_sm_positive_nb = 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
     self.invalid_lg_positive_nb = 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
     self.invalid_src_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_dest_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_src_Token = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 500))
     self.invalid_dest_Token = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 500))
     self.nb_with_leading_zeros_1 = xbridge_utils.generate_random_number_with_leading_zeros(
     )
     self.nb_with_leading_zeros_2 = xbridge_utils.generate_random_number_with_leading_zeros(
     )
def test_createtx_garbage_load_v2(nb_of_runs):
    time_distribution = []
    total_elapsed_seconds = 0
    for i in range(1, nb_of_runs):
        garbage_input_str1 = xbridge_utils.generate_garbage_input(
            xbridge_utils.generate_random_number(1, 10000))
        garbage_input_str2 = xbridge_utils.generate_garbage_input(
            xbridge_utils.generate_random_number(1, 10000))
        garbage_input_str3 = xbridge_utils.generate_garbage_input(
            xbridge_utils.generate_random_number(1, 10000))
        garbage_input_str4 = xbridge_utils.generate_garbage_input(
            xbridge_utils.generate_random_number(1, 10000))
        source_nb = xbridge_utils.generate_random_number(
            -99999999999999999999999999999999999999999999999,
            99999999999999999999999999999999999999999999999)
        dest_nb = xbridge_utils.generate_random_number(
            -99999999999999999999999999999999999999999999999,
            99999999999999999999999999999999999999999999999)
        ts = time.time()
        xbridge_client.CHECK_CREATE_TX(garbage_input_str1, garbage_input_str2,
                                       source_nb, garbage_input_str3,
                                       garbage_input_str4, dest_nb)
        te = time.time()
        total_elapsed_seconds += te - ts
        json_str = {"time": te - ts, "API": "dxCreateTransaction"}
        time_distribution.append(json_str)
    xbridge_utils.export_data("test_createtx_garbage_load_v2.xlsx",
                              time_distribution)
def test_cancel_load_v2(nb_of_runs):
    time_distribution = []
    total_elapsed_seconds = 0
    for i in range(1, nb_of_runs):
        garbage_input_str = xbridge_utils.generate_garbage_input(
            xbridge_utils.generate_random_number(1, 10000))
        ts = time.time()
        assert type(xbridge_client.CHECK_CANCEL_TX(garbage_input_str)) == dict
        te = time.time()
        total_elapsed_seconds += te - ts
        json_str = {
            "time": te - ts,
            "char_nb": len(garbage_input_str),
            "API": "dxCancel"
        }
        time_distribution.append(json_str)
    xbridge_utils.export_data("test_cancel_load_v2.xlsx", time_distribution)
def test_get_tx_info_load_v2(nb_of_runs):
    time_distribution = []
    total_elapsed_seconds = 0
    for i in range(1, nb_of_runs):
        garbage_input_str = xbridge_utils.generate_garbage_input(
            int(xbridge_utils.generate_random_number(1, 10000)))
        ts = time.time()
        assert type(
            xbridge_client.CHECK_GET_TX_INFO(garbage_input_str)) == list
        te = time.time()
        total_elapsed_seconds += te - ts
        json_str = {
            "time": te - ts,
            "char_nb": len(garbage_input_str),
            "API": "dxGetTxInfo"
        }
        time_distribution.append(json_str)
    xbridge_utils.export_data("test_get_tx_info_load_v2.xlsx",
                              time_distribution)
 def setUp(self):
     # Valid data
     self.valid_txid = xbridge_utils.generate_random_valid_txid()
     self.valid_src_Address = xbridge_utils.generate_random_valid_address()
     self.valid_dest_Address = xbridge_utils.generate_random_valid_address()
     # Invalid data
     self.invalid_txid = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_src_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_dest_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.long_txid = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(10000, 12000))
     self.long_src_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(10000, 12000))
     self.long_dest_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(10000, 12000))
 def setUp(self):
     xbridge_utils.generate_new_set_of_data(
         data_nature=xbridge_utils.INVALID_DATA,
         char_min_size=1,
         char_max_size=10000)
     # Valid data
     self.valid_txid = xbridge_utils.generate_random_valid_txid()
     self.valid_src_Token = xbridge_utils.generate_random_valid_token()
     self.valid_dest_Token = xbridge_utils.generate_random_valid_token()
     self.valid_src_Address = xbridge_utils.generate_random_valid_address()
     self.valid_dest_Address = xbridge_utils.generate_random_valid_address()
     self.valid_positive_nb_1 = xbridge_utils.generate_random_number(
         1, 10000)
     self.valid_positive_nb_2 = xbridge_utils.generate_random_number(
         1, 10000)
     # Invalid data
     self.invalid_neg_nb = xbridge_utils.generate_random_number(
         -99999999999999999999999999999999999999999999999,
         -0.0000000000000000000000000000000000000000000000000001)
     self.invalid_sm_positive_nb = xbridge_utils.generate_random_number(
         0.000000000000000000000000001,
         0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
     )
     self.invalid_lg_positive_nb = xbridge_utils.generate_random_number(
         9999999999999999999999999999999999,
         999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
     )
     self.invalid_src_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_dest_Address = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     self.invalid_src_Token = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 500))
     self.invalid_dest_Token = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 500))
     self.nb_with_leading_zeros_1 = xbridge_utils.generate_random_number_with_leading_zeros(
     )
     self.nb_with_leading_zeros_2 = xbridge_utils.generate_random_number_with_leading_zeros(
     )
     # Common pools from which parameters will be randomnly picked
     valid_token = xbridge_utils.generate_random_valid_token()
     self.token_pool = [valid_token, xbridge_utils.c_src_Token]
     valid_address = xbridge_utils.generate_random_valid_address()
     invalid_address_short = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 40))
     invalid_address_med = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(1, 5000))
     invalid_address_long = xbridge_utils.generate_garbage_input(
         xbridge_utils.generate_random_number(5000, 15000))
     self.address_pool = [
         valid_address, invalid_address_short, invalid_address_med,
         invalid_address_long
     ]
     self.amount_pool = [
         xbridge_utils.invalid_random_positive_float,
         xbridge_utils.valid_random_positive_float,
         -xbridge_utils.invalid_random_positive_float,
         -xbridge_utils.valid_random_positive_float,
         xbridge_utils.fixed_small_positive_float,
         xbridge_utils.fixed_large_positive_int, 0
     ]