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
5d4a5bb9
Unverified
Commit
5d4a5bb9
authored
Aug 14, 2023
by
Ethen Pociask
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[indexer.client] Added client to indexer tests
parent
a97ed3bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
7 deletions
+24
-7
client.go
indexer/api/client.go
+6
-7
bridge_transfers_e2e_test.go
indexer/e2e_tests/bridge_transfers_e2e_test.go
+6
-0
setup.go
indexer/e2e_tests/setup.go
+12
-0
No files found.
indexer/api/client.go
View file @
5d4a5bb9
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"net/http"
"net/http"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/db"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
)
)
...
@@ -30,8 +29,8 @@ func (ec *Client) Close() {
...
@@ -30,8 +29,8 @@ func (ec *Client) Close() {
}
}
// GetDepositsByAddress returns all associated (L1->L2) deposits for a provided L1 address.
// GetDepositsByAddress returns all associated (L1->L2) deposits for a provided L1 address.
func
(
ic
*
Client
)
GetDepositsByAddress
(
addr
common
.
Address
)
([]
*
database
.
DepositWithTransactionHash
,
error
)
{
func
(
ic
*
Client
)
GetDepositsByAddress
(
addr
common
.
Address
)
([]
*
database
.
L1BridgeDepositWithTransactionHashes
,
error
)
{
var
deposits
[]
*
database
.
DepositWithTransactionHash
var
deposits
[]
*
database
.
L1BridgeDepositWithTransactionHashes
resp
,
err
:=
ic
.
c
.
Get
(
ic
.
url
+
depositPath
+
addr
.
Hex
())
resp
,
err
:=
ic
.
c
.
Get
(
ic
.
url
+
depositPath
+
addr
.
Hex
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -51,8 +50,8 @@ func (ic *Client) GetDepositsByAddress(addr common.Address) ([]*database.Deposit
...
@@ -51,8 +50,8 @@ func (ic *Client) GetDepositsByAddress(addr common.Address) ([]*database.Deposit
}
}
// GetWithdrawalsByAddress returns all associated (L2->L1) withdrawals for a provided L2 address.
// GetWithdrawalsByAddress returns all associated (L2->L1) withdrawals for a provided L2 address.
func
(
ic
*
Client
)
GetWithdrawalsByAddress
(
addr
common
.
Address
)
(
*
db
.
PaginatedWithdrawal
s
,
error
)
{
func
(
ic
*
Client
)
GetWithdrawalsByAddress
(
addr
common
.
Address
)
(
[]
*
database
.
L2BridgeWithdrawalWithTransactionHashe
s
,
error
)
{
var
deposits
*
db
.
PaginatedWithdrawal
s
var
withdrawals
[]
*
database
.
L2BridgeWithdrawalWithTransactionHashe
s
resp
,
err
:=
ic
.
c
.
Get
(
ic
.
url
+
depositPath
+
addr
.
Hex
())
resp
,
err
:=
ic
.
c
.
Get
(
ic
.
url
+
depositPath
+
addr
.
Hex
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -64,9 +63,9 @@ func (ic *Client) GetWithdrawalsByAddress(addr common.Address) (*db.PaginatedWit
...
@@ -64,9 +63,9 @@ func (ic *Client) GetWithdrawalsByAddress(addr common.Address) (*db.PaginatedWit
return
nil
,
fmt
.
Errorf
(
"unexpected status code: %d"
,
resp
.
StatusCode
)
return
nil
,
fmt
.
Errorf
(
"unexpected status code: %d"
,
resp
.
StatusCode
)
}
}
if
err
:=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
deposit
s
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
withdrawal
s
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
deposit
s
,
nil
return
withdrawal
s
,
nil
}
}
indexer/e2e_tests/bridge_transfers_e2e_test.go
View file @
5d4a5bb9
...
@@ -280,4 +280,10 @@ func TestE2EBridgeTransfersL2ToL1MessagePasserReceive(t *testing.T) {
...
@@ -280,4 +280,10 @@ func TestE2EBridgeTransfersL2ToL1MessagePasserReceive(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
proveReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Equal
(
t
,
proveReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Equal
(
t
,
finalizeReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
require
.
Equal
(
t
,
finalizeReceipt
.
TxHash
,
aliceWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
// (3) Test API query for L2ToL1MessagePasser withdrawals
respWithdrawals
,
err
:=
testSuite
.
Client
.
GetWithdrawalsByAddress
(
aliceAddr
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
proveReceipt
.
TxHash
,
respWithdrawals
[
0
]
.
ProvenL1TransactionHash
)
require
.
Equal
(
t
,
finalizeReceipt
.
TxHash
,
respWithdrawals
[
0
]
.
FinalizedL1TransactionHash
)
}
}
indexer/e2e_tests/setup.go
View file @
5d4a5bb9
...
@@ -5,12 +5,14 @@ import (
...
@@ -5,12 +5,14 @@ import (
"database/sql"
"database/sql"
"fmt"
"fmt"
"io/fs"
"io/fs"
"net/http"
"os"
"os"
"path/filepath"
"path/filepath"
"testing"
"testing"
"time"
"time"
"github.com/ethereum-optimism/optimism/indexer"
"github.com/ethereum-optimism/optimism/indexer"
"github.com/ethereum-optimism/optimism/indexer/api"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/database"
"github.com/ethereum-optimism/optimism/indexer/processor"
"github.com/ethereum-optimism/optimism/indexer/processor"
...
@@ -28,6 +30,7 @@ type E2ETestSuite struct {
...
@@ -28,6 +30,7 @@ type E2ETestSuite struct {
t
*
testing
.
T
t
*
testing
.
T
// Indexer
// Indexer
Client
*
api
.
Client
DB
*
database
.
DB
DB
*
database
.
DB
Indexer
*
indexer
.
Indexer
Indexer
*
indexer
.
Indexer
...
@@ -79,6 +82,10 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
...
@@ -79,6 +82,10 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
L1ERC721Bridge
:
opCfg
.
L1Deployments
.
L1ERC721BridgeProxy
,
L1ERC721Bridge
:
opCfg
.
L1Deployments
.
L1ERC721BridgeProxy
,
},
},
},
},
API
:
config
.
APIConfig
{
Host
:
"127.0.0.1"
,
Port
:
5345
,
},
}
}
db
,
err
:=
database
.
NewDB
(
fmt
.
Sprintf
(
"postgres://%s@localhost:5432/%s?sslmode=disable"
,
dbUser
,
dbName
))
db
,
err
:=
database
.
NewDB
(
fmt
.
Sprintf
(
"postgres://%s@localhost:5432/%s?sslmode=disable"
,
dbUser
,
dbName
))
...
@@ -86,6 +93,10 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
...
@@ -86,6 +93,10 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
indexer
,
err
:=
indexer
.
NewIndexer
(
indexerCfg
)
indexer
,
err
:=
indexer
.
NewIndexer
(
indexerCfg
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
client
:=
api
.
NewClient
(
&
http
.
Client
{},
fmt
.
Sprintf
(
"http://%s:%d"
,
indexerCfg
.
API
.
Host
,
indexerCfg
.
API
.
Port
))
indexerStoppedCh
:=
make
(
chan
interface
{},
1
)
indexerStoppedCh
:=
make
(
chan
interface
{},
1
)
indexerCtx
,
indexerStop
:=
context
.
WithCancel
(
context
.
Background
())
indexerCtx
,
indexerStop
:=
context
.
WithCancel
(
context
.
Background
())
go
func
()
{
go
func
()
{
...
@@ -106,6 +117,7 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
...
@@ -106,6 +117,7 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
return
E2ETestSuite
{
return
E2ETestSuite
{
t
:
t
,
t
:
t
,
DB
:
db
,
DB
:
db
,
Client
:
client
,
Indexer
:
indexer
,
Indexer
:
indexer
,
OpCfg
:
&
opCfg
,
OpCfg
:
&
opCfg
,
OpSys
:
opSys
,
OpSys
:
opSys
,
...
...
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