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_getorderbook_v2(self): for i in range(subTest_count): with self.subTest("random garbage"): try: detailLevel_Type = random.choice([1, 2, 3]) if detailLevel_Type == 1: detailLevel = self.valid_detailLevel if detailLevel_Type == 2: detailLevel = xbridge_utils.generate_random_int(-50, 0) if detailLevel_Type == 3: detailLevel = xbridge_utils.generate_random_int( 4, 9999999999999999999999999999999) 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: maxOrders = xbridge_utils.generate_random_int(-50, 50) else: maxOrders = None 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.dxGetOrderBook(detailLevel, src_Token, dest_Token, maxOrders, showTxids), dict) xbridge_logger.XLOG("test_invalid_getorderbook_v2", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_invalid_getorderbook_v2", 1, ass_err, [ detailLevel, src_Token, dest_Token, maxOrders, showTxids ]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_invalid_getorderbook_v2", 2, json_excpt, [ detailLevel, src_Token, dest_Token, maxOrders, showTxids ])
def test_walletpassphrase_invalid(self): try: log_json = "" random_str = random.choice([ xbridge_utils.invalid_str_from_random_classes_1, xbridge_utils.invalid_str_from_random_classes_2, xbridge_utils.invalid_str_from_random_classes_3, xbridge_utils.invalid_str_from_random_classes_4 ]) random_int = xbridge_utils.generate_random_int( -999999999999, 999999999999) if random.choice(["", random.choice([True, False])]) == "": random_bool = None else: random_bool = random.choice([True, False]) self.assertRaises(xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.walletpassphrase, random_str, random_int, random_bool) xbridge_logger.XLOG("test_walletpassphrase_invalid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_walletpassphrasechange_invalid", 1, ass_err, [random_str, random_int, random_bool]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_walletpassphrasechange_invalid", 2, json_excpt, [random_str, random_int, random_bool])
def test_walletpassphrase_valid(self): try: log_json = "" if xbridge_config.get_wallet_decryption_passphrase() == "": return valid_passphrase = xbridge_config.get_wallet_decryption_passphrase( ) random_int = xbridge_utils.generate_random_int( -999999999999, 999999999999) self.assertIsNone( xbridge_rpc.walletpassphrase(valid_passphrase, random_int, False)) time_str = time.strftime("%Y%m%d-%H%M%S") dumped_wallet_str = xbridge_config.get_conf_log_dir( ) + time_str + "_dumped_wallet.dat" self.assertIsNone( xbridge_utils.rpc_connection.dumpwallet(dumped_wallet_str)) self.assertIsNone(xbridge_rpc.walletlock()) xbridge_logger.XLOG("test_walletpassphrase_valid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_walletpassphrase_valid", 1, ass_err, [dumped_wallet_str]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_walletpassphrase_valid", 2, json_excpt, [dumped_wallet_str])
def test_listreceivedbyaccount_valid(self): log_json = "" try: self.assertIsInstance( xbridge_rpc.rpc_connection.listreceivedbyaccount(), list) optional_minconf = xbridge_utils.generate_random_int( -9999999999, 9999999999) optional_includeempty = random.choice([True, False]) optional_includeWatchonly = random.choice([True, False]) self.assertIsInstance( xbridge_rpc.rpc_connection.listreceivedbyaccount( optional_minconf, optional_includeempty, optional_includeWatchonly), list) xbridge_logger.XLOG("test_listreceivedbyaccount_valid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_listreceivedbyaccount_valid", 1, ass_err, [ optional_minconf, optional_includeempty, optional_includeWatchonly ]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_listreceivedbyaccount_valid", 1, json_excpt, [ optional_minconf, optional_includeempty, optional_includeWatchonly ])
def test_signmessage_invalid(self): if xbridge_config.get_wallet_decryption_passphrase() == "": return valid_passphrase = xbridge_config.get_wallet_decryption_passphrase() random_int = xbridge_utils.generate_random_int(-999999999999, 999999999999) xbridge_rpc.walletpassphrase(valid_passphrase, random_int, False) custom_set = [ x for x in xbridge_utils.set_of_invalid_parameters if not isinstance(x, bool) ] for i in range(subTest_count): log_json = "" with self.subTest("test_signmessage_invalid"): try: invalid_blocknet_address = random.choice(custom_set) message = random.choice(custom_set) self.assertRaises( xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.signmessage, invalid_blocknet_address, message) log_json = { "group": "test_signmessage_invalid", "success": 1, "failure": 0, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) except AssertionError as ass_err: log_json = { "group": "test_signmessage_invalid", "success": 0, "failure": 1, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) xbridge_logger.logger.info( 'test_signmessage_invalid FAILED: %s' % ass_err) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info( 'invalid_blocknet_address: %s \n' % str(invalid_blocknet_address)[:MAX_LOG_LENGTH]) xbridge_logger.logger.info( 'param: %s \n' % str(message)[:MAX_LOG_LENGTH]) except JSONRPCException as json_excpt: log_json = { "group": "test_signmessage_invalid", "success": 0, "failure": 0, "error": 1 } xbridge_utils.ERROR_LOG.append(log_json) xbridge_logger.logger.info( 'test_signmessage_invalid ERROR: %s' % json_excpt) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info( 'invalid_blocknet_address: %s \n' % str(invalid_blocknet_address)[:MAX_LOG_LENGTH]) xbridge_logger.logger.info( 'param: %s \n' % str(message)[:MAX_LOG_LENGTH])
def test_getaddednodeinfo_invalid(self): log_json = "" if xbridge_config.get_wallet_decryption_passphrase() == "": return valid_passphrase = xbridge_config.get_wallet_decryption_passphrase() random_int = xbridge_utils.generate_random_int(-999999999999, 999999999999) xbridge_rpc.walletpassphrase(valid_passphrase, random_int, False) self.assertIsInstance(xbridge_rpc.rpc_connection.getaddednodeinfo(True), list) self.assertIsInstance(xbridge_rpc.rpc_connection.getaddednodeinfo(False), list) for i in range(subTest_count): log_json = "" with self.subTest("comb"): try: dns = random.choice(xbridge_utils.set_of_invalid_parameters) node = random.choice(xbridge_utils.set_of_invalid_parameters) self.assertRaises(xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.getaddednodeinfo, dns, node) log_json = {"group": "test_getaddednodeinfo_invalid", "success": 1, "failure": 0, "error": 0} xbridge_utils.ERROR_LOG.append(log_json) except AssertionError as ass_err: log_json = {"group": "test_getaddednodeinfo_invalid", "success": 0, "failure": 1, "error": 0} xbridge_utils.ERROR_LOG.append(log_json) xbridge_logger.logger.info('test_getaddednodeinfo_invalid FAILED: %s' % ass_err) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info('dns: %s' % str(dns)[:MAX_LOG_LENGTH]) xbridge_logger.logger.info('node: %s' % str(dns)[:MAX_LOG_LENGTH]) except JSONRPCException as json_excpt: xbridge_logger.logger.info('test_getaddednodeinfo_invalid ERROR: %s' % str(json_excpt)) log_json = {"group": "test_getaddednodeinfo_invalid", "success": 0, "failure": 0, "error": 1} xbridge_utils.ERROR_LOG.append(log_json) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info('dns: %s' % str(dns)[:MAX_LOG_LENGTH]) xbridge_logger.logger.info('node: %s' % str(dns)[:MAX_LOG_LENGTH])
def test_addnode_invalid(self): if xbridge_config.get_wallet_decryption_passphrase() == "": return valid_passphrase = xbridge_config.get_wallet_decryption_passphrase() random_int = xbridge_utils.generate_random_int(1, 9999) for i in range(subTest_count): log_json = "" with self.subTest("comb"): try: node = random.choice(xbridge_utils.set_of_invalid_parameters) cmd = random.choice(xbridge_utils.set_of_invalid_parameters) xbridge_rpc.walletpassphrase(valid_passphrase, random_int, False) self.assertRaises(xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.addnode, node, cmd) log_json = {"group": "test_addnode_invalid", "success": 1, "failure": 0, "error": 0} xbridge_utils.ERROR_LOG.append(log_json) except AssertionError as ass_err: log_json = {"group": "test_addnode_invalid", "success": 0, "failure": 1, "error": 0} xbridge_utils.ERROR_LOG.append(log_json) xbridge_logger.logger.info('test_addnode_invalid FAILED: %s' % ass_err) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info('node: %s' % str(node)[:MAX_LOG_LENGTH]) xbridge_logger.logger.info('cmd: %s' % str(cmd)[:MAX_LOG_LENGTH]) except JSONRPCException as json_excpt: xbridge_logger.logger.info('test_addnode_invalid ERROR: %s' % str(json_excpt)) log_json = {"group": "test_addnode_invalid", "success": 0, "failure": 0, "error": 1} xbridge_utils.ERROR_LOG.append(log_json) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info('node: %s' % str(node)[:MAX_LOG_LENGTH]) xbridge_logger.logger.info('cmd: %s' % str(cmd)[:MAX_LOG_LENGTH])
def test_getblockhash_valid(self): try: regular_int = xbridge_utils.generate_random_int(1, 10000) self.assertIsInstance(xbridge_rpc.rpc_connection.getblockhash(0), str) self.assertIsInstance( xbridge_rpc.rpc_connection.getblockhash(regular_int), str) xbridge_logger.XLOG("test_getblockhash_valid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getblockhash_valid", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getblockhash_valid", 2, json_excpt)
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() # detailLevel self.valid_detailLevel = random.choice([1, 2, 3]) self.invalid_detailLevel = xbridge_utils.generate_random_int( 4, 99999999999999999999) self.negative_invalid_detailLevel = xbridge_utils.generate_random_int( -99999999999999999999, -1) # Common pools from which parameters will be randomnly picked self.token_pool = [self.valid_src_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 test_backupwallet_invalid(self): if xbridge_config.get_wallet_decryption_passphrase() == "": return # print("wallet passphrase: " + xbridge_config.get_wallet_decryption_passphrase()) valid_passphrase = xbridge_config.get_wallet_decryption_passphrase() random_int = xbridge_utils.generate_random_int(-999999999999, 999999999999) random_bool = random.choice([True, False]) self.assertIsNone(xbridge_rpc.walletpassphrase(valid_passphrase, random_int, False)) for basic_garbage_str in xbridge_utils.set_of_invalid_parameters: with self.subTest(basic_garbage_str=basic_garbage_str): try: self.assertIsNone(xbridge_rpc.rpc_connection.backupwallet, basic_garbage_str) xbridge_logger.XLOG("test_backupwallet_invalid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_backupwallet_invalid", 1, ass_err, [basic_garbage_str]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_backupwallet_invalid", 2, json_excpt, [basic_garbage_str])
def test_listaccounts_valid_2(self): for i in range(subTest_count): log_json = "" with self.subTest("combinations"): try: optional_minconf = xbridge_utils.generate_random_int( -9999999, 9999999) optional_includeWatchonly = random.choice([True, False]) self.assertIsInstance(xbridge_rpc.listaccounts(), dict) log_json = { "group": "test_listaccounts_valid_2", "success": 1, "failure": 0, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) except AssertionError as ass_err: xbridge_logger.XLOG( "test_listaccounts_valid_2", 1, ass_err, [optional_minconf, optional_includeWatchonly]) except JSONRPCException as json_excpt: xbridge_logger.XLOG( "test_listaccounts_valid_2", 2, json_excpt, [optional_minconf, optional_includeWatchonly])
def test_invalid_getorderbook_v1f(self): for i in range(subTest_count): with self.subTest("random garbage"): try: detailLevel = self.valid_detailLevel src_Token = self.valid_src_Token if random.choice([1, 2, 3, 4, 5]) == 5: dest_Token = src_Token else: dest_Token = self.valid_dest_Token if random.choice([True, False]) is True: maxOrders = xbridge_utils.generate_random_int( -99999999999999999999, 0) else: maxOrders = None if random.choice([True, False]) is True: showTxids = "txids" else: showTxids = None self.assertIsInstance( xbridge_rpc.dxGetOrderBook(detailLevel, src_Token, dest_Token, maxOrders, showTxids), dict) xbridge_logger.XLOG("test_invalid_getorderbook_v1f", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_invalid_getorderbook_v1f", 1, ass_err, [ detailLevel, src_Token, dest_Token, maxOrders, showTxids ]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_invalid_getorderbook_v1f", 2, json_excpt, [ detailLevel, src_Token, dest_Token, maxOrders, showTxids ])
def test_autocombinerewards_valid(self): try: if xbridge_config.get_wallet_decryption_passphrase() == "": return valid_passphrase = xbridge_config.get_wallet_decryption_passphrase( ) random_int = xbridge_utils.generate_random_int( -999999999999, 999999999999) xbridge_rpc.walletpassphrase(valid_passphrase, random_int, False) log_json = "" success_str = "Auto Combine Rewards Threshold Set" xbridge_utils.generate_new_set_of_data( data_nature=xbridge_utils.VALID_DATA) self.assertEqual( xbridge_rpc.rpc_connection.autocombinerewards(False), success_str) self.assertEqual( xbridge_rpc.rpc_connection.autocombinerewards( False, -99999999999999), success_str) self.assertEqual( xbridge_rpc.rpc_connection.autocombinerewards(True, 0), success_str) self.assertEqual( xbridge_rpc.rpc_connection.autocombinerewards( True, xbridge_utils.valid_random_positive_int), success_str) self.assertEqual( xbridge_rpc.rpc_connection.autocombinerewards( True, -xbridge_utils.valid_random_positive_int), success_str) log_json = { "group": "test_autocombinerewards_valid", "success": 1, "failure": 0, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) except AssertionError as ass_err: log_json = { "group": "test_autocombinerewards_valid", "success": 0, "failure": 1, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) xbridge_logger.logger.info( 'test_autocombinerewards_valid FAILED: %s' % ass_err) if MAX_LOG_LENGTH > 0: xbridge_logger.logger.info( 'fixed_positive_int: %s \n' % str(xbridge_utils.fixed_positive_int)) xbridge_logger.logger.info( 'fixed_negative_int: %s \n' % str(xbridge_utils.fixed_negative_int)) xbridge_logger.logger.info( 'valid_random_positive_int: %s \n' % str(xbridge_utils.valid_random_positive_int)) except JSONRPCException as json_excpt: log_json = { "group": "test_autocombinerewards_valid", "success": 0, "failure": 0, "error": 1 } xbridge_utils.ERROR_LOG.append(log_json) xbridge_logger.logger.info( 'test_autocombinerewards_valid ERROR: %s' % json_excpt)