Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
beem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
beem
Commits
47851889
Commit
47851889
authored
7 years ago
by
Holger Nahrstaedt
Browse files
Options
Downloads
Patches
Plain Diff
Improve coverage for graphenerpc
parent
97e8fcb1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
beemgrapheneapi/graphenerpc.py
+30
-26
30 additions, 26 deletions
beemgrapheneapi/graphenerpc.py
tests/beemapi/test_steemnoderpc.py
+81
-2
81 additions, 2 deletions
tests/beemapi/test_steemnoderpc.py
with
111 additions
and
28 deletions
beemgrapheneapi/graphenerpc.py
+
30
−
26
View file @
47851889
...
@@ -200,6 +200,35 @@ class GrapheneRPC(object):
...
@@ -200,6 +200,35 @@ class GrapheneRPC(object):
reply
=
self
.
ws
.
recv
()
reply
=
self
.
ws
.
recv
()
return
reply
return
reply
def
_check_for_server_error
(
self
,
reply
):
"""
Checks for server error message in reply
"""
if
re
.
search
(
"
Internal Server Error
"
,
reply
)
or
re
.
search
(
"
500
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Internal Server Error
"
)
elif
re
.
search
(
"
Not Implemented
"
,
reply
)
or
re
.
search
(
"
501
"
,
reply
):
raise
RPCError
(
"
Not Implemented
"
)
elif
re
.
search
(
"
Bad Gateway
"
,
reply
)
or
re
.
search
(
"
502
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Bad Gateway
"
)
elif
re
.
search
(
"
Service Temporarily Unavailable
"
,
reply
)
or
re
.
search
(
"
Service Unavailable
"
,
reply
)
or
re
.
search
(
"
503
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Service Temporarily Unavailable
"
)
elif
re
.
search
(
"
Gateway Time-out
"
,
reply
)
or
re
.
search
(
"
Gateway Timeout
"
,
reply
)
or
re
.
search
(
"
504
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Gateway Time-out
"
)
elif
re
.
search
(
"
HTTP Version not supported
"
,
reply
)
or
re
.
search
(
"
505
"
,
reply
):
raise
RPCError
(
"
HTTP Version not supported
"
)
elif
re
.
search
(
"
Variant Also Negotiates
"
,
reply
)
or
re
.
search
(
"
506
"
,
reply
):
raise
RPCError
(
"
Variant Also Negotiates
"
)
elif
re
.
search
(
"
Insufficient Storage
"
,
reply
)
or
re
.
search
(
"
507
"
,
reply
):
raise
RPCError
(
"
Insufficient Storage
"
)
elif
re
.
search
(
"
Loop Detected
"
,
reply
)
or
re
.
search
(
"
508
"
,
reply
):
raise
RPCError
(
"
Loop Detected
"
)
elif
re
.
search
(
"
Bandwidth Limit Exceeded
"
,
reply
)
or
re
.
search
(
"
509
"
,
reply
):
raise
RPCError
(
"
Bandwidth Limit Exceeded
"
)
elif
re
.
search
(
"
Not Extended
"
,
reply
)
or
re
.
search
(
"
510
"
,
reply
):
raise
RPCError
(
"
Not Extended
"
)
elif
re
.
search
(
"
Network Authentication Required
"
,
reply
)
or
re
.
search
(
"
511
"
,
reply
):
raise
RPCError
(
"
Network Authentication Required
"
)
else
:
raise
ValueError
(
"
Client returned invalid format. Expected JSON!
"
)
def
rpcexec
(
self
,
payload
):
def
rpcexec
(
self
,
payload
):
"""
"""
Execute a call by sending the payload.
Execute a call by sending the payload.
...
@@ -232,32 +261,7 @@ class GrapheneRPC(object):
...
@@ -232,32 +261,7 @@ class GrapheneRPC(object):
try
:
try
:
ret
=
json
.
loads
(
reply
,
strict
=
False
)
ret
=
json
.
loads
(
reply
,
strict
=
False
)
except
ValueError
:
except
ValueError
:
if
re
.
search
(
"
Internal Server Error
"
,
reply
)
or
re
.
search
(
"
500
"
,
reply
):
self
.
_check_for_server_error
(
reply
)
raise
RPCErrorDoRetry
(
"
Internal Server Error
"
)
elif
re
.
search
(
"
Not Implemented
"
,
reply
)
or
re
.
search
(
"
501
"
,
reply
):
raise
RPCError
(
"
Not Implemented
"
)
elif
re
.
search
(
"
Bad Gateway
"
,
reply
)
or
re
.
search
(
"
502
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Bad Gateway
"
)
elif
re
.
search
(
"
Service Temporarily Unavailable
"
,
reply
)
or
re
.
search
(
"
Service Unavailable
"
,
reply
)
or
re
.
search
(
"
503
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Service Temporarily Unavailable
"
)
elif
re
.
search
(
"
Gateway Time-out
"
,
reply
)
or
re
.
search
(
"
Gateway Timeout
"
,
reply
)
or
re
.
search
(
"
504
"
,
reply
):
raise
RPCErrorDoRetry
(
"
Gateway Time-out
"
)
elif
re
.
search
(
"
HTTP Version not supported
"
,
reply
)
or
re
.
search
(
"
505
"
,
reply
):
raise
RPCError
(
"
HTTP Version not supported
"
)
elif
re
.
search
(
"
Variant Also Negotiates
"
,
reply
)
or
re
.
search
(
"
506
"
,
reply
):
raise
RPCError
(
"
Variant Also Negotiates
"
)
elif
re
.
search
(
"
Insufficient Storage
"
,
reply
)
or
re
.
search
(
"
507
"
,
reply
):
raise
RPCError
(
"
Insufficient Storage
"
)
elif
re
.
search
(
"
Loop Detected
"
,
reply
)
or
re
.
search
(
"
508
"
,
reply
):
raise
RPCError
(
"
Loop Detected
"
)
elif
re
.
search
(
"
Bandwidth Limit Exceeded
"
,
reply
)
or
re
.
search
(
"
509
"
,
reply
):
raise
RPCError
(
"
Bandwidth Limit Exceeded
"
)
elif
re
.
search
(
"
Not Extended
"
,
reply
)
or
re
.
search
(
"
510
"
,
reply
):
raise
RPCError
(
"
Not Extended
"
)
elif
re
.
search
(
"
Network Authentication Required
"
,
reply
)
or
re
.
search
(
"
511
"
,
reply
):
raise
RPCError
(
"
Network Authentication Required
"
)
else
:
raise
ValueError
(
"
Client returned invalid format. Expected JSON!
"
)
log
.
debug
(
json
.
dumps
(
reply
))
log
.
debug
(
json
.
dumps
(
reply
))
...
...
This diff is collapsed.
Click to expand it.
tests/beemapi/test_steemnoderpc.py
+
81
−
2
View file @
47851889
...
@@ -50,11 +50,17 @@ class Testcases(unittest.TestCase):
...
@@ -50,11 +50,17 @@ class Testcases(unittest.TestCase):
keys
=
{
"
active
"
:
wif
,
"
owner
"
:
wif
,
"
memo
"
:
wif
},
keys
=
{
"
active
"
:
wif
,
"
owner
"
:
wif
,
"
memo
"
:
wif
},
num_retries
=
10
num_retries
=
10
)
)
self
.
rpc
=
SteemNodeRPC
(
urls
=
test_list
)
# from getpass import getpass
# from getpass import getpass
# self.bts.wallet.unlock(getpass())
# self.bts.wallet.unlock(getpass())
set_shared_steem_instance
(
self
.
bts
)
set_shared_steem_instance
(
self
.
bts
)
self
.
bts
.
set_default_account
(
"
test
"
)
self
.
bts
.
set_default_account
(
"
test
"
)
def
get_reply
(
self
,
msg
):
reply
=
'
<html> <head><title>403 Forbidden</title></head><body bgcolor=
"
white
"
><center><h1>
'
\
'
%s</h1></center><hr><center>nginx</center></body> </html>
'
%
(
msg
)
return
reply
def
test_non_appbase
(
self
):
def
test_non_appbase
(
self
):
bts
=
self
.
bts
bts
=
self
.
bts
self
.
assertTrue
(
bts
.
chain_params
[
'
min_version
'
]
==
'
0.0.0
'
)
self
.
assertTrue
(
bts
.
chain_params
[
'
min_version
'
]
==
'
0.0.0
'
)
...
@@ -80,14 +86,87 @@ class Testcases(unittest.TestCase):
...
@@ -80,14 +86,87 @@ class Testcases(unittest.TestCase):
bts
.
rpc
.
get_config_abc
()
bts
.
rpc
.
get_config_abc
()
def
test_connect_test_node
(
self
):
def
test_connect_test_node
(
self
):
rpc
=
SteemNodeRPC
(
urls
=
test_list
)
rpc
=
self
.
rpc
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
rpc
.
rpcclose
()
rpc
.
rpcclose
()
rpc
.
rpcconnect
()
rpc
.
rpcconnect
()
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
def
test_connect_test_node2
(
self
):
def
test_connect_test_node2
(
self
):
rpc
=
SteemNodeRPC
(
urls
=
test_list
)
rpc
=
self
.
rpc
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
rpc
.
next
()
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
def
test_connect_test_str_list
(
self
):
str_list
=
"
wss://steemd.pevo.science;wss://gtg.steem.house:8090;wss://rpc.steemliberator.com;wss://rpc.buildteam.io
"
rpc
=
SteemNodeRPC
(
urls
=
str_list
)
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
rpc
.
next
()
rpc
.
next
()
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
def
test_connect_test_str_list2
(
self
):
str_list
=
"
wss://steemd.pevo.science, wss://gtg.steem.house:8090, wss://rpc.steemliberator.com, wss://rpc.buildteam.io
"
rpc
=
SteemNodeRPC
(
urls
=
str_list
)
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
rpc
.
next
()
self
.
assertIn
(
rpc
.
url
,
nodes
+
nodes_appbase
+
nodes_https
)
def
test_server_error
(
self
):
rpc
=
self
.
rpc
with
self
.
assertRaises
(
exceptions
.
RPCErrorDoRetry
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
500 Internal Server Error
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
501 Not Implemented
"
))
with
self
.
assertRaises
(
exceptions
.
RPCErrorDoRetry
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
502 Bad Gateway
"
))
with
self
.
assertRaises
(
exceptions
.
RPCErrorDoRetry
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
503 Service Temporarily Unavailable
"
))
with
self
.
assertRaises
(
exceptions
.
RPCErrorDoRetry
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
504 Gateway Time-out
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
505 HTTP Version not supported
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
506 Variant Also Negotiates
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
507 Insufficient Storage
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
508 Loop Detected
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
509 Bandwidth Limit Exceeded
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
510 Not Extended
"
))
with
self
.
assertRaises
(
exceptions
.
RPCError
):
rpc
.
_check_for_server_error
(
self
.
get_reply
(
"
511 Network Authentication Required
"
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment