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
bee93aa3
Commit
bee93aa3
authored
May 31, 2023
by
Will Cory
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Make test use same package
parent
c725718c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
api_test.go
indexer/api/api_test.go
+9
-10
No files found.
indexer/api/api_test.go
View file @
bee93aa3
package
api
_test
package
api
import
(
import
(
"encoding/json"
"encoding/json"
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/ethereum-optimism/optimism/indexer/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
)
)
...
@@ -16,20 +15,20 @@ type MockDB struct {
...
@@ -16,20 +15,20 @@ type MockDB struct {
mock
.
Mock
mock
.
Mock
}
}
func
(
db
*
MockDB
)
GetDeposits
(
limit
int
,
cursor
string
,
sortDirection
string
)
([]
api
.
Deposit
,
string
,
bool
,
error
)
{
func
(
db
*
MockDB
)
GetDeposits
(
limit
int
,
cursor
string
,
sortDirection
string
)
([]
Deposit
,
string
,
bool
,
error
)
{
args
:=
db
.
Called
(
limit
,
cursor
,
sortDirection
)
args
:=
db
.
Called
(
limit
,
cursor
,
sortDirection
)
return
args
.
Get
(
0
)
.
([]
api
.
Deposit
),
args
.
String
(
1
),
args
.
Bool
(
2
),
args
.
Error
(
3
)
return
args
.
Get
(
0
)
.
([]
Deposit
),
args
.
String
(
1
),
args
.
Bool
(
2
),
args
.
Error
(
3
)
}
}
func
(
db
*
MockDB
)
GetWithdrawals
(
limit
int
,
cursor
string
,
sortDirection
string
,
sortBy
string
)
([]
api
.
Withdrawal
,
string
,
bool
,
error
)
{
func
(
db
*
MockDB
)
GetWithdrawals
(
limit
int
,
cursor
string
,
sortDirection
string
,
sortBy
string
)
([]
Withdrawal
,
string
,
bool
,
error
)
{
args
:=
db
.
Called
(
limit
,
cursor
,
sortDirection
,
sortBy
)
args
:=
db
.
Called
(
limit
,
cursor
,
sortDirection
,
sortBy
)
return
args
.
Get
(
0
)
.
([]
api
.
Withdrawal
),
args
.
String
(
1
),
args
.
Bool
(
2
),
args
.
Error
(
3
)
return
args
.
Get
(
0
)
.
([]
Withdrawal
),
args
.
String
(
1
),
args
.
Bool
(
2
),
args
.
Error
(
3
)
}
}
func
TestApi
(
t
*
testing
.
T
)
{
func
TestApi
(
t
*
testing
.
T
)
{
mockDB
:=
new
(
MockDB
)
mockDB
:=
new
(
MockDB
)
mockDeposits
:=
[]
api
.
Deposit
{
mockDeposits
:=
[]
Deposit
{
{
{
Guid
:
"test-guid"
,
Guid
:
"test-guid"
,
Amount
:
"1000"
,
Amount
:
"1000"
,
...
@@ -41,7 +40,7 @@ func TestApi(t *testing.T) {
...
@@ -41,7 +40,7 @@ func TestApi(t *testing.T) {
},
},
}
}
mockWithdrawals
:=
[]
api
.
Withdrawal
{
mockWithdrawals
:=
[]
Withdrawal
{
{
{
Guid
:
"test-guid"
,
Guid
:
"test-guid"
,
Amount
:
"1000"
,
Amount
:
"1000"
,
...
@@ -57,7 +56,7 @@ func TestApi(t *testing.T) {
...
@@ -57,7 +56,7 @@ func TestApi(t *testing.T) {
mockDB
.
On
(
"GetWithdrawals"
,
10
,
""
,
""
,
""
)
.
Return
(
mockWithdrawals
,
"nextCursor"
,
false
,
nil
)
mockDB
.
On
(
"GetWithdrawals"
,
10
,
""
,
""
,
""
)
.
Return
(
mockWithdrawals
,
"nextCursor"
,
false
,
nil
)
testApi
:=
api
.
NewApi
(
mockDB
,
mockDB
)
testApi
:=
NewApi
(
mockDB
,
mockDB
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/v0/deposits"
,
nil
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
"/api/v0/deposits"
,
nil
)
rr
:=
httptest
.
NewRecorder
()
rr
:=
httptest
.
NewRecorder
()
...
@@ -66,7 +65,7 @@ func TestApi(t *testing.T) {
...
@@ -66,7 +65,7 @@ func TestApi(t *testing.T) {
assert
.
Equal
(
t
,
http
.
StatusOK
,
rr
.
Code
,
"status code should be 200"
)
assert
.
Equal
(
t
,
http
.
StatusOK
,
rr
.
Code
,
"status code should be 200"
)
// TODO make this type exist
// TODO make this type exist
var
depositsResponse
api
.
DepositsResponse
var
depositsResponse
DepositsResponse
err
:=
json
.
Unmarshal
(
rr
.
Body
.
Bytes
(),
&
depositsResponse
)
err
:=
json
.
Unmarshal
(
rr
.
Body
.
Bytes
(),
&
depositsResponse
)
assert
.
NoError
(
t
,
err
)
assert
.
NoError
(
t
,
err
)
...
...
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