def test_invalid_accept_tx_5(self): for i in range(subTest_count): with self.subTest("combinations"): try: txid_from_invalid_set = random.choice( xbridge_utils.set_of_invalid_parameters) picked_txid = random.choice( [txid_from_invalid_set, self.valid_txid]) self.assertIsInstance( xbridge_rpc.accept_tx(picked_txid, self.valid_src_Address, self.valid_src_Address), dict) xbridge_logger.XLOG("test_invalid_accept_tx_5", 0) except AssertionError as ass_err: xbridge_logger.XLOG( "test_invalid_accept_tx_5", 1, ass_err, [ picked_txid, self.valid_src_Address, self.valid_src_Address ]) except JSONRPCException as json_excpt: xbridge_logger.XLOG( "test_invalid_accept_tx_5", 2, json_excpt, [ picked_txid, self.valid_src_Address, self.valid_src_Address ])
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_invalid_create_tx_v0(self): for i in range(subTest_count): with self.subTest("random garbage"): try: src_Address = random.choice( xbridge_utils.set_of_invalid_parameters) dest_Address = random.choice( xbridge_utils.set_of_invalid_parameters) src_Token = random.choice( xbridge_utils.set_of_invalid_parameters) dest_Token = random.choice( xbridge_utils.set_of_invalid_parameters) fromAmount = random.choice( xbridge_utils.set_of_invalid_parameters) toAmount = random.choice( xbridge_utils.set_of_invalid_parameters) self.assertIsInstance( xbridge_rpc.create_tx(src_Address, src_Token, fromAmount, dest_Address, dest_Token, toAmount), dict) xbridge_logger.XLOG("test_invalid_create_tx_v0", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_invalid_create_tx_v0", 1, ass_err, [ src_Address, src_Token, fromAmount, dest_Address, dest_Token, toAmount ]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_invalid_create_tx_v0", 2, json_excpt, [ src_Address, src_Token, fromAmount, dest_Address, dest_Token, toAmount ])
def test_estimatefee(self): for basic_str in xbridge_utils.set_of_invalid_parameters: log_json = "" with self.subTest(basic_str=basic_str): try: if isinstance(basic_str, int): if basic_str in ( -9999999999999999999999999999999999999999999999999999999999999999, 9999999999999999999999999999999999999999999999999999999999999999 ): self.assertIsNone( xbridge_rpc.estimatepriority(basic_str)) else: self.assertIsInstance( xbridge_rpc.estimatepriority(basic_str), Decimal) else: self.assertIsNone(xbridge_rpc.estimatefee(basic_str)) xbridge_logger.XLOG("test_estimatefee", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_estimatefee", 1, ass_err, [basic_str]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_estimatefee", 2, json_excpt, [basic_str])
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_mnsync_valid(self): valid_params = ["status", "reset"] for valid_param in valid_params: log_json = "" with self.subTest(valid_param=valid_param): try: if valid_param == "reset": self.assertIsInstance( xbridge_rpc.rpc_connection.mnsync(valid_param), str) log_json = { "group": "test_mnsync_valid", "success": 1, "failure": 0, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) else: self.assertIsInstance( xbridge_rpc.rpc_connection.mnsync(valid_param), dict) log_json = { "group": "test_mnsync_valid", "success": 1, "failure": 0, "error": 0 } xbridge_utils.ERROR_LOG.append(log_json) except AssertionError as ass_err: xbridge_logger.XLOG("test_mnsync_valid", 1, ass_err, [valid_param]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_mnsync_valid", 2, json_excpt, [valid_param])
def test_invalid_gettradehistory_v2(self): for i in range(subTest_count): with self.subTest("random garbage"): try: src_Token = self.valid_token dest_Token = random.choice( xbridge_utils.set_of_invalid_parameters) unix_starttime = random.choice( xbridge_utils.set_of_invalid_parameters) unix_endtime = random.choice( xbridge_utils.set_of_invalid_parameters) if random.choice([True, False]) is True: showTxids = random.choice( xbridge_utils.set_of_invalid_parameters) else: showTxids = None self.assertIsInstance( xbridge_rpc.dxGetTradeHistory(src_Token, dest_Token, unix_starttime, unix_endtime, showTxids), list) xbridge_logger.XLOG("test_invalid_gettradehistory_v2", 0) except AssertionError as ass_err: xbridge_logger.XLOG( "test_invalid_gettradehistory_v2", 1, ass_err, [ src_Token, dest_Token, unix_starttime, unix_endtime, showTxids ]) except JSONRPCException as json_excpt: xbridge_logger.XLOG( "test_invalid_gettradehistory_v2", 2, json_excpt, [ src_Token, dest_Token, unix_starttime, unix_endtime, showTxids ])
def test_get_blockcount(self): try: self.assertIsInstance(xbridge_rpc.get_blockcount(), int) self.assertGreater(xbridge_rpc.get_blockcount(), 120000) xbridge_logger.XLOG("test_get_blockcount", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_get_blockcount", 1, ass_err)
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_getaddressesbyaccount(self): for basic_garbage_str in xbridge_utils.set_of_invalid_parameters: with self.subTest(basic_garbage_str=basic_garbage_str): try: if isinstance(basic_garbage_str, str): self.assertIsInstance( xbridge_rpc.getaddressesbyaccount( basic_garbage_str), Decimal) elif basic_garbage_str in ( -9999999999999999999999999999999999999999999999999999999999999999, 9999999999999999999999999999999999999999999999999999999999999999 ): self.assertIsNone( xbridge_rpc.getaddressesbyaccount( basic_garbage_str)) else: self.assertRaises( xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.getaddressesbyaccount, basic_garbage_str) xbridge_logger.XLOG("test_getaddressesbyaccount", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getaddressesbyaccount", 1, ass_err, [basic_garbage_str]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getaddressesbyaccount", 2, json_excpt, [basic_garbage_str])
def test_estimatepriority(self): # modified_set = [x for x in xbridge_utils.set_of_invalid_parameters if not isinstance(x, int)] for basic_str in xbridge_utils.set_of_invalid_parameters: log_json = "" with self.subTest(basic_str=basic_str): try: if isinstance(basic_str, int): if basic_str in ( -9999999999999999999999999999999999999999999999999999999999999999, 9999999999999999999999999999999999999999999999999999999999999999 ): self.assertIsNone( xbridge_rpc.estimatepriority(basic_str)) else: self.assertIsInstance( xbridge_rpc.estimatepriority(basic_str), Decimal) else: self.assertRaises( xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.estimatepriority, basic_str) xbridge_logger.XLOG("test_estimatepriority", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_estimatepriority", 1, ass_err, [basic_str]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_estimatepriority", 2, json_excpt, [basic_str])
def test_listreceivedbyaccount_invalid(self): custom_set = [ x for x in xbridge_utils.set_of_invalid_parameters if x is not None ] for i in range(subTest_count): with self.subTest("subtest combinations"): try: optional_minconf = random.choice(custom_set) optional_includeempty = random.choice(custom_set) optional_includeWatchonly = random.choice(custom_set) if isinstance(optional_minconf, int) and isinstance( optional_includeempty, bool) and isinstance( optional_includeWatchonly, bool): continue self.assertRaises( xbridge_custom_exceptions.ValidBlockNetException, xbridge_rpc.listreceivedbyaccount, optional_minconf, optional_includeempty, optional_includeWatchonly) xbridge_logger.XLOG("test_listreceivedbyaccount_invalid", 0) except AssertionError as ass_err: xbridge_logger.XLOG( "test_listreceivedbyaccount_valid", 1, ass_err, [ optional_minconf, optional_includeempty, optional_includeWatchonly ])
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_get_difficulty(self): try: self.assertIsInstance(xbridge_rpc.rpc_connection.getdifficulty(), Decimal) self.assertGreater(xbridge_rpc.rpc_connection.getdifficulty(), 100) xbridge_logger.XLOG("test_get_difficulty", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_get_difficulty", 1, ass_err)
def test_getmempoolinfo(self): try: self.assertIsInstance(xbridge_rpc.rpc_connection.getmempoolinfo(), dict) xbridge_logger.XLOG("test_getmempoolinfo", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getmempoolinfo", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getmempoolinfo", 2, json_excpt)
def test_getbestblockhash(self): try: self.assertIsInstance( xbridge_rpc.rpc_connection.getbestblockhash(), str) xbridge_logger.XLOG("getbestblockhash", 0) except AssertionError as ass_err: xbridge_logger.XLOG("getbestblockhash", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("getbestblockhash", 2, json_excpt)
def test_getchaintips(self): try: self.assertIsInstance(xbridge_rpc.rpc_connection.getchaintips(), list) xbridge_logger.XLOG("test_getchaintips", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getchaintips", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getchaintips", 2, json_excpt)
def test_listlockunspent(self): try: self.assertIsInstance(xbridge_rpc.rpc_connection.listlockunspent(), list) xbridge_logger.XLOG("test_listlockunspent", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_listlockunspent", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_listlockunspent", 2, json_excpt)
def test_get_budget_valid(self): try: budget = xbridge_rpc.get_budget() self.assertIsInstance(budget, dict) xbridge_logger.XLOG("test_get_budget_valid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_get_budget_valid", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_get_budget_valid", 2, json_excpt)
def test_getunconfirmedbalance(self): try: log_json = "" self.assertIsInstance( xbridge_rpc.rpc_connection.getunconfirmedbalance(), Decimal) xbridge_logger.XLOG("test_getunconfirmedbalance", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getunconfirmedbalance", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getunconfirmedbalance", 2, json_excpt)
def test_get_stake_threshold(self): try: log_json = "" self.assertIsInstance( xbridge_rpc.rpc_connection.getstakesplitthreshold(), dict) xbridge_logger.XLOG("test_get_stake_threshold", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_get_stake_threshold", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_get_stake_threshold", 2, json_excpt)
def test_getaccount(self): for basic_garbage_str in xbridge_utils.set_of_invalid_parameters: with self.subTest(basic_garbage_str=basic_garbage_str): try: self.assertRaises(JSONRPCException, xbridge_rpc.rpc_connection.getaccount, basic_garbage_str) xbridge_logger.XLOG("test_getaccount", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getaccount", 1, ass_err, [basic_garbage_str])
def test_getrawchangeaddress(self): try: log_json = "" new_address = xbridge_rpc.rpc_connection.getrawchangeaddress() self.assertIsInstance(new_address, str) self.assertEqual(len(new_address), 34) xbridge_logger.XLOG("test_getrawchangeaddress", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getrawchangeaddress", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getrawchangeaddress", 2, json_excpt)
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 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_getrawmempool_valid(self): try: self.assertIsInstance( xbridge_rpc.rpc_connection.getrawmempool(True), dict) self.assertIsInstance( xbridge_rpc.rpc_connection.getrawmempool(False), list) self.assertIsInstance(xbridge_rpc.rpc_connection.getrawmempool(), list) xbridge_logger.XLOG("test_getrawmempool_valid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getrawmempool_valid", 1, ass_err) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getrawmempool_valid", 2, json_excpt)
def test_validateaddress_valid(self): try: valid_block_address = xbridge_utils.generate_valid_blocknet_address( ) self.assertIsInstance( xbridge_rpc.validateaddress(valid_block_address), dict) xbridge_logger.XLOG("test_validateaddress_valid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_validateaddress_valid", 1, ass_err, [valid_block_address]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_validateaddress_valid", 2, json_excpt, [valid_block_address])
def test_servicenode_invalid(self): for i in range(subTest_count): log_json = "" with self.subTest("test_servicenode_invalid"): try: cmd_param = random.choice( xbridge_utils.set_of_invalid_parameters) self.assertRaises(JSONRPCException, xbridge_rpc.rpc_connection.servicenode, cmd_param) xbridge_logger.XLOG("test_servicenode_invalid", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_servicenode_invalid", 1, ass_err, [cmd_param])
def test_getnewaddress(self): try: log_json = "" xbridge_rpc.rpc_connection.keypoolrefill(1000) new_address = xbridge_rpc.rpc_connection.getnewaddress() self.assertIsInstance(new_address, str) self.assertEqual(len(new_address), 34) xbridge_logger.XLOG("test_getnewaddress", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_getnewaddress", 1, ass_err, [new_address]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_getnewaddress", 2, json_excpt, [new_address])
def test_invalid_cancel_2(self): string_length=64 for itm in [xbridge_utils.one_classes_list, xbridge_utils.two_classes_list, xbridge_utils.three_classes_list, xbridge_utils.four_classes_list, xbridge_utils.five_classes_list]: for sub_item in itm: with self.subTest(sub_item=sub_item): clss_str = sub_item + "{" + str(string_length) + "}" try: generated_str = StringGenerator(clss_str).render() self.assertIsInstance(xbridge_rpc.cancel_tx(generated_str), dict) xbridge_logger.XLOG("test_invalid_cancel_2", 0) except AssertionError as ass_err: xbridge_logger.XLOG("test_invalid_cancel_2", 1, ass_err, [generated_str]) except JSONRPCException as json_excpt: xbridge_logger.XLOG("test_invalid_cancel_2", 2, json_excpt, [generated_str])