Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
1760613c
Commit
1760613c
authored
Jan 19, 2022
by
Matthew Slipper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code review updates
- Fixes ENG-1903
parent
594893df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
13 deletions
+21
-13
wicked-foxes-cry.md
.changeset/wicked-foxes-cry.md
+5
-0
failover_test.go
go/proxyd/integration_tests/failover_test.go
+8
-7
validation_test.go
go/proxyd/integration_tests/validation_test.go
+6
-6
server.go
go/proxyd/server.go
+2
-0
No files found.
.changeset/wicked-foxes-cry.md
0 → 100644
View file @
1760613c
---
'
@eth-optimism/proxyd'
:
minor
---
Add integration tests and batching
go/proxyd/integration_tests/failover_test.go
View file @
1760613c
...
...
@@ -11,8 +11,10 @@ import (
"time"
)
const
goodResponse
=
"{
\"
jsonrpc
\"
:
\"
2.0
\"
,
\"
result
\"
:
\"
hello
\"
,
\"
id
\"
: 999}"
const
noBackendsResponse
=
"{
\"
error
\"
:{
\"
code
\"
:-32011,
\"
message
\"
:
\"
no backends available for method
\"
},
\"
id
\"
:999,
\"
jsonrpc
\"
:
\"
2.0
\"
}"
const
(
goodResponse
=
`{"jsonrpc": "2.0", "result": "hello", "id": 999}`
noBackendsResponse
=
`{"error":{"code":-32011,"message":"no backends available for method"},"id":999,"jsonrpc":"2.0"}`
)
func
TestFailover
(
t
*
testing
.
T
)
{
goodBackend
:=
NewMockBackend
(
SingleResponseHandler
(
200
,
goodResponse
))
...
...
@@ -82,7 +84,7 @@ func TestFailover(t *testing.T) {
})
}
t
.
Run
(
"backend times out"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"backend times out
and falls back to another
"
,
func
(
t
*
testing
.
T
)
{
badBackend
.
SetHandler
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
time
.
Sleep
(
2
*
time
.
Second
)
w
.
Write
([]
byte
(
"{}"
))
...
...
@@ -93,12 +95,11 @@ func TestFailover(t *testing.T) {
RequireEqualJSON
(
t
,
[]
byte
(
goodResponse
),
res
)
require
.
Equal
(
t
,
1
,
len
(
badBackend
.
Requests
()))
require
.
Equal
(
t
,
1
,
len
(
goodBackend
.
Requests
()))
})
t
.
Run
(
"works with a batch request"
,
func
(
t
*
testing
.
T
)
{
goodBackend
.
Reset
()
badBackend
.
Reset
()
})
t
.
Run
(
"works with a batch request"
,
func
(
t
*
testing
.
T
)
{
badBackend
.
SetHandler
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
500
)
}))
...
...
@@ -155,7 +156,7 @@ func TestRetries(t *testing.T) {
func
TestOutOfServiceInterval
(
t
*
testing
.
T
)
{
goodBackend
:=
NewMockBackend
(
SingleResponseHandler
(
200
,
goodResponse
))
defer
goodBackend
.
Close
()
badBackend
:=
NewMockBackend
(
SingleResponseHandler
(
200
,
goodResponse
)
)
badBackend
:=
NewMockBackend
(
nil
)
defer
badBackend
.
Close
()
require
.
NoError
(
t
,
os
.
Setenv
(
"GOOD_BACKEND_RPC_URL"
,
goodBackend
.
URL
()))
...
...
go/proxyd/integration_tests/validation_test.go
View file @
1760613c
...
...
@@ -9,12 +9,12 @@ import (
)
const
(
notWhitelistedResponse
=
"{
\"
jsonrpc
\"
:
\"
2.0
\"
,
\"
error
\"
:{
\"
code
\"
:-32001,
\"
message
\"
:
\"
rpc method is not whitelisted
\"
},
\"
id
\"
:999}"
parseErrResponse
=
"{
\"
jsonrpc
\"
:
\"
2.0
\"
,
\"
error
\"
:{
\"
code
\"
:-32700,
\"
message
\"
:
\"
parse error
\"
},
\"
id
\"
:null}"
invalidJSONRPCVersionResponse
=
"{
\"
error
\"
:{
\"
code
\"
:-32601,
\"
message
\"
:
\"
invalid JSON-RPC version
\"
},
\"
id
\"
:null,
\"
jsonrpc
\"
:
\"
2.0
\"
}"
invalidIDResponse
=
"{
\"
error
\"
:{
\"
code
\"
:-32601,
\"
message
\"
:
\"
invalid ID
\"
},
\"
id
\"
:null,
\"
jsonrpc
\"
:
\"
2.0
\"
}"
invalidMethodResponse
=
"{
\"
error
\"
:{
\"
code
\"
:-32601,
\"
message
\"
:
\"
no method specified
\"
},
\"
id
\"
:null,
\"
jsonrpc
\"
:
\"
2.0
\"
}"
invalidBatchLenResponse
=
"{
\"
error
\"
:{
\"
code
\"
:-32601,
\"
message
\"
:
\"
must specify at least one batch call
\"
},
\"
id
\"
:null,
\"
jsonrpc
\"
:
\"
2.0
\"
}"
notWhitelistedResponse
=
`{"jsonrpc":"2.0","error":{"code":-32001,"message":"rpc method is not whitelisted"},"id":999}`
parseErrResponse
=
`{"jsonrpc":"2.0","error":{"code":-32700,"message":"parse error"},"id":null}`
invalidJSONRPCVersionResponse
=
`{"error":{"code":-32601,"message":"invalid JSON-RPC version"},"id":null,"jsonrpc":"2.0"}`
invalidIDResponse
=
`{"error":{"code":-32601,"message":"invalid ID"},"id":null,"jsonrpc":"2.0"}`
invalidMethodResponse
=
`{"error":{"code":-32601,"message":"no method specified"},"id":null,"jsonrpc":"2.0"}`
invalidBatchLenResponse
=
`{"error":{"code":-32601,"message":"must specify at least one batch call"},"id":null,"jsonrpc":"2.0"}`
)
func
TestSingleRPCValidation
(
t
*
testing
.
T
)
{
...
...
go/proxyd/server.go
View file @
1760613c
...
...
@@ -338,6 +338,7 @@ func writeRPCRes(ctx context.Context, w http.ResponseWriter, res *RPCRes) {
statusCode
=
res
.
Error
.
HTTPErrorCode
}
w
.
Header
()
.
Set
(
"content-type"
,
"application/json"
)
w
.
WriteHeader
(
statusCode
)
ww
:=
&
recordLenWriter
{
Writer
:
w
}
enc
:=
json
.
NewEncoder
(
ww
)
...
...
@@ -351,6 +352,7 @@ func writeRPCRes(ctx context.Context, w http.ResponseWriter, res *RPCRes) {
}
func
writeBatchRPCRes
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
res
[]
*
RPCRes
)
{
w
.
Header
()
.
Set
(
"content-type"
,
"application/json"
)
w
.
WriteHeader
(
200
)
ww
:=
&
recordLenWriter
{
Writer
:
w
}
enc
:=
json
.
NewEncoder
(
ww
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment