Commit 1f618bb7 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2346 from mslipper/feat/circleci-2

ci: Add CircleCI config
parents edbf338e 8d5ebf21
This diff is collapsed.
This diff is collapsed.
...@@ -2,12 +2,13 @@ package metrics ...@@ -2,12 +2,13 @@ package metrics
import ( import (
"fmt" "fmt"
"net/http"
l2common "github.com/ethereum-optimism/optimism/l2geth/common" l2common "github.com/ethereum-optimism/optimism/l2geth/common"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
) )
const metricsNamespace = "indexer" const metricsNamespace = "indexer"
......
...@@ -2,6 +2,7 @@ package bridge ...@@ -2,6 +2,7 @@ package bridge
import ( import (
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/go/indexer/bindings/address_manager" "github.com/ethereum-optimism/optimism/go/indexer/bindings/address_manager"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
......
...@@ -2,6 +2,7 @@ package bridge ...@@ -2,6 +2,7 @@ package bridge
import ( import (
"context" "context"
"github.com/ethereum-optimism/optimism/go/indexer/bindings/l1bridge" "github.com/ethereum-optimism/optimism/go/indexer/bindings/l1bridge"
"github.com/ethereum-optimism/optimism/go/indexer/db" "github.com/ethereum-optimism/optimism/go/indexer/db"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
......
...@@ -2,6 +2,7 @@ package l1 ...@@ -2,6 +2,7 @@ package l1
import ( import (
"context" "context"
"github.com/ethereum-optimism/optimism/go/indexer/bindings/l1erc20" "github.com/ethereum-optimism/optimism/go/indexer/bindings/l1erc20"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
...@@ -40,7 +41,6 @@ func QueryERC20(address common.Address, client *ethclient.Client) (*db.Token, er ...@@ -40,7 +41,6 @@ func QueryERC20(address common.Address, client *ethclient.Client) (*db.Token, er
}, nil }, nil
} }
func QueryStateBatches(filterer *scc.StateCommitmentChainFilterer, startHeight, endHeight uint64, ctx context.Context) (map[common.Hash][]db.StateBatch, error) { func QueryStateBatches(filterer *scc.StateCommitmentChainFilterer, startHeight, endHeight uint64, ctx context.Context) (map[common.Hash][]db.StateBatch, error) {
batches := make(map[common.Hash][]db.StateBatch) batches := make(map[common.Hash][]db.StateBatch)
......
...@@ -255,7 +255,7 @@ func (b *Backend) ProxyWS(clientConn *websocket.Conn, methodWhitelist *StringSet ...@@ -255,7 +255,7 @@ func (b *Backend) ProxyWS(clientConn *websocket.Conn, methodWhitelist *StringSet
return nil, ErrBackendOverCapacity return nil, ErrBackendOverCapacity
} }
backendConn, _, err := b.dialer.Dial(b.wsURL, nil) backendConn, _, err := b.dialer.Dial(b.wsURL, nil) // nolint:bodyclose
if err != nil { if err != nil {
b.setOffline() b.setOffline()
if err := b.rateLimiter.DecBackendWSConns(b.Name); err != nil { if err := b.rateLimiter.DecBackendWSConns(b.Name); err != nil {
...@@ -513,7 +513,9 @@ func (w *WSProxier) clientPump(ctx context.Context, errC chan error) { ...@@ -513,7 +513,9 @@ func (w *WSProxier) clientPump(ctx context.Context, errC chan error) {
msgType, msg, err := w.clientConn.ReadMessage() msgType, msg, err := w.clientConn.ReadMessage()
if err != nil { if err != nil {
errC <- err errC <- err
outConn.WriteMessage(websocket.CloseMessage, formatWSError(err)) if err := outConn.WriteMessage(websocket.CloseMessage, formatWSError(err)); err != nil {
log.Error("error writing backendConn message", "err", err)
}
return return
} }
...@@ -575,7 +577,9 @@ func (w *WSProxier) backendPump(ctx context.Context, errC chan error) { ...@@ -575,7 +577,9 @@ func (w *WSProxier) backendPump(ctx context.Context, errC chan error) {
msgType, msg, err := w.backendConn.ReadMessage() msgType, msg, err := w.backendConn.ReadMessage()
if err != nil { if err != nil {
errC <- err errC <- err
w.clientConn.WriteMessage(websocket.CloseMessage, formatWSError(err)) if err := w.clientConn.WriteMessage(websocket.CloseMessage, formatWSError(err)); err != nil {
log.Error("error writing clientConn message", "err", err)
}
return return
} }
......
...@@ -3,12 +3,13 @@ package integration_tests ...@@ -3,12 +3,13 @@ package integration_tests
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/alicebob/miniredis"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/alicebob/miniredis"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
) )
func TestCaching(t *testing.T) { func TestCaching(t *testing.T) {
......
...@@ -2,13 +2,14 @@ package integration_tests ...@@ -2,13 +2,14 @@ package integration_tests
import ( import (
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
"net/http" "net/http"
"os" "os"
"sync/atomic" "sync/atomic"
"testing" "testing"
"time" "time"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
) )
const ( const (
...@@ -39,7 +40,7 @@ func TestFailover(t *testing.T) { ...@@ -39,7 +40,7 @@ func TestFailover(t *testing.T) {
"backend responds 200 with non-JSON response", "backend responds 200 with non-JSON response",
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200) w.WriteHeader(200)
w.Write([]byte("this data is not JSON!")) _, _ = w.Write([]byte("this data is not JSON!"))
}), }),
}, },
{ {
...@@ -87,7 +88,7 @@ func TestFailover(t *testing.T) { ...@@ -87,7 +88,7 @@ func TestFailover(t *testing.T) {
t.Run("backend times out and falls back to another", 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) { badBackend.SetHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
w.Write([]byte("{}")) _, _ = w.Write([]byte("{}"))
})) }))
res, statusCode, err := client.SendRPC("eth_chainId", nil) res, statusCode, err := client.SendRPC("eth_chainId", nil)
require.NoError(t, err) require.NoError(t, err)
...@@ -133,7 +134,7 @@ func TestRetries(t *testing.T) { ...@@ -133,7 +134,7 @@ func TestRetries(t *testing.T) {
w.WriteHeader(500) w.WriteHeader(500)
return return
} }
w.Write([]byte(goodResponse)) _, _ = w.Write([]byte(goodResponse))
})) }))
// test case where request eventually succeeds // test case where request eventually succeeds
...@@ -169,7 +170,7 @@ func TestOutOfServiceInterval(t *testing.T) { ...@@ -169,7 +170,7 @@ func TestOutOfServiceInterval(t *testing.T) {
defer shutdown() defer shutdown()
okHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { okHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(goodResponse)) _, _ = w.Write([]byte(goodResponse))
}) })
badBackend.SetHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { badBackend.SetHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(503) w.WriteHeader(503)
...@@ -190,10 +191,12 @@ func TestOutOfServiceInterval(t *testing.T) { ...@@ -190,10 +191,12 @@ func TestOutOfServiceInterval(t *testing.T) {
require.Equal(t, 2, len(badBackend.Requests())) require.Equal(t, 2, len(badBackend.Requests()))
require.Equal(t, 2, len(goodBackend.Requests())) require.Equal(t, 2, len(goodBackend.Requests()))
res, statusCode, err = client.SendBatchRPC( _, statusCode, err = client.SendBatchRPC(
NewRPCReq("1", "eth_chainId", nil), NewRPCReq("1", "eth_chainId", nil),
NewRPCReq("1", "eth_chainId", nil), NewRPCReq("1", "eth_chainId", nil),
) )
require.NoError(t, err)
require.Equal(t, 200, statusCode)
require.Equal(t, 2, len(badBackend.Requests())) require.Equal(t, 2, len(badBackend.Requests()))
require.Equal(t, 4, len(goodBackend.Requests())) require.Equal(t, 4, len(goodBackend.Requests()))
......
...@@ -4,11 +4,12 @@ import ( ...@@ -4,11 +4,12 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"github.com/ethereum-optimism/optimism/go/proxyd"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"sync" "sync"
"github.com/ethereum-optimism/optimism/go/proxyd"
) )
type RecordedRequest struct { type RecordedRequest struct {
...@@ -27,7 +28,7 @@ type MockBackend struct { ...@@ -27,7 +28,7 @@ type MockBackend struct {
func SingleResponseHandler(code int, response string) http.HandlerFunc { func SingleResponseHandler(code int, response string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(code) w.WriteHeader(code)
w.Write([]byte(response)) _, _ = w.Write([]byte(response))
} }
} }
......
package integration_tests package integration_tests
import ( import (
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
"os" "os"
"testing" "testing"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
) )
type resWithCode struct { type resWithCode struct {
......
...@@ -4,12 +4,13 @@ import ( ...@@ -4,12 +4,13 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/BurntSushi/toml"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"testing" "testing"
"github.com/BurntSushi/toml"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
) )
type ProxydClient struct { type ProxydClient struct {
......
package integration_tests package integration_tests
import ( import (
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
"os" "os"
"strings" "strings"
"testing" "testing"
"github.com/ethereum-optimism/optimism/go/proxyd"
"github.com/stretchr/testify/require"
) )
const ( const (
......
...@@ -217,7 +217,11 @@ func Start(config *Config) (func(), error) { ...@@ -217,7 +217,11 @@ func Start(config *Config) (func(), error) {
if config.Metrics.Enabled { if config.Metrics.Enabled {
addr := fmt.Sprintf("%s:%d", config.Metrics.Host, config.Metrics.Port) addr := fmt.Sprintf("%s:%d", config.Metrics.Host, config.Metrics.Port)
log.Info("starting metrics server", "addr", addr) log.Info("starting metrics server", "addr", addr)
go http.ListenAndServe(addr, promhttp.Handler()) go func() {
if err := http.ListenAndServe(addr, promhttp.Handler()); err != nil {
log.Error("error starting metrics server", "err", err)
}
}()
} }
// To allow integration tests to cleanly come up, wait // To allow integration tests to cleanly come up, wait
......
...@@ -5,10 +5,11 @@ import ( ...@@ -5,10 +5,11 @@ import (
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/log"
"github.com/go-redis/redis/v8"
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/log"
"github.com/go-redis/redis/v8"
) )
const MaxRPSScript = ` const MaxRPSScript = `
......
...@@ -2,8 +2,9 @@ package proxyd ...@@ -2,8 +2,9 @@ package proxyd
import ( import (
"encoding/json" "encoding/json"
"github.com/stretchr/testify/require"
"testing" "testing"
"github.com/stretchr/testify/require"
) )
func TestRPCResJSON(t *testing.T) { func TestRPCResJSON(t *testing.T) {
......
...@@ -107,15 +107,15 @@ func (s *Server) WSListenAndServe(host string, port int) error { ...@@ -107,15 +107,15 @@ func (s *Server) WSListenAndServe(host string, port int) error {
func (s *Server) Shutdown() { func (s *Server) Shutdown() {
if s.rpcServer != nil { if s.rpcServer != nil {
s.rpcServer.Shutdown(context.Background()) _ = s.rpcServer.Shutdown(context.Background())
} }
if s.wsServer != nil { if s.wsServer != nil {
s.wsServer.Shutdown(context.Background()) _ = s.wsServer.Shutdown(context.Background())
} }
} }
func (s *Server) HandleHealthz(w http.ResponseWriter, r *http.Request) { func (s *Server) HandleHealthz(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK")) _, _ = w.Write([]byte("OK"))
} }
func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) { func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
...@@ -159,7 +159,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) { ...@@ -159,7 +159,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
return return
} }
batchRes := make([]*RPCRes, len(reqs), len(reqs)) batchRes := make([]*RPCRes, len(reqs))
var batchContainsCached bool var batchContainsCached bool
for i := 0; i < len(reqs); i++ { for i := 0; i < len(reqs); i++ {
req, err := ParseRPCReq(reqs[i]) req, err := ParseRPCReq(reqs[i])
...@@ -301,7 +301,7 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context ...@@ -301,7 +301,7 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context
} }
return context.WithValue( return context.WithValue(
r.Context(), r.Context(),
ContextKeyReqID, ContextKeyReqID, // nolint:staticcheck
randStr(10), randStr(10),
) )
} }
...@@ -321,11 +321,11 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context ...@@ -321,11 +321,11 @@ func (s *Server) populateContext(w http.ResponseWriter, r *http.Request) context
} }
} }
ctx := context.WithValue(r.Context(), ContextKeyAuth, s.authenticatedPaths[authorization]) ctx := context.WithValue(r.Context(), ContextKeyAuth, s.authenticatedPaths[authorization]) // nolint:staticcheck
ctx = context.WithValue(ctx, ContextKeyXForwardedFor, xff) ctx = context.WithValue(ctx, ContextKeyXForwardedFor, xff) // nolint:staticcheck
return context.WithValue( return context.WithValue(
ctx, ctx,
ContextKeyReqID, ContextKeyReqID, // nolint:staticcheck
randStr(10), randStr(10),
) )
} }
...@@ -413,17 +413,6 @@ func GetXForwardedFor(ctx context.Context) string { ...@@ -413,17 +413,6 @@ func GetXForwardedFor(ctx context.Context) string {
return xff return xff
} }
type recordLenReader struct {
io.Reader
Len int
}
func (r *recordLenReader) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
r.Len += n
return
}
type recordLenWriter struct { type recordLenWriter struct {
io.Writer io.Writer
Len int Len int
......
...@@ -35,8 +35,8 @@ func main() { ...@@ -35,8 +35,8 @@ func main() {
app.Description = "Teleportr bridge from L1 to L2" app.Description = "Teleportr bridge from L1 to L2"
app.Commands = []cli.Command{ app.Commands = []cli.Command{
{ {
Name: "migrate", Name: "migrate",
Usage: "Migrates teleportr's database", Usage: "Migrates teleportr's database",
Action: teleportr.Migrate(), Action: teleportr.Migrate(),
}, },
} }
......
...@@ -181,4 +181,4 @@ func Migrate() func(ctx *cli.Context) error { ...@@ -181,4 +181,4 @@ func Migrate() func(ctx *cli.Context) error {
log.Info("Done") log.Info("Done")
return nil return nil
} }
} }
\ No newline at end of file
FROM golang:1.17.8-alpine3.15
RUN apk add --no-cache make gcc musl-dev linux-headers git jq curl bash gzip ca-certificates openssh && \
go install gotest.tools/gotestsum@latest && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.2
CMD ["bash"]
FROM python:3.8.12-slim-buster
RUN apt-get update && \
apt-get install -y curl openssh-client git build-essential ca-certificates && \
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh && \
bash nodesource_setup.sh && \
apt-get install -y nodejs && \
npm i -g yarn && \
npm i -g depcheck && \
pip install slither-analyzer
...@@ -23,4 +23,4 @@ curl \ ...@@ -23,4 +23,4 @@ curl \
--output /dev/null \ --output /dev/null \
$L2_URL $L2_URL
npx hardhat test --network optimism --no-compile npx hardhat test --network optimism --no-compile "$@"
#!/bin/bash #!/bin/bash
CONTAINER=l2geth CONTAINER=l2geth
RETRIES=30 RETRIES=90
i=0 i=0
until docker-compose logs l2geth | grep -q "Starting Sequencer Loop"; until docker-compose logs l2geth | grep -q "Starting Sequencer Loop";
do do
sleep 3 sleep 1
if [ $i -eq $RETRIES ]; then if [ $i -eq $RETRIES ]; then
echo 'Timed out waiting for sequencer' echo 'Timed out waiting for sequencer'
break break
......
module.exports = { module.exports = {
extends: '../../.eslintrc.js', extends: '../../.eslintrc.js',
ignorePatterns: [
'src/contract-artifacts.ts',
'src/contract-deployed-artifacts.ts',
],
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
], ],
"scripts": { "scripts": {
"start": "ts-node ./src/service.ts", "start": "ts-node ./src/service.ts",
"test:coverage": "echo 'No tests defined.'",
"build": "tsc -p ./tsconfig.build.json", "build": "tsc -p ./tsconfig.build.json",
"clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo", "clean": "rimraf dist/ ./tsconfig.build.tsbuildinfo",
"lint": "yarn lint:fix && yarn lint:check", "lint": "yarn lint:fix && yarn lint:check",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
], ],
"scripts": { "scripts": {
"start": "ts-node ./src/service", "start": "ts-node ./src/service",
"test:coverage": "echo 'No tests defined.'",
"build": "tsc -p tsconfig.build.json", "build": "tsc -p tsconfig.build.json",
"clean": "rimraf ./dist ./tsconfig.build.tsbuildinfo", "clean": "rimraf ./dist ./tsconfig.build.tsbuildinfo",
"lint": "yarn run lint:fix && yarn run lint:check", "lint": "yarn run lint:fix && yarn run lint:check",
......
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