def _call(self, method, params=None, _id=1): params = params or [] data = { 'jsonrpc': '2.0', 'method': method, 'params': params, 'id': _id, } scheme = 'http' if self.tls: scheme += 's' url = '{}://{}:{}'.format(scheme, self.host, self.port) headers = {'Content-Type': JSON_MEDIA_TYPE} try: r = self.session.post(url, headers=headers, data=json.dumps(data)) except RequestsConnectionError: raise ConnectionError if r.status_code / 100 != 2: raise BadStatusCodeError(r.status_code) try: response = r.json() except ValueError: raise BadJsonError(r.text) try: return response['result'] except KeyError: raise BadResponseError(response)
def test_create_contract(): with pytest.raises(BadResponseError) as err: hash = c.create_contract( None, '0x%s' % open('tests/Example.bin', 'r').read(), None) # in case "Intrinsic gas too low" wasn't an issue, check return hash isHash(hash) #request was good, but we still need to throw raise BadResponseError()