Better lint and formatting (#1263)

Enforce goimports, add tooling and documentation, and run it on the repo.
This commit is contained in:
tbjump 2022-06-21 12:18:16 -07:00 committed by GitHub
parent 57fe302314
commit 4575fe05d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 319 additions and 100 deletions

View File

@ -8,6 +8,9 @@ on:
jobs: jobs:
# Run the full Tilt build and wait for it to converge # Run the full Tilt build and wait for it to converge
tilt: tilt:
# in the future, we may want to run cheap lints, tests, and builds before firing up the expensive tilt test.
# But for now, we'll kick-off everything at once
# needs: [go-lint-and-tests, node, algorand, ethereum, terra, rust-lint-and-tests]
runs-on: tilt-kube-public runs-on: tilt-kube-public
# Cancel previous builds on the same branch/ref. Full runs are expensive # Cancel previous builds on the same branch/ref. Full runs are expensive
@ -72,7 +75,6 @@ jobs:
with: with:
node-version: "16" node-version: "16"
- run: cd terra && make test - run: cd terra && make test
terra-2: terra-2:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
@ -82,7 +84,7 @@ jobs:
node-version: "16" node-version: "16"
- run: cd cosmwasm && make test - run: cd cosmwasm && make test
# Run linters, Go tests and other outside-of-Tilt things. # Run Go linters, Go tests and other outside-of-Tilt things.
lint-and-tests: lint-and-tests:
# The linter is slow enough that we want to run it on the self-hosted runner # The linter is slow enough that we want to run it on the self-hosted runner
runs-on: tilt-kube-public runs-on: tilt-kube-public
@ -94,14 +96,20 @@ jobs:
- uses: actions/setup-go@v2 - uses: actions/setup-go@v2
with: with:
go-version: "1.17.5" go-version: "1.17.5"
# ensure that code is formatted - name: Install formatter
- run: GOFMT_OUTPUT="$(gofmt -l `find ./node ./event_database -name '*.go' | grep -v vendor` 2>&1)"; if [ -n "$GOFMT_OUTPUT" ]; then printf "All the following files are not correctly formatted\n${GOFMT_OUTPUT}\n"; exit 1; fi run: go install golang.org/x/tools/cmd/goimports@latest
# run linters - name: Formatting checks
- run: make generate && ./lint.sh run: ./scripts/lint.sh -l -g format
# The go-ethereum and celo-blockchain packages both implement secp256k1 using the exact same header, but that causes duplicate symbols. - name: Install linters
- run: cd node && go test -v -ldflags '-extldflags "-Wl,--allow-multiple-definition" ' ./... run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.2
- name: Run linters
run: make generate && ./scripts/lint.sh -g lint
# Run rust lints and tests # The go-ethereum and celo-blockchain packages both implement secp256k1 using the exact same header, but that causes duplicate symbols.
- name: Run golang tests
run: cd node && go test -v -ldflags '-extldflags "-Wl,--allow-multiple-definition" ' ./...
# Run Rust lints and tests
rust-lint-and-tests: rust-lint-and-tests:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:

View File

@ -66,3 +66,24 @@ of communication (like transfers). It is likely that you can use the existing Wo
own features on top of, without requiring any changes in Wormhole itself. own features on top of, without requiring any changes in Wormhole itself.
Please open a GitHub issue outlining your use case, and we can help you build it! Please open a GitHub issue outlining your use case, and we can help you build it!
# Pre-Commit checks
Run `./scripts/lint.sh -d format` and `./scripts/lint.sh lint`.
## IDE Integration
### Golang formatting
You must format your code with `goimports` before submitting.
You can install it with `go install golang.org/x/tools/cmd/goimports@latest` and run it with `goimports -d ./`.
You can enable it in VSCode with the following in your `settings.json`.
```json
"go.useLanguageServer": true,
"go.formatTool": "goimports",
"[go]": {
"editor.defaultFormatter": "golang.go",
"editor.formatOnSaveMode": "file",
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
},
```

View File

@ -5,8 +5,9 @@ RUN useradd -u 1000 -U -m -d /home/lint lint
USER 1000 USER 1000
WORKDIR /home/lint WORKDIR /home/lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \ # install goimports
sh -s -- -b ~ v1.42.0 RUN go install golang.org/x/tools/cmd/goimports@latest
RUN --mount=type=bind,target=/app,source=node cd /app && \ # install golangci-lint
GOGC=off ~/golangci-lint run --skip-dirs pkg/supervisor --timeout=10m --out-format=github-actions ./... RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(go env GOPATH)/bin v1.46.2

View File

@ -1,8 +0,0 @@
#!/usr/bin/env bash
# fail if any command fails
set -e
set -o pipefail
# we duplicate stderr to stdout and then filter and parse stdout to only include errors that are readable as github annotations
DOCKER_BUILDKIT=1 docker build -f Dockerfile.lint . 2>&1 | while read line; do echo $line; echo $line >&2; done | (grep "::" || true) | cut -f3- -d " "

View File

@ -2,11 +2,12 @@ package debug
import ( import (
"encoding/hex" "encoding/hex"
"log"
"strings"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"log"
"strings"
) )
var decodeVaaCmd = &cobra.Command{ var decodeVaaCmd = &cobra.Command{

View File

@ -3,15 +3,16 @@ package guardiand
import ( import (
"context" "context"
"fmt" "fmt"
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
"github.com/certusone/wormhole/node/pkg/vaa"
"github.com/spf13/cobra"
"log" "log"
"os" "os"
"sort" "sort"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"time" "time"
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
"github.com/certusone/wormhole/node/pkg/vaa"
"github.com/spf13/cobra"
) )
// How to test in container: // How to test in container:

View File

@ -7,6 +7,13 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"math"
"math/rand"
"net"
"net/http"
"os"
"time"
"github.com/certusone/wormhole/node/pkg/db" "github.com/certusone/wormhole/node/pkg/db"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1" publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
@ -15,12 +22,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"math"
"math/rand"
"net"
"net/http"
"os"
"time"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
nodev1 "github.com/certusone/wormhole/node/pkg/proto/node/v1" nodev1 "github.com/certusone/wormhole/node/pkg/proto/node/v1"

View File

@ -1,9 +1,10 @@
package guardiand package guardiand
import ( import (
"unicode"
"go.uber.org/zap/buffer" "go.uber.org/zap/buffer"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
"unicode"
) )
type consoleEncoder struct { type consoleEncoder struct {

View File

@ -2,6 +2,8 @@ package guardiand
import ( import (
"fmt" "fmt"
"net"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/db" "github.com/certusone/wormhole/node/pkg/db"
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1" publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
@ -9,7 +11,6 @@ import (
"github.com/certusone/wormhole/node/pkg/supervisor" "github.com/certusone/wormhole/node/pkg/supervisor"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc" "google.golang.org/grpc"
"net"
) )
func publicrpcServiceRunnable(logger *zap.Logger, listenAddr string, db *db.Database, gst *common.GuardianSetState) (supervisor.Runnable, *grpc.Server, error) { func publicrpcServiceRunnable(logger *zap.Logger, listenAddr string, db *db.Database, gst *common.GuardianSetState) (supervisor.Runnable, *grpc.Server, error) {

View File

@ -3,7 +3,11 @@ package guardiand
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1" "net"
"net/http"
"strings"
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
"github.com/certusone/wormhole/node/pkg/supervisor" "github.com/certusone/wormhole/node/pkg/supervisor"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/improbable-eng/grpc-web/go/grpcweb" "github.com/improbable-eng/grpc-web/go/grpcweb"
@ -11,9 +15,6 @@ import (
"golang.org/x/crypto/acme" "golang.org/x/crypto/acme"
"golang.org/x/crypto/acme/autocert" "golang.org/x/crypto/acme/autocert"
"google.golang.org/grpc" "google.golang.org/grpc"
"net"
"net/http"
"strings"
) )
func allowCORSWrapper(h http.Handler) http.Handler { func allowCORSWrapper(h http.Handler) http.Handler {

View File

@ -2,8 +2,9 @@ package guardiand
import ( import (
"fmt" "fmt"
"github.com/coreos/go-systemd/activation"
"net" "net"
"github.com/coreos/go-systemd/activation"
) )
func getSDListeners() ([]net.Listener, error) { func getSDListeners() ([]net.Listener, error) {

View File

@ -2,10 +2,11 @@ package cmd
import ( import (
"fmt" "fmt"
"os"
"github.com/certusone/wormhole/node/cmd/debug" "github.com/certusone/wormhole/node/cmd/debug"
"github.com/certusone/wormhole/node/cmd/spy" "github.com/certusone/wormhole/node/cmd/spy"
"github.com/certusone/wormhole/node/pkg/version" "github.com/certusone/wormhole/node/pkg/version"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"

View File

@ -4,10 +4,15 @@ import (
"context" "context"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"net"
"net/http"
"os"
"sync"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/p2p" "github.com/certusone/wormhole/node/pkg/p2p"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/certusone/wormhole/node/pkg/proto/spy/v1" spyv1 "github.com/certusone/wormhole/node/pkg/proto/spy/v1"
"github.com/certusone/wormhole/node/pkg/supervisor" "github.com/certusone/wormhole/node/pkg/supervisor"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/google/uuid" "github.com/google/uuid"
@ -20,10 +25,6 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"net"
"net/http"
"os"
"sync"
) )
var ( var (

View File

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/hex" "encoding/hex"
"flag" "flag"
"github.com/certusone/wormhole/node/pkg/notify/discord" "github.com/certusone/wormhole/node/pkg/notify/discord"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"go.uber.org/zap" "go.uber.org/zap"

View File

@ -4,11 +4,12 @@ import (
"context" "context"
"flag" "flag"
"fmt" "fmt"
"log"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
nodev1 "github.com/certusone/wormhole/node/pkg/proto/node/v1" nodev1 "github.com/certusone/wormhole/node/pkg/proto/node/v1"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"google.golang.org/grpc" "google.golang.org/grpc"
"log"
) )
var ( var (

View File

@ -5,6 +5,12 @@ import (
"encoding/hex" "encoding/hex"
"flag" "flag"
"fmt" "fmt"
"log"
"net/http"
"strconv"
"strings"
"time"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/db" "github.com/certusone/wormhole/node/pkg/db"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
@ -14,11 +20,6 @@ import (
"github.com/gagliardetto/solana-go/rpc" "github.com/gagliardetto/solana-go/rpc"
"golang.org/x/time/rate" "golang.org/x/time/rate"
"google.golang.org/grpc" "google.golang.org/grpc"
"log"
"net/http"
"strconv"
"strings"
"time"
) )
var ( var (

View File

@ -7,6 +7,8 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
"github.com/algorand/go-algorand-sdk/client/v2/algod" "github.com/algorand/go-algorand-sdk/client/v2/algod"
"github.com/algorand/go-algorand-sdk/client/v2/indexer" "github.com/algorand/go-algorand-sdk/client/v2/indexer"
"github.com/algorand/go-algorand-sdk/crypto" "github.com/algorand/go-algorand-sdk/crypto"
@ -21,7 +23,6 @@ import (
"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"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type ( type (

View File

@ -1,9 +1,10 @@
package common package common
import ( import (
"github.com/certusone/wormhole/node/pkg/vaa"
"time" "time"
"github.com/certusone/wormhole/node/pkg/vaa"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )

View File

@ -1,10 +1,10 @@
package common package common
import ( import (
"github.com/grpc-ecosystem/go-grpc-middleware" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"github.com/grpc-ecosystem/go-grpc-middleware/tags" grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
"github.com/grpc-ecosystem/go-grpc-prometheus" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc" "google.golang.org/grpc"
) )

View File

@ -1,9 +1,10 @@
package common package common
import ( import (
"testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestKeyIndex(t *testing.T) { func TestKeyIndex(t *testing.T) {

View File

@ -2,11 +2,12 @@ package common
import ( import (
"fmt" "fmt"
"io/ioutil"
"os"
"github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"go.uber.org/zap" "go.uber.org/zap"
"io/ioutil"
"os"
) )
func GetOrCreateNodeKey(logger *zap.Logger, path string) (crypto.PrivKey, error) { func GetOrCreateNodeKey(logger *zap.Logger, path string) (crypto.PrivKey, error) {

View File

@ -2,8 +2,9 @@ package common
import ( import (
"encoding/hex" "encoding/hex"
"github.com/stretchr/testify/assert"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestAESGCM(t *testing.T) { func TestAESGCM(t *testing.T) {

View File

@ -2,9 +2,10 @@ package common
import ( import (
"fmt" "fmt"
"golang.org/x/sys/unix"
"os" "os"
"syscall" "syscall"
"golang.org/x/sys/unix"
) )
// LockMemory locks current and future pages in memory to protect secret keys from being swapped out to disk. // LockMemory locks current and future pages in memory to protect secret keys from being swapped out to disk.

View File

@ -3,10 +3,11 @@ package db
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/certusone/wormhole/node/pkg/vaa"
"github.com/dgraph-io/badger/v3"
"strconv" "strconv"
"strings" "strings"
"github.com/certusone/wormhole/node/pkg/vaa"
"github.com/dgraph-io/badger/v3"
) )
type Database struct { type Database struct {

View File

@ -3,8 +3,9 @@ package devnet
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/stretchr/testify/assert"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestDeterministicP2PPrivKeyByIndex(t *testing.T) { func TestDeterministicP2PPrivKeyByIndex(t *testing.T) {

View File

@ -3,10 +3,11 @@ package ethereum
import ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
eth_common "github.com/ethereum/go-ethereum/common" eth_common "github.com/ethereum/go-ethereum/common"
"time"
) )
var ( var (

View File

@ -8,10 +8,11 @@ package ethereum
import ( import (
"context" "context"
"time"
common "github.com/certusone/wormhole/node/pkg/common" common "github.com/certusone/wormhole/node/pkg/common"
ethRpc "github.com/ethereum/go-ethereum/rpc" ethRpc "github.com/ethereum/go-ethereum/rpc"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type MoonbeamFinalizer struct { type MoonbeamFinalizer struct {

View File

@ -1,10 +1,11 @@
package ethereum package ethereum
import ( import (
"testing"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestPadAddress(t *testing.T) { func TestPadAddress(t *testing.T) {

View File

@ -3,12 +3,13 @@ package discord
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"strings"
"sync"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/api"
"github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/discord"
"go.uber.org/zap" "go.uber.org/zap"
"strings"
"sync"
) )
type DiscordNotifier struct { type DiscordNotifier struct {

View File

@ -1,6 +1,10 @@
package p2p package p2p
import ( import (
"math"
"regexp"
"strconv"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/certusone/wormhole/node/pkg/version" "github.com/certusone/wormhole/node/pkg/version"
@ -8,9 +12,6 @@ import (
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"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"
"math"
"regexp"
"strconv"
) )
var ( var (

View File

@ -5,6 +5,9 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
"fmt" "fmt"
"strings"
"time"
node_common "github.com/certusone/wormhole/node/pkg/common" node_common "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/certusone/wormhole/node/pkg/version" "github.com/certusone/wormhole/node/pkg/version"
@ -12,8 +15,6 @@ import (
ethcrypto "github.com/ethereum/go-ethereum/crypto" ethcrypto "github.com/ethereum/go-ethereum/crypto"
"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"
"strings"
"time"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"

View File

@ -1,9 +1,10 @@
package p2p package p2p
import ( import (
"sync"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"sync"
) )
// The p2p package implements a simple global metrics registry singleton for node status values transmitted on-chain. // The p2p package implements a simple global metrics registry singleton for node status values transmitted on-chain.

View File

@ -3,11 +3,12 @@ package p2p
import ( import (
"crypto/ed25519" "crypto/ed25519"
"crypto/rand" "crypto/rand"
"testing"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"github.com/mr-tron/base58" "github.com/mr-tron/base58"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestNewRegistry(t *testing.T) { func TestNewRegistry(t *testing.T) {

View File

@ -2,9 +2,10 @@ package processor
import ( import (
"encoding/hex" "encoding/hex"
"time"
"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"
"time"
ethcommon "github.com/ethereum/go-ethereum/common" ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"

View File

@ -3,12 +3,13 @@ package processor
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"time"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/db" "github.com/certusone/wormhole/node/pkg/db"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
"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"
"time"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -3,6 +3,7 @@ package processor
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"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"

View File

@ -4,6 +4,9 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/rand" "crypto/rand"
"testing"
"time"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/certusone/wormhole/node/pkg/vaa" "github.com/certusone/wormhole/node/pkg/vaa"
@ -12,8 +15,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zaptest/observer" "go.uber.org/zap/zaptest/observer"
"testing"
"time"
) )
func getVAA() vaa.VAA { func getVAA() vaa.VAA {

View File

@ -3,9 +3,10 @@ package processor
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"github.com/certusone/wormhole/node/pkg/notify/discord"
"time" "time"
"github.com/certusone/wormhole/node/pkg/notify/discord"
"github.com/certusone/wormhole/node/pkg/db" "github.com/certusone/wormhole/node/pkg/db"
ethcommon "github.com/ethereum/go-ethereum/common" ethcommon "github.com/ethereum/go-ethereum/common"

View File

@ -2,8 +2,9 @@ package processor
import ( import (
"fmt" "fmt"
"github.com/stretchr/testify/assert"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestCalculateQuorum(t *testing.T) { func TestCalculateQuorum(t *testing.T) {

View File

@ -2,12 +2,13 @@ package publicrpc
import ( import (
"context" "context"
"testing"
publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1" publicrpcv1 "github.com/certusone/wormhole/node/pkg/proto/publicrpc/v1"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"testing"
) )
func TestGetSignedVAANoMessage(t *testing.T) { func TestGetSignedVAANoMessage(t *testing.T) {

View File

@ -4,6 +4,8 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"time"
"github.com/certusone/wormhole/node/pkg/common" "github.com/certusone/wormhole/node/pkg/common"
"github.com/certusone/wormhole/node/pkg/p2p" "github.com/certusone/wormhole/node/pkg/p2p"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1" gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
@ -19,7 +21,6 @@ import (
"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"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
type SolanaWatcher struct { type SolanaWatcher struct {

View File

@ -1,16 +1,17 @@
package telemetry package telemetry
import ( import (
"cloud.google.com/go/logging"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"cloud.google.com/go/logging"
"github.com/blendle/zapdriver" "github.com/blendle/zapdriver"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/buffer" "go.uber.org/zap/buffer"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
"google.golang.org/api/option" "google.golang.org/api/option"
"io/ioutil"
) )
type Telemetry struct { type Telemetry struct {

View File

@ -5,14 +5,15 @@ import (
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/certusone/wormhole/node/pkg/p2p"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/prometheus/client_golang/prometheus/promauto"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
"github.com/certusone/wormhole/node/pkg/p2p"
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
eth_common "github.com/ethereum/go-ethereum/common" eth_common "github.com/ethereum/go-ethereum/common"

View File

@ -1,8 +1,11 @@
package vaa package vaa
import "testing" import (
import "time" "testing"
import "github.com/stretchr/testify/assert" "time"
"github.com/stretchr/testify/assert"
)
// Testing the expected default behavior of a CreateGovernanceVAA // Testing the expected default behavior of a CreateGovernanceVAA
func TestCreateGovernanceVAA(t *testing.T) { func TestCreateGovernanceVAA(t *testing.T) {

View File

@ -3,6 +3,7 @@ package vaa
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )

View File

@ -2,9 +2,10 @@ package vaa
import ( import (
"encoding/hex" "encoding/hex"
"testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestCoreModule(t *testing.T) { func TestCoreModule(t *testing.T) {

View File

@ -5,14 +5,15 @@ import (
"crypto/elliptic" "crypto/elliptic"
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"math/big" "math/big"
"reflect" "reflect"
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestChainIDFromString(t *testing.T) { func TestChainIDFromString(t *testing.T) {

View File

@ -4,11 +4,12 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"testing"
"time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing"
"time"
) )
func TestSerializeDeserialize(t *testing.T) { func TestSerializeDeserialize(t *testing.T) {

152
scripts/lint.sh Executable file
View File

@ -0,0 +1,152 @@
#!/usr/bin/env bash
# fail if any command fails
set -eo pipefail -o nounset
ROOT="$(dirname "$(dirname "$(realpath "$0")")")"
DOCKERFILE="$ROOT/Dockerfile.lint"
VALID_COMMANDS=("lint" "format")
SELF_ARGS_WITHOUT_DOCKER=""
GOIMPORTS_ARGS=""
GOLANGCI_LINT_ARGS=""
print_help() {
cat <<-EOF >&2
Usage: $(basename "$0") [-h] [-c] [-w] [-d] [-l] COMMAND
COMMAND can be one of: "${VALID_COMMANDS[*]}"
-h Print this help.
-c Run in docker and don't worry about dependencies
-w Automatically fix all formatting issues
-d Print diff for all formatting issues
-l List files that have formatting issues
-g Format output to be parsed by github actions
EOF
}
format(){
if [ "$GOIMPORTS_ARGS" == "" ]; then
GOIMPORTS_ARGS="-l"
fi
# only -l supports output as github action
if [ "$GITHUB_ACTION" == "true" ]; then
GOIMPORTS_ARGS="-l"
fi
# Check for dependencies
if ! command -v goimports >/dev/null 2>&1; then
printf "%s\n" "Require goimports. You can run this command in a docker container instead with '-c' and not worry about it or install it: \n\tgo install golang.org/x/tools/cmd/goimports@latest" >&2
exit 1
fi
# Use -exec because of pitfall #1 in http://mywiki.wooledge.org/BashPitfalls
GOFMT_OUTPUT="$(find ./node ./event_database -type f -name '*.go' -not -path './node/pkg/proto/*' -print0 | xargs -r -0 goimports $GOIMPORTS_ARGS 2>&1)"
if [ -n "$GOFMT_OUTPUT" ]; then
if [ "$GITHUB_ACTION" == "true" ]; then
GOFMT_OUTPUT="$(echo "$GOFMT_OUTPUT" | awk '{print "::error file="$0"::Formatting error. Please format using ./scripts/lint.sh -d format."}')"
fi
echo "$GOFMT_OUTPUT" >&2
exit 1
fi
}
lint(){
# Check for dependencies
if ! command -v golangci-lint >/dev/null 2>&1; then
printf "%s\n" "Require golangci-lint. You can run this command in a docker container instead with '-c' and not worry about it or install it: https://golangci-lint.run/usage/install/"
fi
# Do the actual linting!
cd "$ROOT"/node
golangci-lint run --skip-dirs pkg/supervisor --timeout=10m --path-prefix=node $GOLANGCI_LINT_ARGS ./...
}
DOCKER="false"
GITHUB_ACTION="false"
while getopts 'cwdlgh' opt; do
case "$opt" in
c)
DOCKER="true"
;;
w)
GOIMPORTS_ARGS+="-w "
SELF_ARGS_WITHOUT_DOCKER+="-w "
;;
d)
GOIMPORTS_ARGS+="-d "
SELF_ARGS_WITHOUT_DOCKER+="-d "
;;
l)
GOIMPORTS_ARGS+="-l "
SELF_ARGS_WITHOUT_DOCKER+="-l "
;;
g)
GOLANGCI_LINT_ARGS+="--out-format=github-actions "
GITHUB_ACTION="true"
SELF_ARGS_WITHOUT_DOCKER+="-g "
;;
h)
print_help
exit 0
;;
?)
echo "Invalid command option." >&2
print_help
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [ "$#" -ne "1" ]; then
echo "Need to specify COMMAND." >&2
print_help
exit 1
fi
COMMAND="$1"
if [[ ! " ${VALID_COMMANDS[*]} " == *" $COMMAND "* ]]; then
echo "Invalid command $COMMAND." >&2
print_help
exit 1
fi
# run this script recursively inside docker, if requested
if [ "$DOCKER" == "true" ]; then
# The easy thing to do here would be to use a bind mount to share the code with the container.
# But this doesn't work in scenarios where we are in a container already.
# But it's easy so we just won't support that case for now.
# If we wanted to support it, my idea would be to `docker run`, `docker cp`, `docker exec`, `docker rm`.
if grep -Esq 'docker|lxc|kubepods' /proc/1/cgroup; then
echo "Already running inside a container. This situation isn't supported (yet)." >&2
exit 1
fi
DOCKER_IMAGE="$(docker build -q -f "$DOCKERFILE" .)"
DOCKER_EXEC="./scripts/$(basename "$0")"
MOUNT="--mount=type=bind,target=/app,source=$PWD"
# for safety, mount as readonly unless -w flag was given
if ! [[ "$GOIMPORTS_ARGS" =~ "w" ]]; then
MOUNT+=",readonly"
fi
docker run --workdir /app "$MOUNT" "$DOCKER_IMAGE" "$DOCKER_EXEC" $SELF_ARGS_WITHOUT_DOCKER "$COMMAND"
exit "$?"
fi
case $COMMAND in
"lint")
lint
;;
"format")
format
;;
esac