Commit fdaa22a0 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.client] Fixed E2E tests, added metrics and timeout to client

parent 9b87075c
......@@ -423,13 +423,13 @@ func TestE2EBridgeTransfersCursoredWithdrawals(t *testing.T) {
require.False(t, aliceWithdrawals.HasNextPage)
// Respects Limits & Supplied Cursors
aliceWithdrawals, err = testSuite.DB.BridgeTransfers.L2BridgeWithdrawalsByAddress(aliceAddr, "", 100)
aliceWithdrawals, err = testSuite.DB.BridgeTransfers.L2BridgeWithdrawalsByAddress(aliceAddr, "", 2)
require.NotNil(t, aliceWithdrawals)
require.NoError(t, err)
require.Len(t, aliceWithdrawals.Withdrawals, 2)
require.True(t, aliceWithdrawals.HasNextPage)
aliceWithdrawals, err = testSuite.DB.BridgeTransfers.L2BridgeWithdrawalsByAddress(aliceAddr, aliceWithdrawals.Cursor, 100)
aliceWithdrawals, err = testSuite.DB.BridgeTransfers.L2BridgeWithdrawalsByAddress(aliceAddr, aliceWithdrawals.Cursor, 1)
require.NotNil(t, aliceWithdrawals)
require.NoError(t, err)
require.Len(t, aliceWithdrawals.Withdrawals, 1)
......@@ -464,7 +464,9 @@ func Test_ClientGetWithdrawals(t *testing.T) {
type actor struct {
addr common.Address
priv *ecdsa.PrivateKey
hash common.Hash
depositHash common.Hash
withdrawalHash common.Hash
}
actors := []actor{
......@@ -478,13 +480,13 @@ func Test_ClientGetWithdrawals(t *testing.T) {
},
}
// Iterate over each actor and deposit / withdraw
// (1) Iterate over each actor and deposit / withdraw
for _, actor := range actors {
l2Opts, err := bind.NewKeyedTransactorWithChainID(actor.priv, testSuite.OpCfg.L2ChainIDBig())
require.NoError(t, err)
l2Opts.Value = big.NewInt(params.Ether)
// (1) Deposit user funds into L2 via OptimismPortal contract
// (1.a) Deposit user funds into L2 via OptimismPortal contract
l1Opts, err := bind.NewKeyedTransactorWithChainID(actor.priv, testSuite.OpCfg.L1ChainIDBig())
require.NoError(t, err)
l1Opts.Value = l2Opts.Value
......@@ -493,30 +495,41 @@ func Test_ClientGetWithdrawals(t *testing.T) {
_, err = wait.ForReceiptOK(context.Background(), testSuite.L1Client, depositTx.Hash())
require.NoError(t, err)
// (2) Initiate withdrawal transaction via L2ToL1MessagePasser contract
// (1.b) Initiate withdrawal transaction via L2ToL1MessagePasser contract
l2ToL1MessagePasserWithdrawTx, err := l2ToL1MessagePasser.Receive(l2Opts)
require.NoError(t, err)
l2ToL1WithdrawReceipt, err := wait.ForReceiptOK(context.Background(), testSuite.L2Client, l2ToL1MessagePasserWithdrawTx.Hash())
require.NoError(t, err)
// wait for processor catchup
// (1.c) wait for indexer processor to catchup with the L2 block containing the withdrawal tx
require.NoError(t, wait.For(context.Background(), 500*time.Millisecond, func() (bool, error) {
l2Header := testSuite.Indexer.BridgeProcessor.LatestL2Header
return l2Header != nil && l2Header.Number.Uint64() >= l2ToL1WithdrawReceipt.BlockNumber.Uint64(), nil
}))
actor.hash = l2ToL1MessagePasserWithdrawTx.Hash()
actor.withdrawalHash = l2ToL1MessagePasserWithdrawTx.Hash()
}
// (2) Test that Alice's tx can be retrieved via API client
// (2) Test that Alice's withdrawal and deposit txs can be retrieved via API client
aliceWithdrawals, err := testSuite.Client.GetAllWithdrawalsByAddress(aliceAddr)
require.NoError(t, err)
require.Len(t, aliceWithdrawals, 1)
require.Equal(t, actors[0], aliceWithdrawals[0].L2TransactionHash[0])
require.Equal(t, actors[0].withdrawalHash, aliceWithdrawals[0].L2TransactionHash[0])
aliceDeposits, err := testSuite.Client.GetAllDepositsByAddress(aliceAddr)
require.NoError(t, err)
require.Len(t, aliceDeposits, 1)
require.Equal(t, actors[0].depositHash, aliceDeposits[0].L1TransactionHash[0])
// (3) Test that Bob's tx can be retrieved via API client
// (3) Test that Bob's withdrawal and deposit txs can be retrieved via API client
bobWithdrawals, err := testSuite.Client.GetAllWithdrawalsByAddress(bobAddr)
require.NoError(t, err)
require.Len(t, bobWithdrawals, 1)
require.Equal(t, actors[1], bobWithdrawals[0].L2TransactionHash[0])
require.Equal(t, actors[1].withdrawalHash, bobWithdrawals[0].L2TransactionHash[0])
bobDeposits, err := testSuite.Client.GetAllDepositsByAddress(bobAddr)
require.NoError(t, err)
require.Equal(t, actors[0].depositHash, aliceDeposits[0].L1TransactionHash[0])
require.Equal(t, actors[1].depositHash, bobDeposits[0].L2TransactionHash[0])
}
......@@ -8,9 +8,8 @@ import (
"testing"
"time"
"github.com/ethereum-optimism/optimism/indexer/api"
"github.com/ethereum-optimism/optimism/indexer"
"github.com/ethereum-optimism/optimism/indexer/api"
"github.com/ethereum-optimism/optimism/indexer/client"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/database"
......@@ -27,14 +26,14 @@ import (
type E2ETestSuite struct {
t *testing.T
// API
Client *client.Client
API *api.API
// Indexer
DB *database.DB
Indexer *indexer.Indexer
// API
API *api.Api
Client *client.Client
// Rollup
OpCfg *op_e2e.SystemConfig
OpSys *op_e2e.System
......@@ -89,8 +88,8 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
L1ERC721BridgeProxy: opCfg.L1Deployments.L1ERC721BridgeProxy,
},
},
HTTPServer: config.ServerConfig{Host: "http://localhost", Port: 8777},
MetricsServer: config.ServerConfig{Host: "127.0.0.1", Port: 0},
HTTPServer: config.ServerConfig{Host: "127.0.0.1", Port: 8080},
MetricsServer: config.ServerConfig{Host: "127.0.0.1", Port: 7081},
}
db, err := database.NewDB(indexerCfg.DB)
......@@ -102,36 +101,52 @@ func createE2ETestSuite(t *testing.T) E2ETestSuite {
require.NoError(t, err)
indexerCtx, indexerStop := context.WithCancel(context.Background())
go func() {
err := indexer.Run(indexerCtx)
require.NoError(t, err)
if err != nil { // panicking here ensures that the test will exit
// during service failure. Using t.Fail() wouldn't be caught
// until all awaiting routines finish which would never happen.
panic(err)
}
}()
api := api.NewApi(indexerLog, db.BridgeTransfers, indexerCfg.HTTPServer, indexerCfg.MetricsServer)
apiLog := testlog.Logger(t, log.LvlInfo).New("role", "indexer_api")
apiCfg := config.ServerConfig{
Host: "127.0.0.1",
Port: 6669,
}
mCfg := config.ServerConfig{
Host: "127.0.0.1",
Port: 0,
}
api := api.NewApi(apiLog, db.BridgeTransfers, apiCfg, mCfg)
apiCtx, apiStop := context.WithCancel(context.Background())
go func() {
err := api.Start(indexerCtx)
require.NoError(t, err)
err := api.Start(apiCtx)
if err != nil {
panic(err)
}
}()
t.Cleanup(func() {
apiStop()
indexerStop()
})
cfg := &client.Config{
client, err := client.NewClient(&client.Config{
PaginationLimit: 100,
URL: fmt.Sprintf("%s:%d", indexerCfg.HTTPServer.Host, indexerCfg.HTTPServer.Port),
}
client, err := client.NewClient(cfg, nil)
URL: fmt.Sprintf("http://%s:%d", indexerCfg.HTTPServer.Host, indexerCfg.HTTPServer.Port),
})
require.NoError(t, err)
return E2ETestSuite{
t: t,
DB: db,
API: api,
Client: client,
DB: db,
Indexer: indexer,
OpCfg: &opCfg,
OpSys: opSys,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment