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
c02dc701
Unverified
Commit
c02dc701
authored
Nov 14, 2023
by
Ethen Pociask
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[indexer.withdrawal_type_supplies] testing handler svc functions
parent
ba647633
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
27 deletions
+92
-27
models.go
indexer/api/models/models.go
+1
-2
service.go
indexer/api/service/service.go
+7
-7
service_test.go
indexer/api/service/service_test.go
+84
-18
No files found.
indexer/api/models/models.go
View file @
c02dc701
...
...
@@ -4,8 +4,7 @@ import (
"github.com/ethereum/go-ethereum/common"
)
// Params ... Query params
type
Params
struct
{
type
QueryParams
struct
{
Address
common
.
Address
Limit
int
Cursor
string
...
...
indexer/api/service/service.go
View file @
c02dc701
...
...
@@ -9,13 +9,13 @@ import (
)
type
Service
interface
{
GetDeposits
(
*
models
.
Params
)
(
*
database
.
L1BridgeDepositsResponse
,
error
)
GetDeposits
(
*
models
.
Query
Params
)
(
*
database
.
L1BridgeDepositsResponse
,
error
)
DepositResponse
(
*
database
.
L1BridgeDepositsResponse
)
models
.
DepositResponse
GetWithdrawals
(
params
*
models
.
Params
)
(
*
database
.
L2BridgeWithdrawalsResponse
,
error
)
GetWithdrawals
(
params
*
models
.
Query
Params
)
(
*
database
.
L2BridgeWithdrawalsResponse
,
error
)
WithdrawResponse
(
*
database
.
L2BridgeWithdrawalsResponse
)
models
.
WithdrawalResponse
GetSupplyInfo
()
(
*
models
.
BridgeSupplyView
,
error
)
QueryParams
(
a
,
l
,
c
string
)
(
*
models
.
Params
,
error
)
QueryParams
(
a
,
l
,
c
string
)
(
*
models
.
Query
Params
,
error
)
}
type
HandlerSvc
struct
{
...
...
@@ -32,7 +32,7 @@ func New(v *Validator, db database.BridgeTransfersView, l log.Logger) Service {
}
}
func
(
svc
*
HandlerSvc
)
QueryParams
(
a
,
c
,
l
string
)
(
*
models
.
Params
,
error
)
{
func
(
svc
*
HandlerSvc
)
QueryParams
(
a
,
c
,
l
string
)
(
*
models
.
Query
Params
,
error
)
{
address
,
err
:=
svc
.
v
.
ParseValidateAddress
(
a
)
if
err
!=
nil
{
svc
.
logger
.
Error
(
"invalid address param"
,
"param"
,
a
,
"err"
,
err
)
...
...
@@ -51,7 +51,7 @@ func (svc *HandlerSvc) QueryParams(a, c, l string) (*models.Params, error) {
return
nil
,
err
}
return
&
models
.
Params
{
return
&
models
.
Query
Params
{
Address
:
address
,
Cursor
:
c
,
Limit
:
limit
,
...
...
@@ -59,7 +59,7 @@ func (svc *HandlerSvc) QueryParams(a, c, l string) (*models.Params, error) {
}
func
(
svc
*
HandlerSvc
)
GetWithdrawals
(
params
*
models
.
Params
)
(
*
database
.
L2BridgeWithdrawalsResponse
,
error
)
{
func
(
svc
*
HandlerSvc
)
GetWithdrawals
(
params
*
models
.
Query
Params
)
(
*
database
.
L2BridgeWithdrawalsResponse
,
error
)
{
withdrawals
,
err
:=
svc
.
db
.
L2BridgeWithdrawalsByAddress
(
params
.
Address
,
params
.
Cursor
,
params
.
Limit
)
if
err
!=
nil
{
svc
.
logger
.
Error
(
"error getting withdrawals"
,
"err"
,
err
.
Error
(),
"address"
,
params
.
Address
.
String
())
...
...
@@ -103,7 +103,7 @@ func (svc *HandlerSvc) WithdrawResponse(withdrawals *database.L2BridgeWithdrawal
}
}
func
(
svc
*
HandlerSvc
)
GetDeposits
(
params
*
models
.
Params
)
(
*
database
.
L1BridgeDepositsResponse
,
error
)
{
func
(
svc
*
HandlerSvc
)
GetDeposits
(
params
*
models
.
Query
Params
)
(
*
database
.
L1BridgeDepositsResponse
,
error
)
{
deposits
,
err
:=
svc
.
db
.
L1BridgeDepositsByAddress
(
params
.
Address
,
params
.
Cursor
,
params
.
Limit
)
if
err
!=
nil
{
svc
.
logger
.
Error
(
"error getting deposits"
,
"err"
,
err
.
Error
(),
"address"
,
params
.
Address
.
String
())
...
...
indexer/api/service/service_test.go
View file @
c02dc701
...
...
@@ -5,19 +5,36 @@ import (
"reflect"
"testing"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/indexer/api/service"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func
TestCreateWithdrawal
(
t
*
testing
.
T
)
{
func
assertNotEmpty
(
t
*
testing
.
T
,
item
any
)
{
structType
:=
reflect
.
TypeOf
(
item
)
svc
:=
service
.
New
(
nil
,
nil
,
nil
)
// (1) Create a dummy database response object
structVal
:=
reflect
.
ValueOf
(
item
)
fieldNum
:=
structVal
.
NumField
()
for
i
:=
0
;
i
<
fieldNum
;
i
++
{
field
:=
structVal
.
Field
(
i
)
fieldName
:=
structType
.
Field
(
i
)
.
Name
isSet
:=
field
.
IsValid
()
&&
!
field
.
IsZero
()
require
.
True
(
t
,
isSet
,
fmt
.
Sprintf
(
"%s in not set"
,
fieldName
))
}
}
func
TestWithdrawalResponse
(
t
*
testing
.
T
)
{
svc
:=
service
.
New
(
nil
,
nil
,
nil
)
cdh
:=
common
.
HexToHash
(
"0x2"
)
dbWithdrawals
:=
&
database
.
L2BridgeWithdrawalsResponse
{
withdraws
:=
&
database
.
L2BridgeWithdrawalsResponse
{
Withdrawals
:
[]
database
.
L2BridgeWithdrawalWithTransactionHashes
{
{
L2BridgeWithdrawal
:
database
.
L2BridgeWithdrawal
{
...
...
@@ -39,28 +56,77 @@ func TestCreateWithdrawal(t *testing.T) {
},
}
// (2) Create and validate response object
response
:=
svc
.
WithdrawResponse
(
dbWithdrawals
)
response
:=
svc
.
WithdrawResponse
(
withdraws
)
require
.
NotEmpty
(
t
,
response
.
Items
)
require
.
Len
(
t
,
response
.
Items
,
1
)
assertNotEmpty
(
t
,
response
.
Items
[
0
])
}
// (3) Use reflection to check that all fields in WithdrawalItem are populated correctly
func
TestDepositResponse
(
t
*
testing
.
T
)
{
cdh
:=
common
.
HexToHash
(
"0x2"
)
svc
:=
service
.
New
(
nil
,
nil
,
nil
)
item
:=
response
.
Items
[
0
]
structType
:=
reflect
.
TypeOf
(
item
)
deposits
:=
&
database
.
L1BridgeDepositsResponse
{
Deposits
:
[]
database
.
L1BridgeDepositWithTransactionHashes
{
{
L1BridgeDeposit
:
database
.
L1BridgeDeposit
{
BridgeTransfer
:
database
.
BridgeTransfer
{
CrossDomainMessageHash
:
&
cdh
,
Tx
:
database
.
Transaction
{
FromAddress
:
common
.
HexToAddress
(
"0x3"
),
ToAddress
:
common
.
HexToAddress
(
"0x4"
),
Timestamp
:
5
,
},
TokenPair
:
database
.
TokenPair
{
LocalTokenAddress
:
common
.
HexToAddress
(
"0x6"
),
RemoteTokenAddress
:
common
.
HexToAddress
(
"0x7"
),
},
},
},
},
},
}
structVal
:=
reflect
.
ValueOf
(
item
)
fieldNum
:=
structVal
.
NumField
()
response
:=
svc
.
DepositResponse
(
deposits
)
require
.
NotEmpty
(
t
,
response
.
Items
)
require
.
Len
(
t
,
response
.
Items
,
1
)
assertNotEmpty
(
t
,
response
.
Items
[
0
])
}
for
i
:=
0
;
i
<
fieldNum
;
i
++
{
field
:=
structVal
.
Field
(
i
)
fieldName
:=
structType
.
Field
(
i
)
.
Name
func
TestQueryParams
(
t
*
testing
.
T
)
{
isSet
:=
field
.
IsValid
()
&&
!
field
.
IsZero
()
var
tests
=
[]
struct
{
name
string
test
func
(
*
testing
.
T
,
service
.
Service
)
}{
{
name
:
"empty params"
,
test
:
func
(
t
*
testing
.
T
,
svc
service
.
Service
)
{
params
,
err
:=
svc
.
QueryParams
(
""
,
""
,
""
)
require
.
Error
(
t
,
err
)
require
.
Nil
(
t
,
params
)
},
},
{
name
:
"empty params except address"
,
test
:
func
(
t
*
testing
.
T
,
svc
service
.
Service
)
{
addr
:=
common
.
HexToAddress
(
"0x420"
)
params
,
err
:=
svc
.
QueryParams
(
addr
.
String
(),
""
,
""
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
params
)
require
.
Equal
(
t
,
addr
,
params
.
Address
)
require
.
Equal
(
t
,
100
,
params
.
Limit
)
require
.
Equal
(
t
,
""
,
params
.
Cursor
)
},
},
}
require
.
True
(
t
,
isSet
,
fmt
.
Sprintf
(
"%s in not set"
,
fieldName
))
v
:=
new
(
service
.
Validator
)
svc
:=
service
.
New
(
v
,
nil
,
log
.
New
())
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
tt
.
test
(
t
,
svc
)
})
}
}
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