diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4905250..80a883a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,3 +14,4 @@ updates: open-pull-requests-limit: 10 labels: - T:dependencies + target-branch: dev diff --git a/.github/workflows/checks.golang.yml b/.github/workflows/checks.golang.yml new file mode 100644 index 0000000..473b94d --- /dev/null +++ b/.github/workflows/checks.golang.yml @@ -0,0 +1,35 @@ +# +# Generated by @zondax/cli +# +name: Checks + +on: + push: + branches: [ main, dev ] + pull_request: + branches: [ main, dev ] + +jobs: + checks: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: true + - uses: actions/setup-go@v3 + with: + go-version: '1.21' + - name: Build + run: | + make build + - name: ModTidy check + run: make check-modtidy + - name: Lint check + run: | + export PATH=$PATH:$(go env GOPATH)/bin + make install_lint + make lint + - name: Run tests + run: | + make test \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/main.yml similarity index 64% rename from .github/workflows/test.yml rename to .github/workflows/main.yml index a3c7bbb..94edddd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,16 @@ name: Test + on: + # Triggers the workflow on push or pull request events but only for the main branch push: branches: - - master + - main pull_request: + branches: + - main + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: jobs: @@ -13,7 +20,10 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.18' + go-version: '1.21' + - name: Build + run: | + go build - name: test & coverage report creation run: | go test common.go -mod=readonly -timeout 5m -short -race -coverprofile=coverage.txt -covermode=atomic diff --git a/.gitignore b/.gitignore index 09c773a..5cebab9 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ cmake-build-debug/ \.idea/workspace\.xml \.idea/ vendor/ + +coverage.txt diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 539e6d7..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,7 +0,0 @@ -# CHANGELOG - -## Unreleased - -### API-Breaking Changes - -* [#39](https://github.com/cosmos/ledger-cosmos-go/pull/39) Add support for SIGN_MODE_TEXTUAL by adding a new argument `p2 byte` to `SignSECP256K1`. diff --git a/LICENSE b/LICENSE index 5f0220d..c416a42 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2018 - 2022 ZondaX AG + Copyright Zondax AG Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..63b6a37 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +# +# Generated by @zondax/cli +# +-include Makefile.settings.mk + +# Get all directories under cmd +CMDS=$(shell find cmd -type d) + +# Strip cmd/ from directory names and generate output binary names +BINS=$(subst cmd/,output/,$(CMDS)) + +default: build + +build: + @go build + +mod-tidy: + @go mod tidy + +mod-clean: + go clean -modcache + +mod-update: mod-clean + @go get -u ./... + @go mod tidy + +generate: mod-tidy + go generate ./internal/... + +version: build + ./output/$(APP_NAME) version + +clean: + go clean + +gitclean: + git clean -xfd + git submodule foreach --recursive git clean -xfd + +install_lint: + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest + +check-modtidy: + @go mod tidy + git diff --exit-code -- go.mod go.sum + +lint: + golangci-lint --version + golangci-lint run + +test: + @go test common.go -mod=readonly -timeout 5m -short -race -coverprofile=coverage.txt -covermode=atomic + @go test common.go -mod=readonly -timeout 5m diff --git a/README.md b/README.md index 45bd224..b580ad4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,6 @@ # ledger-cosmos-go -[![Test](https://github.com/cosmos/ledger-cosmos-go/actions/workflows/test.yml/badge.svg)](https://github.com/cosmos/ledger-cosmos-go/actions/workflows/test.yml) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![GithubActions](https://github.com/zondax/ledger-go/actions/workflows/main.yml/badge.svg)](https://github.com/Zondax/ledger-go/blob/main/.github/workflows/main.yml) [![Build status](https://ci.appveyor.com/api/projects/status/ovpfx35t289n3403?svg=true)](https://ci.appveyor.com/project/cosmos/ledger-cosmos-go) -This project is work in progress. Some aspects are subject to change. - -# Get source -Apart from cloning, be sure you install dep dependency management tool -https://github.com/golang/dep diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 1cc50fb..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: 1.0.0.{build} - -platform: x64 - -branches: - only: - - master - -clone_folder: c:\ledger-cosmos-go - -environment: - GOPATH: c:\gopath - -install: - - choco install -y mingw - - echo %PATH% - - echo %GOPATH% - - set PATH=%GOPATH%\bin;c:\go\bin;C:\tools\mingw64\bin;%PATH% - - go version - - go env - -build_script: - - go build -x ./common.go ./user_app.go ./validator_app.go - - go test ./common - diff --git a/common.go b/common.go index debd8f7..8d8c17f 100644 --- a/common.go +++ b/common.go @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 ZondaX AG +* (c) Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/common_test.go b/common_test.go index 9ab487d..42d46ca 100644 --- a/common_test.go +++ b/common_test.go @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 Zondax AG +* (c) Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/user_app.go b/user_app.go index e2beec9..41c121c 100644 --- a/user_app.go +++ b/user_app.go @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 ZondaX AG +* (c) Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -330,7 +330,7 @@ func (ledger *LedgerCosmos) getAddressPubKeySECP256K1(bip32Path []uint32, hrp st } pubkey = response[0:33] - addr = string(response[33:len(response)]) + addr = string(response[33:]) return pubkey, addr, err } diff --git a/user_app_test.go b/user_app_test.go index 0597c27..79d04bc 100644 --- a/user_app_test.go +++ b/user_app_test.go @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 ZondaX AG +* (c) Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import ( func Test_UserFindLedger(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } assert.NotNil(t, userApp) @@ -44,7 +44,7 @@ func Test_UserFindLedger(t *testing.T) { func Test_UserGetVersion(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() @@ -61,7 +61,7 @@ func Test_UserGetVersion(t *testing.T) { func Test_UserGetPublicKey(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() @@ -85,7 +85,7 @@ func Test_UserGetPublicKey(t *testing.T) { func Test_GetAddressPubKeySECP256K1_Zero(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() @@ -109,7 +109,7 @@ func Test_GetAddressPubKeySECP256K1_Zero(t *testing.T) { func Test_GetAddressPubKeySECP256K1(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() @@ -133,7 +133,7 @@ func Test_GetAddressPubKeySECP256K1(t *testing.T) { func Test_UserPK_HDPaths(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() @@ -200,7 +200,7 @@ func getDummyTx() []byte { func Test_UserSign(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() @@ -219,26 +219,26 @@ func Test_UserSign(t *testing.T) { } if err != nil { - t.Fatalf("[GetPK] Error: " + err.Error()) + t.Fatalf("[GetPK] Error: %s", err.Error()) return } pub2, err := btcec.ParsePubKey(pubKey[:]) if err != nil { - t.Fatalf("[ParsePK] Error: " + err.Error()) + t.Fatalf("[ParsePK] Error: %s", err.Error()) return } sig2, err := ecdsa.ParseDERSignature(signature[:]) if err != nil { - t.Fatalf("[ParseSig] Error: " + err.Error()) + t.Fatalf("[ParseSig] Error: %s", err.Error()) return } hash := sha256.Sum256(message) verified := sig2.Verify(hash[:], pub2) if !verified { - t.Fatalf("[VerifySig] Error verifying signature: " + err.Error()) + t.Fatalf("[VerifySig] Error verifying signature: %s", err.Error()) return } } @@ -246,7 +246,7 @@ func Test_UserSign(t *testing.T) { func Test_UserSign_Fails(t *testing.T) { userApp, err := FindLedgerCosmosUserApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%v", err) } defer userApp.Close() diff --git a/validator_app.go b/validator_app.go index 617c536..97db459 100644 --- a/validator_app.go +++ b/validator_app.go @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 ZondaX AG +* (c) Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/validator_app_test.go b/validator_app_test.go index c61a26c..9f70b2f 100644 --- a/validator_app_test.go +++ b/validator_app_test.go @@ -1,5 +1,5 @@ /******************************************************************************* -* (c) 2018 - 2022 ZondaX AG +* (c) Zondax AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,15 +17,16 @@ package ledger_cosmos_go import ( + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func Test_ValGetVersion(t *testing.T) { validatorApp, err := FindLedgerTendermintValidatorApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%s", err.Error()) } defer validatorApp.Close() @@ -40,7 +41,7 @@ func Test_ValGetVersion(t *testing.T) { func Test_ValGetPublicKey(t *testing.T) { validatorApp, err := FindLedgerTendermintValidatorApp() if err != nil { - t.Fatalf(err.Error()) + t.Fatalf("%s", err.Error()) } defer validatorApp.Close()