Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bridge): add lint and test workflow #952

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/070_lint_and_test_go_bridge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Lint Go bridge

on:
push:
paths:
- bridge/tfchain_bridge/**
workflow_dispatch:

jobs:
lint:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
submodules: "true"
sparse-checkout: |
clients/tfchain-client-go
bridge/tfchain_bridge

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20"
cache: false
# cache-dependency-path: bridge/tfchain_bridge/go.sum
id: go

- name: golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
with:
args: --timeout 3m --verbose
working-directory: bridge/tfchain_bridge

- name: staticcheck
uses: dominikh/staticcheck-action@v1.3.0
with:
version: "2022.1.3"
working-directory: bridge/tfchain_bridge
env:
GO111MODULE: on

- name: gofmt
uses: Jerome1337/gofmt-action@v1.0.5
with:
gofmt-path: './bridge/tfchain_bridge'
gofmt-flags: "-l -d"
4 changes: 2 additions & 2 deletions bridge/tfchain_bridge/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/threefoldtech/tfchain_bridge
module github.com/threefoldtech/tfchain/bridge/tfchain_bridge

go 1.17

Expand Down Expand Up @@ -52,4 +52,4 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/threefoldtech/tfchain/clients/tfchain-client-go => ../../clients/tfchain-client-go
replace github.com/threefoldtech/tfchain/clients/tfchain-client-go => ../../clients/tfchain-client-go
6 changes: 3 additions & 3 deletions bridge/tfchain_bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/rs/zerolog/log"
flag "github.com/spf13/pflag"
"github.com/threefoldtech/tfchain_bridge/pkg"
"github.com/threefoldtech/tfchain_bridge/pkg/bridge"
"github.com/threefoldtech/tfchain_bridge/pkg/logger"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/bridge"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/logger"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions bridge/tfchain_bridge/pkg/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/threefoldtech/tfchain_bridge/pkg"
"github.com/threefoldtech/tfchain_bridge/pkg/stellar"
subpkg "github.com/threefoldtech/tfchain_bridge/pkg/substrate"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/stellar"
subpkg "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/substrate"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions bridge/tfchain_bridge/pkg/bridge/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
hProtocol "github.com/stellar/go/protocols/horizon"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg"
_logger "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/logger"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/tfchain_bridge/pkg"
_logger "github.com/threefoldtech/tfchain_bridge/pkg/logger"
)

// mint handler for stellar
Expand Down
6 changes: 3 additions & 3 deletions bridge/tfchain_bridge/pkg/bridge/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
hProtocol "github.com/stellar/go/protocols/horizon"
"github.com/threefoldtech/tfchain_bridge/pkg"
_logger "github.com/threefoldtech/tfchain_bridge/pkg/logger"
subpkg "github.com/threefoldtech/tfchain_bridge/pkg/substrate"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg"
_logger "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/logger"
subpkg "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/substrate"
)

// refund handler for stellar
Expand Down
4 changes: 2 additions & 2 deletions bridge/tfchain_bridge/pkg/bridge/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg"
subpkg "github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg/substrate"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/tfchain_bridge/pkg"
subpkg "github.com/threefoldtech/tfchain_bridge/pkg/substrate"
)

func (bridge *Bridge) handleWithdrawCreated(ctx context.Context, withdraw subpkg.WithdrawCreatedEvent) error {
Expand Down
8 changes: 5 additions & 3 deletions bridge/tfchain_bridge/pkg/stellar/stellar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
horizoneffects "github.com/stellar/go/protocols/horizon/effects"
"github.com/stellar/go/protocols/horizon/operations"
"github.com/stellar/go/txnbuild"
"github.com/threefoldtech/tfchain/bridge/tfchain_bridge/pkg"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/tfchain_bridge/pkg"
)

const (
Expand All @@ -42,6 +42,8 @@ type StellarWallet struct {
sequenceNumber int64
}

type TraceIdKey struct{}

func NewStellarWallet(ctx context.Context, config *pkg.StellarConfig) (*StellarWallet, error) {
kp, err := keypair.ParseFull(config.StellarSeed)

Expand Down Expand Up @@ -93,7 +95,7 @@ func (w *StellarWallet) CreatePaymentAndReturnSignature(ctx context.Context, tar
}

func (w *StellarWallet) CreatePaymentWithSignaturesAndSubmit(ctx context.Context, target string, amount uint64, txHash string, signatures []substrate.StellarSignature, sequenceNumber int64) error {
ctx_with_trace_id := context.WithValue(ctx, "trace_id", txHash)
ctx_with_trace_id := context.WithValue(ctx, TraceIdKey{}, txHash)

txnBuild, err := w.generatePaymentOperation(amount, target, sequenceNumber)
if err != nil {
Expand Down Expand Up @@ -122,7 +124,7 @@ func (w *StellarWallet) CreatePaymentWithSignaturesAndSubmit(ctx context.Context
}

func (w *StellarWallet) CreateRefundPaymentWithSignaturesAndSubmit(ctx context.Context, target string, amount uint64, txHash string, signatures []substrate.StellarSignature, sequenceNumber int64) error {
ctx_with_trace_id := context.WithValue(ctx, "trace_id", txHash)
ctx_with_trace_id := context.WithValue(ctx, TraceIdKey{}, txHash)
txnBuild, err := w.generatePaymentOperation(amount, target, sequenceNumber)
if err != nil {
return err
Expand Down
Loading