def test_json_rpc(): # TODO: Broken api_server = api.APIServer() api_server.daemon = True api_server.start() url = 'http://' + str( config.RPC_USER) + ':' + config.RPC_PASSWORD + '@localhost:' + str( config.RPC_PORT) # TEMP: Use external server. url = 'http://' + str( config.RPC_USER) + ':' + config.RPC_PASSWORD + '@localhost:' + '14000' headers = {'content-type': 'application/json'} payloads = [] # payloads.append({ # "method": "get_balances", # "params": {"filters": {'field': 'address', 'op': '==', 'value': 'mtQheFaSfWELRB2MyMBaiWjdDm6ux9Ezns'}}, # "jsonrpc": "2.0", # "id": 0, # }) payloads.append({ "method": "create_send", "params": { 'source': 'mtQheFaSfWELRB2MyMBaiWjdDm6ux9Ezns', 'destination': destination_default, 'asset': config.XCP, 'quantity': 1, 'encoding': 'pubkeyhash', 'pubkey': '0319f6e07b0b8d756156394b9dcf3b011fe9ac19f2700bd6b69a6a1783dbb8b977' }, "jsonrpc": "2.0", "id": 0, }) for payload in payloads: for attempt in range(100): # Try until server is ready. try: response = requests.post(url, data=json.dumps(payload), headers=headers).json() # print('\npayload', payload) # print('response', response, '\n') if not response['result']: raise Exception('null result') assert False assert response['jsonrpc'] == '2.0' assert response['id'] == 0 output_new['rpc.' + payload['method']] = response['result'] break except requests.exceptions.ConnectionError: time.sleep(.05) if attempt == 99: exit(1) # Fail
def setup_module(): counterpartyd.set_options(database_file=tempfile.gettempdir() + '/fixtures.unittest.db', testnet=True, **util_test.COUNTERPARTYD_OPTIONS) util_test.restore_database(config.DATABASE, CURR_DIR + '/fixtures/scenarios/unittest_fixture.sql') util.FIRST_MULTISIG_BLOCK_TESTNET = 1 # start RPC server api_server = api.APIServer() api_server.daemon = True api_server.start() for attempt in range(5000): # wait until server is ready. if api_server.is_ready: break elif attempt == 4999: raise Exception("Timeout: RPC server not ready after 5s") else: time.sleep(0.001)
def test_json_rpc(): api_server = api.APIServer() api_server.daemon = True api_server.start() time.sleep(1) url = 'http://localhost:' + str(config.RPC_PORT) + '/jsonrpc/' headers = {'content-type': 'application/json'} auth = HTTPBasicAuth(config.RPC_USER, config.RPC_PASSWORD) payloads = [] payloads.append({ "method": "get_balances", "params": { "filters": { 'field': 'address', 'op': '==', 'value': source_default } }, "jsonrpc": "2.0", "id": 0, }) for payload in payloads: response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth).json() try: output_new['rpc.' + payload['method']] = response['result'] except: output_new['rpc.' + payload['method']] = response['error'] assert response['jsonrpc'] == '2.0' assert response['id'] == 0
elif args.action == 'pending': awaiting_btcs = util.get_order_matches(db, validity='pending', is_mine=True) table = PrettyTable(['Matched Order ID', 'Time Left']) for order_match in awaiting_btcs: order_match = format_order_match(db, order_match) table.add_row(order_match) print(table) # PARSING elif args.action == 'reparse': blocks.reparse(db) elif args.action == 'rollback': blocks.reparse(db, block_index=args.block_index) elif args.action == 'server': api_server = api.APIServer() api_server.daemon = True api_server.start() blocks.follow(db) elif args.action == 'potentials': blocks.get_potentials(db) else: parser.print_help() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4