diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a825425..8812840 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: golangci: strategy: matrix: - go-version: [1.15.x,1.16.x] + go-version: [1.15.x,1.16.x,1.17.x] os: [macos-latest, ubuntu-latest] name: lint runs-on: ${{ matrix.os }} @@ -26,7 +26,7 @@ jobs: build: strategy: matrix: - go-version: [ 1.13.x,1.14.x,1.15.x, 1.16.x ] + go-version: [ 1.15.x, 1.16.x, 1.17.x ] os: [ macos-latest, ubuntu-latest ] runs-on: ${{ matrix.os }} steps: @@ -38,7 +38,7 @@ jobs: go-version: ${{ matrix.go-version }} - name: Tests - run: make test-unit + run: make run-unit-tests - name: Update code coverage run: bash <(curl -s https://codecov.io/bash) - name: Build diff --git a/.make/common.mk b/.make/common.mk deleted file mode 100644 index 9b24ae7..0000000 --- a/.make/common.mk +++ /dev/null @@ -1,72 +0,0 @@ -## Default repository domain name -ifndef GIT_DOMAIN - override GIT_DOMAIN=github.com -endif - -## Set if defined (alias variable for ease of use) -ifdef branch - override REPO_BRANCH=$(branch) - export REPO_BRANCH -endif - -## Do we have git available? -HAS_GIT := $(shell command -v git 2> /dev/null) - -ifdef HAS_GIT - ## Do we have a repo? - HAS_REPO := $(shell git rev-parse --is-inside-work-tree 2> /dev/null) - ifdef HAS_REPO - ## Automatically detect the repo owner and repo name (for local use with Git) - REPO_NAME=$(shell basename "$(shell git rev-parse --show-toplevel 2> /dev/null)") - OWNER=$(shell git config --get remote.origin.url | sed 's/git@$(GIT_DOMAIN)://g' | sed 's/\/$(REPO_NAME).git//g') - REPO_OWNER=$(shell echo $(OWNER) | tr A-Z a-z) - VERSION_SHORT=$(shell git describe --tags --always --abbrev=0) - export REPO_NAME, REPO_OWNER, VERSION_SHORT - endif -endif - -## Set the distribution folder -ifndef DISTRIBUTIONS_DIR - override DISTRIBUTIONS_DIR=./dist -endif -export DISTRIBUTIONS_DIR - -help: ## Show this help message - @egrep -h '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#' - -release:: ## Full production release (creates release in Github) - @test $(github_token) - @export GITHUB_TOKEN=$(github_token) && goreleaser --rm-dist - -release-test: ## Full production test release (everything except deploy) - @goreleaser --skip-publish --rm-dist - -release-snap: ## Test the full release (build binaries) - @goreleaser --snapshot --skip-publish --rm-dist - -replace-version: ## Replaces the version in HTML/JS (pre-deploy) - @test $(version) - @test "$(path)" - @find $(path) -name "*.html" -type f -exec sed -i '' -e "s/{{version}}/$(version)/g" {} \; - @find $(path) -name "*.js" -type f -exec sed -i '' -e "s/{{version}}/$(version)/g" {} \; - -tag: ## Generate a new tag and push (tag version=0.0.0) - @test $(version) - @git tag -a v$(version) -m "Pending full release..." - @git push origin v$(version) - @git fetch --tags -f - -tag-remove: ## Remove a tag if found (tag-remove version=0.0.0) - @test $(version) - @git tag -d v$(version) - @git push --delete origin v$(version) - @git fetch --tags - -tag-update: ## Update an existing tag to current commit (tag-update version=0.0.0) - @test $(version) - @git push --force origin HEAD:refs/tags/v$(version) - @git fetch --tags -f - -update-releaser: ## Update the goreleaser application - @brew update - @brew upgrade goreleaser diff --git a/.make/go.mk b/.make/go.mk deleted file mode 100644 index 3db3a5a..0000000 --- a/.make/go.mk +++ /dev/null @@ -1,94 +0,0 @@ -## Default to the repo name if empty -ifndef BINARY_NAME - override BINARY_NAME=app -endif - -## Define the binary name -ifdef CUSTOM_BINARY_NAME - override BINARY_NAME=$(CUSTOM_BINARY_NAME) -endif - -## Set the binary release names -DARWIN=$(BINARY_NAME)-darwin -LINUX=$(BINARY_NAME)-linux -WINDOWS=$(BINARY_NAME)-windows.exe - -.PHONY: test lint vet install - -bench: ## Run all benchmarks in the Go application - @go test -bench=. -benchmem - -build-go: ## Build the Go application (locally) - @go build -o bin/$(BINARY_NAME) - -clean-mods: ## Remove all the Go mod cache - @go clean -modcache - -coverage: ## Shows the test coverage - @go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out - -godocs: ## Sync the latest tag with GoDocs - @test $(GIT_DOMAIN) - @test $(REPO_OWNER) - @test $(REPO_NAME) - @test $(VERSION_SHORT) - @curl https://proxy.golang.org/$(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)/@v/$(VERSION_SHORT).info - -install: ## Install the application - @go build -o $$GOPATH/bin/$(BINARY_NAME) - -install-go: ## Install the application (Using Native Go) - @go install $(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME) - -lint: ## Run the golangci-lint application (install if not found) - @echo "downloading golangci-lint..." - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v1.42.0 - @echo "running golangci-lint..." - @GOGC=20 ./bin/golangci-lint run - -test: ## Runs vet, lint and ALL tests - @$(MAKE) lint - @echo "running tests..." - @go test ./... -v - -test-unit: - @go test ./... -race -coverprofile=coverage.txt -covermode=atomic - -test-short: ## Runs vet, lint and tests (excludes integration tests) - @$(MAKE) lint - @echo "running tests (short)..." - @go test ./... -v -test.short - -test-ci: ## Runs all tests via CI (exports coverage) - @$(MAKE) lint - @echo "running tests (CI)..." - @go test ./... -race -coverprofile=coverage.txt -covermode=atomic - -test-ci-no-race: ## Runs all tests via CI (no race) (exports coverage) - @$(MAKE) lint - @echo "running tests (CI - no race)..." - @go test ./... -coverprofile=coverage.txt -covermode=atomic - -test-ci-short: ## Runs unit tests via CI (exports coverage) - @$(MAKE) lint - @echo "running tests (CI - unit tests only)..." - @go test ./... -test.short -race -coverprofile=coverage.txt -covermode=atomic - -uninstall: ## Uninstall the application (and remove files) - @test $(BINARY_NAME) - @test $(GIT_DOMAIN) - @test $(REPO_OWNER) - @test $(REPO_NAME) - @go clean -i $(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME) - @rm -rf $$GOPATH/src/$(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME) - @rm -rf $$GOPATH/bin/$(BINARY_NAME) - -update: ## Update all project dependencies - @go get -u ./... && go mod tidy - -update-linter: ## Update the golangci-lint package (macOS only) - @brew upgrade golangci-lint - -vet: ## Run the Go vet application - @echo "running go vet..." - @go vet -v ./... diff --git a/Makefile b/Makefile index 770eaf9..612e9eb 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,39 @@ -# Common makefile commands & variables between projects -include .make/common.mk +SHELL=/bin/bash -# Common Golang makefile commands & variables between projects -include .make/go.mk +help: + @egrep -h '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#' -## Not defined? Use default repo name which is the application -ifeq ($(REPO_NAME),) - REPO_NAME="go-bc" -endif +run-all-tests: run-linter run-unit-tests -## Not defined? Use default repo owner -ifeq ($(REPO_OWNER),) - REPO_OWNER="libsv" -endif +pre-commit: vendor-deps run-all-tests -.PHONY: clean +run-unit-tests: + @go clean -testcache && go test -v ./... -race -all: ## Runs multiple commands - @$(MAKE) test +run-unit-tests-cover: + @go test ./... -race -v -coverprofile cover.out && \ + go tool cover -html=cover.out -o cover.html && \ + open file:///$(shell pwd)/cover.html -clean: ## Remove previous builds and any test cache data - @go clean -cache -testcache -i -r - @test $(DISTRIBUTIONS_DIR) - @if [ -d $(DISTRIBUTIONS_DIR) ]; then rm -r $(DISTRIBUTIONS_DIR); fi +run-linter: + @golangci-lint run --deadline=480s --skip-dirs=vendor --tests -release:: ## Runs common.release then runs godocs - @$(MAKE) godocs \ No newline at end of file +install-linter: + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.35.2 + +go-doc-mac: + @open http://localhost:6060 && \ + godoc -http=:6060 + +go-doc-linux: + @xdg-open http://localhost:6060 && \ + godoc -http=:6060 + +vendor-deps: + @go mod tidy && go mod vendor + +tag: ## Generate a new tag and push (tag version=0.0.0) + @run-all-tests + @git tag -a v$(version) -m "Pending full release..." + @git push origin v$(version) + @git fetch --tags -f diff --git a/block_test.go b/block_test.go index 67adca2..f3f3a61 100644 --- a/block_test.go +++ b/block_test.go @@ -5,9 +5,10 @@ import ( "errors" "testing" - "github.com/libsv/go-bc" "github.com/libsv/go-bt/v2" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestNewBlock(t *testing.T) { diff --git a/blockheader_test.go b/blockheader_test.go index d4fb1df..f1b78ed 100644 --- a/blockheader_test.go +++ b/blockheader_test.go @@ -6,8 +6,9 @@ import ( "errors" "testing" - "github.com/libsv/go-bc" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestNewBlockHeader(t *testing.T) { diff --git a/bytemanipulation_test.go b/bytemanipulation_test.go index 4e21626..b8075a3 100644 --- a/bytemanipulation_test.go +++ b/bytemanipulation_test.go @@ -4,9 +4,10 @@ import ( "encoding/hex" "testing" - "github.com/libsv/go-bc" "github.com/libsv/go-bk/crypto" "github.com/libsv/go-bt/v2" + + "github.com/libsv/go-bc" ) func TestGenesisHash(t *testing.T) { diff --git a/go.sum b/go.sum index d197069..48a63e2 100644 --- a/go.sum +++ b/go.sum @@ -8,12 +8,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/libsv/go-bk v0.0.0-20210430094342-ff08e691962b h1:NJkme7OR8Mz8emNPiG0Ix2gSBqZyQRasE1LVCp5SvhE= -github.com/libsv/go-bk v0.0.0-20210430094342-ff08e691962b/go.mod h1:xbDkeFFpP0uyFaPLnP6TwaLpAsHaslZ0LftTdWlB6HI= github.com/libsv/go-bk v0.1.4 h1:bTxlerGeibh8RRmyhFK03wSAEp6EAJxGR4vXuRT0LCE= github.com/libsv/go-bk v0.1.4/go.mod h1:xbDkeFFpP0uyFaPLnP6TwaLpAsHaslZ0LftTdWlB6HI= -github.com/libsv/go-bt/v2 v2.0.0-20210730150403-97fd3b293e05 h1:rRANK7Nc+bp0odO2zvDdHZBloGuwopGIx54yXypuR9k= -github.com/libsv/go-bt/v2 v2.0.0-20210730150403-97fd3b293e05/go.mod h1:62PATaSIMQ3omXVr9D4S7uMKaQByCJjNkrNzFpYThco= github.com/libsv/go-bt/v2 v2.0.0-beta.7 h1:ccJXfmO2i+79oP/mDYYqvqa5DH1QV+2a1eh8+HUKhic= github.com/libsv/go-bt/v2 v2.0.0-beta.7/go.mod h1:6Vk1qMlMoFJFNm7rR7NmFx4VwHNMCi4+V9WBqTd37rQ= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -25,7 +21,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/merklebranches.go b/merklebranches.go index 2500275..424d6c1 100644 --- a/merklebranches.go +++ b/merklebranches.go @@ -12,7 +12,7 @@ func getHashes(txHashes []string) []string { hashes := make([]string, 0, len(txHashes)) for i, tx := range txHashes { - hashes[i] = (ReverseHexString(tx)) + hashes[i] = ReverseHexString(tx) } return hashes diff --git a/merkleproof.go b/merkleproof.go index 6d72bf9..da14df2 100644 --- a/merkleproof.go +++ b/merkleproof.go @@ -69,17 +69,17 @@ func (mp *MerkleProof) ToBytes() ([]byte, error) { var txLength []byte if len(mp.TxOrID) > 64 { // tx bytes instead of txid // set bit at index 0 - flags |= (1 << 0) + flags |= 1 << 0 txLength = bt.VarInt(uint64(len(txOrID))) } if mp.TargetType == "header" { // set bit at index 1 - flags |= (1 << 1) + flags |= 1 << 1 } else if mp.TargetType == "merkleRoot" { // set bit at index 2 - flags |= (1 << 2) + flags |= 1 << 2 } // ignore proofType and compositeType for this version diff --git a/merkleproof_test.go b/merkleproof_test.go index ef675db..42a083e 100644 --- a/merkleproof_test.go +++ b/merkleproof_test.go @@ -4,8 +4,9 @@ import ( "encoding/hex" "testing" - "github.com/libsv/go-bc" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestMerkleProofToBytes(t *testing.T) { diff --git a/merkleroot_test.go b/merkleroot_test.go index cb3d5b0..2c9f307 100644 --- a/merkleroot_test.go +++ b/merkleroot_test.go @@ -3,8 +3,9 @@ package bc_test import ( "testing" - "github.com/libsv/go-bc" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestBuildMerkleRoot(t *testing.T) { diff --git a/merkletreeparent_test.go b/merkletreeparent_test.go index b48b117..1133528 100644 --- a/merkletreeparent_test.go +++ b/merkletreeparent_test.go @@ -4,8 +4,9 @@ import ( "encoding/hex" "testing" - "github.com/libsv/go-bc" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestGetMerkleTreeParentStr(t *testing.T) { diff --git a/spv/createenvelope_test.go b/spv/createenvelope_test.go index e72fd50..4d43ce2 100644 --- a/spv/createenvelope_test.go +++ b/spv/createenvelope_test.go @@ -6,10 +6,11 @@ import ( "fmt" "testing" - "github.com/libsv/go-bc" - "github.com/libsv/go-bc/spv" "github.com/libsv/go-bt/v2" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" + "github.com/libsv/go-bc/spv" ) type mockTxMerkleGetter struct { diff --git a/spv/creator.go b/spv/creator.go index 655a100..99e9335 100644 --- a/spv/creator.go +++ b/spv/creator.go @@ -3,9 +3,10 @@ package spv import ( "context" - "github.com/libsv/go-bc" "github.com/libsv/go-bt/v2" "github.com/pkg/errors" + + "github.com/libsv/go-bc" ) // An EnvelopeCreator is an interface used to build the spv.Envelope data type for diff --git a/spv/creator_test.go b/spv/creator_test.go index 3de33b5..31c8a56 100644 --- a/spv/creator_test.go +++ b/spv/creator_test.go @@ -3,9 +3,10 @@ package spv_test import ( "testing" - "github.com/libsv/go-bc/spv" "github.com/pkg/errors" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc/spv" ) func TestEnvelopeCreator_NewEnvelopeCreator(t *testing.T) { diff --git a/spv/envelope_test.go b/spv/envelope_test.go index 8a09ea1..8a7e70d 100644 --- a/spv/envelope_test.go +++ b/spv/envelope_test.go @@ -3,8 +3,9 @@ package spv import ( "testing" - "github.com/libsv/go-bc" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestEnvelope_IsAnchored(t *testing.T) { diff --git a/spv/verifier_test.go b/spv/verifier_test.go index bead16c..fe390d1 100644 --- a/spv/verifier_test.go +++ b/spv/verifier_test.go @@ -3,10 +3,11 @@ package spv_test import ( "testing" - "github.com/libsv/go-bc" - "github.com/libsv/go-bc/spv" "github.com/pkg/errors" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" + "github.com/libsv/go-bc/spv" ) func TestPaymentVerifier_NewPaymentVerifier(t *testing.T) { diff --git a/spv/verifymerkleproof.go b/spv/verifymerkleproof.go index 5d42e4e..db802b5 100644 --- a/spv/verifymerkleproof.go +++ b/spv/verifymerkleproof.go @@ -6,8 +6,9 @@ import ( "errors" "fmt" - "github.com/libsv/go-bc" "github.com/libsv/go-bt/v2" + + "github.com/libsv/go-bc" ) const ( diff --git a/spv/verifymerkleproof_internal_test.go b/spv/verifymerkleproof_internal_test.go index a7ff6dd..2cb0937 100644 --- a/spv/verifymerkleproof_internal_test.go +++ b/spv/verifymerkleproof_internal_test.go @@ -3,8 +3,9 @@ package spv import ( "testing" - "github.com/libsv/go-bc" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" ) func TestParseBinaryMerkleProof(t *testing.T) { diff --git a/spv/verifymerkleproof_test.go b/spv/verifymerkleproof_test.go index 382f108..20db7e2 100644 --- a/spv/verifymerkleproof_test.go +++ b/spv/verifymerkleproof_test.go @@ -4,9 +4,10 @@ import ( "context" "testing" + "github.com/stretchr/testify/assert" + "github.com/libsv/go-bc" "github.com/libsv/go-bc/spv" - "github.com/stretchr/testify/assert" ) type mockBlockHeaderChain struct{} diff --git a/spv/verifypayment_test.go b/spv/verifypayment_test.go index f052fcc..2597736 100644 --- a/spv/verifypayment_test.go +++ b/spv/verifypayment_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/libsv/go-bc" - "github.com/libsv/go-bc/spv" "github.com/libsv/go-bt/v2" "github.com/pkg/errors" "github.com/stretchr/testify/assert" + + "github.com/libsv/go-bc" + "github.com/libsv/go-bc/spv" ) type mockBlockHeaderClient struct { diff --git a/vendor/github.com/libsv/go-bt/v2/tx.go b/vendor/github.com/libsv/go-bt/v2/tx.go index 4f99f32..32d6526 100644 --- a/vendor/github.com/libsv/go-bt/v2/tx.go +++ b/vendor/github.com/libsv/go-bt/v2/tx.go @@ -415,13 +415,12 @@ func (tx *Tx) IsFeePaidEnough(fees *FeeQuote) (bool, error) { } totalInputSatoshis := tx.TotalInputSatoshis() totalOutputSatoshis := tx.TotalOutputSatoshis() - + if totalInputSatoshis < totalOutputSatoshis { return false, nil } actualFeePaid := totalInputSatoshis - totalOutputSatoshis - return actualFeePaid >= expFeesPaid.TotalFeePaid, nil }