diff --git a/Gopkg.lock b/Gopkg.lock index 991c7b811..d696c6539 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -92,6 +92,12 @@ packages = ["."] revision = "f71540b9dfdcfe64dbf2818e9b66423c6aafcacd" +[[projects]] + branch = "master" + name = "github.com/pkg/errors" + packages = ["."] + revision = "d58f94251046e7f70ac45aceea6cf6f61415ccca" + [[projects]] branch = "master" name = "golang.org/x/crypto" @@ -101,6 +107,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "5976f1edbea819ab26c66eb5e5604c255a72f174b7a47bb218f3b8a6733d0c3a" + inputs-digest = "8dc0933d88a4dda8879b373d68550cf2211ad8850c9b091d9894c5d21a92a086" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 54cc860aa..9050a0c54 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -63,6 +63,10 @@ branch = "master" name = "bou.ke/monkey" +[[constraint]] + branch = "master" + name = "github.com/pkg/errors" + [prune] go-tests = true unused-packages = true diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..fb5b8b454 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,10 @@ +node { + stage 'Checkout' + checkout scm + + stage 'Version' + sh './deploy.sh version' + + stage 'Build' + sh "./deploy.sh build" +} diff --git a/addrmgr/doc.go b/addrmgr/doc.go index 23567a3bb..8ddc8bfdf 100644 --- a/addrmgr/doc.go +++ b/addrmgr/doc.go @@ -35,4 +35,4 @@ periodically purge peers which no longer appear to be good peers as well as bias the selection toward known good peers. The general idea is to make a best effort at only providing usable addresses. */ -package addrmgr \ No newline at end of file +package addrmgr diff --git a/blockdag/blockheap.go b/blockdag/blockheap.go index 1e89f7211..4917d6390 100644 --- a/blockdag/blockheap.go +++ b/blockdag/blockheap.go @@ -44,8 +44,8 @@ func NewHeap() BlockHeap { return h } -// Pop removes the block with lowest height from this heap and returns it -func (bh BlockHeap) Pop() *blockNode { +// pop removes the block with lowest height from this heap and returns it +func (bh BlockHeap) pop() *blockNode { return heap.Pop(bh.impl).(*blockNode) } diff --git a/blockdag/blockheap_test.go b/blockdag/blockheap_test.go index f57dd435c..0f1c77d13 100644 --- a/blockdag/blockheap_test.go +++ b/blockdag/blockheap_test.go @@ -76,7 +76,7 @@ func TestBlockHeap(t *testing.T) { var poppedBlock *blockNode if test.expectedPop != nil { - poppedBlock = heap.Pop() + poppedBlock = heap.pop() } if heap.Len() != test.expectedLength { t.Errorf("unexpected heap length in test \"%s\". "+ diff --git a/blockdag/blockset_test.go b/blockdag/blockset_test.go index 90a84df3e..f91e1bdfe 100644 --- a/blockdag/blockset_test.go +++ b/blockdag/blockset_test.go @@ -23,10 +23,10 @@ func TestHashes(t *testing.T) { ) expected := []daghash.Hash{ - daghash.Hash{0}, - daghash.Hash{1}, - daghash.Hash{2}, - daghash.Hash{3}, + {0}, + {1}, + {2}, + {3}, } if !daghash.AreEqual(bs.hashes(), expected) { diff --git a/blockdag/doc.go b/blockdag/doc.go index e85188933..082918bd7 100644 --- a/blockdag/doc.go +++ b/blockdag/doc.go @@ -78,4 +78,4 @@ This package includes spec changes outlined by the following BIPs: BIP0030 (https://en.bitcoin.it/wiki/BIP_0030) BIP0034 (https://en.bitcoin.it/wiki/BIP_0034) */ -package blockdag \ No newline at end of file +package blockdag diff --git a/blockdag/example_test.go b/blockdag/example_test.go index 439155869..87490cf98 100644 --- a/blockdag/example_test.go +++ b/blockdag/example_test.go @@ -22,7 +22,7 @@ import ( // overview documentation describes, this includes all of the Bitcoin consensus // rules. This example intentionally attempts to insert a duplicate genesis // block to illustrate how an invalid block is handled. -func ExampleBlockChain_ProcessBlock() { +func ExampleBlockDAG_ProcessBlock() { // Create a new database to store the accepted blocks into. Typically // this would be opening an existing database and would not be deleting // and creating a new database like this, but it is done here so this is diff --git a/blockdag/fullblocktests/doc.go b/blockdag/fullblocktests/doc.go index 2b056ec72..bfedc43d9 100644 --- a/blockdag/fullblocktests/doc.go +++ b/blockdag/fullblocktests/doc.go @@ -17,4 +17,4 @@ This package has intentionally been designed so it can be used as a standalone package for any projects needing to test their implementation against a full set of blocks that exercise the consensus validation rules. */ -package fullblocktests \ No newline at end of file +package fullblocktests diff --git a/blockdag/phantom.go b/blockdag/phantom.go index fe22cddbc..453d90352 100644 --- a/blockdag/phantom.go +++ b/blockdag/phantom.go @@ -85,7 +85,7 @@ func traverseCandidates(newBlock *blockNode, candidates blockSet, selectedParent } for queue.Len() > 0 { - current := queue.Pop() + current := queue.pop() if candidates.contains(current) { if current == selectedParent || selectedParentPast.anyChildInSet(current) { selectedParentPast.add(current) diff --git a/blockdag/validate.go b/blockdag/validate.go index 828dadf9f..9753e476f 100644 --- a/blockdag/validate.go +++ b/blockdag/validate.go @@ -696,7 +696,7 @@ func validateParents(blockHeader *wire.BlockHeader, parents blockSet) error { } } for queue.Len() > 0 { - current := queue.Pop() + current := queue.pop() if parents.contains(current) { return fmt.Errorf("Block %s is both a parent of %s and an"+ " ancestor of another parent", diff --git a/btcd.go b/btcd.go index 668f3d09d..9ca264159 100644 --- a/btcd.go +++ b/btcd.go @@ -23,8 +23,8 @@ import ( "github.com/daglabs/btcd/logger" "github.com/daglabs/btcd/server" "github.com/daglabs/btcd/signal" - "github.com/daglabs/btcd/version" "github.com/daglabs/btcd/util/fs" + "github.com/daglabs/btcd/version" ) const ( diff --git a/btcec/doc.go b/btcec/doc.go index 4a8e2de7a..fa8346ab0 100644 --- a/btcec/doc.go +++ b/btcec/doc.go @@ -18,4 +18,4 @@ standard formats. It was designed for use with btcd, but should be general enough for other uses of elliptic curve crypto. It was originally based on some initial work by ThePiachu, but has significantly diverged since then. */ -package btcec \ No newline at end of file +package btcec diff --git a/cmd/addblock/config.go b/cmd/addblock/config.go index 19ffc58d2..3b8c9a388 100644 --- a/cmd/addblock/config.go +++ b/cmd/addblock/config.go @@ -12,8 +12,8 @@ import ( "github.com/daglabs/btcd/dagconfig" "github.com/daglabs/btcd/database" _ "github.com/daglabs/btcd/database/ffldb" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" flags "github.com/jessevdk/go-flags" ) diff --git a/cmd/addblock/import.go b/cmd/addblock/import.go index b5d4dbab2..53ed6e61e 100644 --- a/cmd/addblock/import.go +++ b/cmd/addblock/import.go @@ -14,8 +14,8 @@ import ( "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/database" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // importResults houses the stats and result as an import operation. diff --git a/cmd/btcctl/httpclient.go b/cmd/btcctl/httpclient.go index fd4f905da..687c8f5bb 100644 --- a/cmd/btcctl/httpclient.go +++ b/cmd/btcctl/httpclient.go @@ -10,8 +10,8 @@ import ( "net" "net/http" - "github.com/daglabs/btcd/btcjson" "github.com/btcsuite/go-socks/socks" + "github.com/daglabs/btcd/btcjson" ) // newHTTPClient returns a new HTTP client that is configured according to the diff --git a/cmd/findcheckpoint/config.go b/cmd/findcheckpoint/config.go index aeb00f943..42efbefe2 100644 --- a/cmd/findcheckpoint/config.go +++ b/cmd/findcheckpoint/config.go @@ -12,8 +12,8 @@ import ( "github.com/daglabs/btcd/dagconfig" "github.com/daglabs/btcd/database" _ "github.com/daglabs/btcd/database/ffldb" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" flags "github.com/jessevdk/go-flags" ) diff --git a/connmgr/doc.go b/connmgr/doc.go index c8bbe825f..acb90c31a 100644 --- a/connmgr/doc.go +++ b/connmgr/doc.go @@ -11,4 +11,4 @@ Connection Manager handles all the general connection concerns such as maintaining a set number of outbound connections, sourcing peers, banning, limiting max connections, tor lookup, etc. */ -package connmgr \ No newline at end of file +package connmgr diff --git a/dagconfig/doc.go b/dagconfig/doc.go index dfc5f3e71..fc1747dc4 100644 --- a/dagconfig/doc.go +++ b/dagconfig/doc.go @@ -58,4 +58,4 @@ // non-standard network. As a general rule of thumb, all network parameters // should be unique to the network, but parameter collisions can still occur // (unfortunately, this is the case with regtest and testnet3 sharing magics). -package dagconfig \ No newline at end of file +package dagconfig diff --git a/database/cmd/dbtool/globalconfig.go b/database/cmd/dbtool/globalconfig.go index ce6a6c6e9..3ed1a9b09 100644 --- a/database/cmd/dbtool/globalconfig.go +++ b/database/cmd/dbtool/globalconfig.go @@ -13,8 +13,8 @@ import ( "github.com/daglabs/btcd/dagconfig" "github.com/daglabs/btcd/database" _ "github.com/daglabs/btcd/database/ffldb" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) var ( diff --git a/database/cmd/dbtool/insecureimport.go b/database/cmd/dbtool/insecureimport.go index 28889daff..2a0228f96 100644 --- a/database/cmd/dbtool/insecureimport.go +++ b/database/cmd/dbtool/insecureimport.go @@ -14,8 +14,8 @@ import ( "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/database" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // importCmd defines the configuration options for the insecureimport command. diff --git a/database/doc.go b/database/doc.go index 3c307bf80..497206713 100644 --- a/database/doc.go +++ b/database/doc.go @@ -88,4 +88,4 @@ provide the ability to create an arbitrary number of nested buckets. It is a good idea to avoid a lot of buckets with little data in them as it could lead to poor page utilization depending on the specific driver in use. */ -package database \ No newline at end of file +package database diff --git a/database/ffldb/dbcache.go b/database/ffldb/dbcache.go index 23bf90d95..1abe95392 100644 --- a/database/ffldb/dbcache.go +++ b/database/ffldb/dbcache.go @@ -10,10 +10,10 @@ import ( "sync" "time" - "github.com/daglabs/btcd/database/internal/treap" "github.com/btcsuite/goleveldb/leveldb" "github.com/btcsuite/goleveldb/leveldb/iterator" "github.com/btcsuite/goleveldb/leveldb/util" + "github.com/daglabs/btcd/database/internal/treap" ) const ( diff --git a/database/ffldb/doc.go b/database/ffldb/doc.go index b3a0fd978..96a2992cb 100644 --- a/database/ffldb/doc.go +++ b/database/ffldb/doc.go @@ -26,4 +26,4 @@ database path as a string and the block network: // Handle error } */ -package ffldb \ No newline at end of file +package ffldb diff --git a/database/ffldb/ldbtreapiter.go b/database/ffldb/ldbtreapiter.go index e78628de7..e382e596b 100644 --- a/database/ffldb/ldbtreapiter.go +++ b/database/ffldb/ldbtreapiter.go @@ -5,9 +5,9 @@ package ffldb import ( - "github.com/daglabs/btcd/database/internal/treap" "github.com/btcsuite/goleveldb/leveldb/iterator" "github.com/btcsuite/goleveldb/leveldb/util" + "github.com/daglabs/btcd/database/internal/treap" ) // ldbTreapIter wraps a treap iterator to provide the additional functionality diff --git a/database/ffldb/whitebox_test.go b/database/ffldb/whitebox_test.go index 0940b7df5..6b6430f43 100644 --- a/database/ffldb/whitebox_test.go +++ b/database/ffldb/whitebox_test.go @@ -17,12 +17,12 @@ import ( "path/filepath" "testing" - "github.com/daglabs/btcd/dagconfig" - "github.com/daglabs/btcd/database" - "github.com/daglabs/btcd/wire" - "github.com/daglabs/btcd/util" "github.com/btcsuite/goleveldb/leveldb" ldberrors "github.com/btcsuite/goleveldb/leveldb/errors" + "github.com/daglabs/btcd/dagconfig" + "github.com/daglabs/btcd/database" + "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) var ( diff --git a/database/internal/treap/doc.go b/database/internal/treap/doc.go index 037a01cc0..4f46e057c 100644 --- a/database/internal/treap/doc.go +++ b/database/internal/treap/doc.go @@ -24,4 +24,4 @@ since the treap it points to is immutable. This effectively provides O(1) snapshot capability with efficient memory usage characteristics since the old nodes only remain allocated until there are no longer any references to them. */ -package treap \ No newline at end of file +package treap diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 000000000..76fd929bc --- /dev/null +++ b/deploy.sh @@ -0,0 +1,146 @@ +#!/bin/sh + +export ENVIRONMENT_NAME=${ENVIRONMENT_NAME:-"dev"} +export CF_STACK_NAME=${CF_STACK_NAME:-"${ENVIRONMENT_NAME}-ECS-BTCD"} +export SERVICE_NAME=${SERVICE_NAME:-"btcd"} +export IMAGE_TAG=${IMAGE_TAG:-"latest"} +# GIT_COMMIT is set by Jenkins +export COMMIT=${COMMIT:-$GIT_COMMIT} + +AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-eu-central-1} +export AWS_DEFAULT_REGION +AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output=text) +export AWS_ACCOUNT_ID +ECR_SERVER=${ECR_SERVER:-"$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"} +export ECR_SERVER + +CF_PARAM=TaskImage +IMAGE_NAME=${ECR_SERVER}/${SERVICE_NAME} + +trap "exit 1" INT +fatal() { echo "ERROR: $*" >&2; exit 1; } +measure_runtime() { + START=$(date +%s) + echo "--> $*" >&2 + "$@" + rc=$? + echo "--> took $(($(date +%s) - START))s" >&2 + return $rc +} + +test_git_cli() { + git --version >/dev/null || fatal 'The "git" CLI tool is not available.' +} + +test_aws_cli() { + aws --version >/dev/null || fatal 'The "aws" CLI tool is not available.' + aws sts get-caller-identity >/dev/null || fatal 'The "aws" CLI tool is not configured.' +} + +test_docker_cli() { + docker --version >/dev/null || fatal 'The "docker" CLI tool is not available.' +} + +test_docker_server() { + docker version -f 'Docker server version {{.Server.Version}}, build {{.Server.GitCommit}}' >/dev/null \ + || fatal 'The "docker" server is not available' +} + +# fix $COMMIT if executed without Jenkins +if [ -z "$COMMIT" ]; then + test_git_cli + COMMIT=$(git rev-parse --short=7 HEAD) + export COMMIT +fi + +version() { + test_git_cli + # place environment variables set by Jenkins into a metadata file + cat <<-EOF > version.txt + GIT_BRANCH=$BRANCH_NAME + GIT_COMMIT=$(git rev-parse --short=12 HEAD) + GIT_AUTHOR_EMAIL=$(git log -1 --pretty='format:%ae') + GIT_AUTHOR_NAME=$(git log -1 --pretty='format:%an') + GIT_AUTHOR_DATE=$(git log -1 --pretty='format:%aI') + EOF +} + +login() { + test_aws_cli + eval "$(aws ecr get-login --no-include-email)" +} + +build() { + login + test_docker_cli + version + measure_runtime docker build -t "${SERVICE_NAME}:${COMMIT}" . \ + -f docker/Dockerfile \ + || fatal 'Failed to build the docker image' +} + +create_ecr() { + echo "==> Checking for existance of ECR repository..." + measure_runtime aws ecr describe-repositories --query 'repositories[].repositoryName' \ + | grep -E "\"$SERVICE_NAME\"" >/dev/null \ + || { + echo "==> ECR for $SERVICE_NAME does not exist. Creating ..." + measure_runtime aws ecr create-repository --repository-name "$SERVICE_NAME" \ + || fatal 'Failed to create ECR repository' + } +} + +push() { + test_aws_cli + test_docker_cli + test_docker_server + build + measure_runtime docker tag "${SERVICE_NAME}:${COMMIT}" "${IMAGE_NAME}:${COMMIT}" || fatal 'Failed to tag docker image' + measure_runtime docker tag "${SERVICE_NAME}:${COMMIT}" "${IMAGE_NAME}:latest" || fatal 'Failed to tag docker image to :last' + create_ecr + login + measure_runtime docker push "${IMAGE_NAME}:${COMMIT}" || fatal 'Failed to push docker image to ECR' + measure_runtime docker push "${IMAGE_NAME}:latest" || fatal 'Failed to push docker image :latest to ECR' +} + +deploy() { + measure_runtime aws cloudformation \ + update-stack \ + --stack-name "$CF_STACK_NAME" \ + --capabilities CAPABILITY_NAMED_IAM \ + --use-previous-template \ + --parameters "ParameterKey=EnvironmentName,UsePreviousValue=true \ + ParameterKey=$CF_PARAM,ParameterValue=${IMAGE_NAME}:$COMMIT" \ + || fatal "Failed to update CloudFormation stack $STACK_NAME." +} + +usage() { + echo "Usage: $0 " + echo " version - create a version.txt file with some meta data" + echo " build - create docker image named $SERVICE_NAME with tag \$COMMIT" + echo " login - configure docker push credentials to use AWS ECR" + echo " push - tag image as :latest and push both :\$COMMIT and :latest to ECR" + echo " push_all - push for all AWS regions" + echo " deploy - update CloudFormation stack '$CF_STACK_NAME' with ECR image '${SERVICE_NAME}:${COMMIT}'" +} + +push_all() { + for AWS_DEFAULT_REGION in 'us-east-1' 'us-east-2'; do + export AWS_DEFAULT_REGION + ECR_SERVER="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com" + export ECR_SERVER + IMAGE_NAME=${ECR_SERVER}/${SERVICE_NAME} + export IMAGE_NAME + push + done +} + +case $1 in + version) version ;; + build) build ;; + login) login ;; + push) push ;; + push_all) push_all ;; + deploy) deploy ;; + *) usage ;; +esac diff --git a/docker/Dockerfile b/docker/Dockerfile index 3a6069c4d..81bfd7994 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -15,20 +15,22 @@ RUN go get -u github.com/golang/lint/golint \ COPY ./Gopkg.* ./ -RUN dep ensure -v --vendor-only +RUN dep ensure -v -vendor-only COPY . . -RUN gofmt -d -e -s . \ - && go tool vet -all . \ - && golint -set_exit_status . \ - && aligncheck . \ - && structcheck -e . \ - && varcheck -e . +RUN TEST_DIRS=`go list -f {{.Dir}} ./... | grep -v /vendor/` +RUN GOFMT_RESULT=`gofmt -l $TEST_DIRS`; echo $GOFMT_RESULT; test -z "$GOFMT_RESULT" +RUN go vet ./... +# RUN golint -set_exit_status $TEST_DIRS +# RUN aligncheck ./... +# RUN structcheck -e ./... +# RUN varcheck -e ./... RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o btcd . -RUN strip btcd -RUN go test ./... +# Remove the line below and uncomment the line after it for testing with coverage +RUN go test -gcflags='-l' ./... +# RUN ./test.sh # --- multistage docker build: stage #2: runtime image FROM alpine diff --git a/integration/csv_test.go b/integration/csv_test.go index a9950dac1..e1667e6a7 100644 --- a/integration/csv_test.go +++ b/integration/csv_test.go @@ -20,8 +20,8 @@ import ( "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/integration/rpctest" "github.com/daglabs/btcd/txscript" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // makeTestOutput creates an on-chain output paying to a freshly generated diff --git a/integration/rpctest/rpc_harness.go b/integration/rpctest/rpc_harness.go index e9064fca8..ef3ce7412 100644 --- a/integration/rpctest/rpc_harness.go +++ b/integration/rpctest/rpc_harness.go @@ -18,8 +18,8 @@ import ( "github.com/daglabs/btcd/dagconfig" "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/rpcclient" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) const ( diff --git a/integration/rpctest/rpc_harness_test.go b/integration/rpctest/rpc_harness_test.go index 519fed660..0031efb23 100644 --- a/integration/rpctest/rpc_harness_test.go +++ b/integration/rpctest/rpc_harness_test.go @@ -16,8 +16,8 @@ import ( "github.com/daglabs/btcd/dagconfig" "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/txscript" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) func testSendOutputs(r *Harness, t *testing.T) { diff --git a/mempool/doc.go b/mempool/doc.go index 57eb240ee..3adad018b 100644 --- a/mempool/doc.go +++ b/mempool/doc.go @@ -78,4 +78,4 @@ violations through type assertions. In addition, callers can programmatically determine the specific rule violation by type asserting the Err field to one of the aforementioned types and examining their underlying ErrorCode field. */ -package mempool \ No newline at end of file +package mempool diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 1aece3c3f..02c50430a 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -556,7 +556,7 @@ func TestProcessTransaction(t *testing.T) { nonStdSigScriptTx := util.NewTx(&wire.MsgTx{ Version: 1, - TxIn: []*wire.TxIn{&wire.TxIn{ + TxIn: []*wire.TxIn{{ PreviousOutPoint: wire.OutPoint{Hash: *p2shTx.Hash(), Index: 0}, SignatureScript: wrappedP2SHNonStdSigScript, Sequence: wire.MaxTxInSequenceNum, @@ -603,7 +603,7 @@ func TestProcessTransaction(t *testing.T) { //Checks that a transaction with no outputs will get rejected noOutsTx := util.NewTx(&wire.MsgTx{ Version: 1, - TxIn: []*wire.TxIn{&wire.TxIn{ + TxIn: []*wire.TxIn{{ PreviousOutPoint: dummyPrevOut, SignatureScript: dummySigScript, Sequence: wire.MaxTxInSequenceNum, @@ -676,7 +676,7 @@ func TestProcessTransaction(t *testing.T) { tx = util.NewTx(&wire.MsgTx{ Version: 1, - TxIn: []*wire.TxIn{&wire.TxIn{ + TxIn: []*wire.TxIn{{ PreviousOutPoint: spendableOuts[5].outPoint, SignatureScript: []byte{02, 01}, //Unparsable script Sequence: wire.MaxTxInSequenceNum, diff --git a/netsync/doc.go b/netsync/doc.go index 32a165d5a..7f45286d7 100644 --- a/netsync/doc.go +++ b/netsync/doc.go @@ -10,4 +10,4 @@ new blocks connected to the chain. Currently the sync manager selects a single sync peer that it downloads all blocks from until it is up to date with the longest chain the sync peer is aware of. */ -package netsync \ No newline at end of file +package netsync diff --git a/netsync/interface.go b/netsync/interface.go index df5ba8049..80019484a 100644 --- a/netsync/interface.go +++ b/netsync/interface.go @@ -10,8 +10,8 @@ import ( "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/mempool" "github.com/daglabs/btcd/peer" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // PeerNotifier exposes methods to notify peers of status changes to diff --git a/peer/doc.go b/peer/doc.go index 01bc2e8ed..d483faddd 100644 --- a/peer/doc.go +++ b/peer/doc.go @@ -147,4 +147,4 @@ Bitcoin Improvement Proposals This package supports all BIPS supported by the wire package. (https://godoc.org/github.com/daglabs/btcd/wire#hdr-Bitcoin_Improvement_Proposals) */ -package peer \ No newline at end of file +package peer diff --git a/rpcclient/doc.go b/rpcclient/doc.go index 8423f1658..347ad786e 100644 --- a/rpcclient/doc.go +++ b/rpcclient/doc.go @@ -175,4 +175,4 @@ The following full-blown client examples are in the examples directory: for notifications about changes to account balances, and gets a list of unspent transaction outputs (utxos) the wallet can sign */ -package rpcclient \ No newline at end of file +package rpcclient diff --git a/rpcclient/examples/btcdwebsockets/main.go b/rpcclient/examples/btcdwebsockets/main.go index e66c08606..70d867adf 100644 --- a/rpcclient/examples/btcdwebsockets/main.go +++ b/rpcclient/examples/btcdwebsockets/main.go @@ -11,8 +11,8 @@ import ( "time" "github.com/daglabs/btcd/rpcclient" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) func main() { diff --git a/rpcclient/extensions.go b/rpcclient/extensions.go index 537fc27f4..4bf8cb965 100644 --- a/rpcclient/extensions.go +++ b/rpcclient/extensions.go @@ -14,8 +14,8 @@ import ( "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/dagconfig/daghash" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // FutureDebugLevelResult is a future promise to deliver the result of a diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 4ee96b8bd..951e0c239 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -23,9 +23,9 @@ import ( "sync/atomic" "time" - "github.com/daglabs/btcd/btcjson" "github.com/btcsuite/go-socks/socks" "github.com/btcsuite/websocket" + "github.com/daglabs/btcd/btcjson" ) var ( diff --git a/rpcclient/notify.go b/rpcclient/notify.go index 7d3d4a810..a606e25a0 100644 --- a/rpcclient/notify.go +++ b/rpcclient/notify.go @@ -15,8 +15,8 @@ import ( "github.com/daglabs/btcd/btcjson" "github.com/daglabs/btcd/dagconfig/daghash" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) var ( diff --git a/server/rpc/rpcserver.go b/server/rpc/rpcserver.go index 080665fa5..8907d9633 100644 --- a/server/rpc/rpcserver.go +++ b/server/rpc/rpcserver.go @@ -4214,7 +4214,7 @@ func NewRPCServer( gbtWorkState: newGbtWorkState(cfg.TimeSource), helpCacher: newHelpCacher(), requestProcessShutdown: make(chan struct{}), - quit: make(chan int), + quit: make(chan int), } if config.MainConfig().RPCUser != "" && config.MainConfig().RPCPass != "" { login := config.MainConfig().RPCUser + ":" + config.MainConfig().RPCPass diff --git a/service_windows.go b/service_windows.go index 8fba132e1..581e15743 100644 --- a/service_windows.go +++ b/service_windows.go @@ -13,10 +13,10 @@ import ( "github.com/btcsuite/winsvc/eventlog" "github.com/btcsuite/winsvc/mgr" "github.com/btcsuite/winsvc/svc" - "github.com/daglabs/btcd/signal" "github.com/daglabs/btcd/config" - "github.com/daglabs/btcd/version" "github.com/daglabs/btcd/server" + "github.com/daglabs/btcd/signal" + "github.com/daglabs/btcd/version" ) const ( diff --git a/test.sh b/test.sh new file mode 100755 index 000000000..706f66609 --- /dev/null +++ b/test.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +export COVERAGE_PATH="./coverage.txt" +export COVERAGE_TEMP_PATH="./coverage.tmp" + +# Remove the old coverage file if exists +rm -f ${COVERAGE_PATH} + +# Create a new coverage file +echo 'mode: atomic' > ${COVERAGE_PATH} + +# Test each package (excluding vendor packages) separately +# Function inlining messes with monkey patching so we disable it by passing -gcflags='-l' +# Running tests with -covermode=atomic saves us from race conditions unique to the testing environment +# We write coverage for every package to a temporary file so that we may append it to one global coverage file +go list ./... | \ + grep -v "vendor" | \ + xargs -n1 -I{} sh -c "go test -gcflags='-l' -timeout 20s -covermode=atomic -coverprofile=${COVERAGE_TEMP_PATH} {} && tail -n +2 ${COVERAGE_TEMP_PATH} >> ${COVERAGE_PATH}" | \ + tee /tmp/test + +# Remove the temporary coverage file +rm -f ${COVERAGE_TEMP_PATH} + +# Succeed only if everything is 100% covered +grep "ok .* 100.0% of statements" -v /tmp/test > /tmp/test2 || true +if [ -s /tmp/test2 ] +then + echo " >> tests failed or not 100% coverage" + exit 1 +else + echo " >> tests completed successfully" + exit 0 +fi diff --git a/txscript/doc.go b/txscript/doc.go index 1bf3c7c7c..7da521615 100644 --- a/txscript/doc.go +++ b/txscript/doc.go @@ -39,4 +39,4 @@ error messages with contextual information. A convenience function named IsErrorCode is also provided to allow callers to easily check for a specific error code. See ErrorCode in the package documentation for a full list. */ -package txscript \ No newline at end of file +package txscript diff --git a/util/base58/base58_test.go b/util/base58/base58_test.go index e69f645eb..2291f247a 100644 --- a/util/base58/base58_test.go +++ b/util/base58/base58_test.go @@ -7,8 +7,8 @@ package base58_test import ( "bytes" "encoding/hex" - "testing" "github.com/daglabs/btcd/util/base58" + "testing" ) var stringTests = []struct { diff --git a/util/base58/base58bench_test.go b/util/base58/base58bench_test.go index 3e9b4339e..9f28bd7a1 100644 --- a/util/base58/base58bench_test.go +++ b/util/base58/base58bench_test.go @@ -6,8 +6,8 @@ package base58_test import ( "bytes" - "testing" "github.com/daglabs/btcd/util/base58" + "testing" ) func BenchmarkBase58Encode(b *testing.B) { diff --git a/util/base58/base58check_test.go b/util/base58/base58check_test.go index ea04ea7d9..caf08c311 100644 --- a/util/base58/base58check_test.go +++ b/util/base58/base58check_test.go @@ -5,8 +5,8 @@ package base58_test import ( - "testing" "github.com/daglabs/btcd/util/base58" + "testing" ) var checkEncodingStringTests = []struct { diff --git a/util/base58/doc.go b/util/base58/doc.go index 6ce99eb27..9a2c0e6e3 100644 --- a/util/base58/doc.go +++ b/util/base58/doc.go @@ -26,4 +26,4 @@ used to differentiate the same payload. For Bitcoin addresses, the extra version is used to differentiate the network of otherwise identical public keys which helps prevent using an address intended for one network on another. */ -package base58 \ No newline at end of file +package base58 diff --git a/util/bech32/bech32_test.go b/util/bech32/bech32_test.go index 867b8e6ce..a15ff223f 100644 --- a/util/bech32/bech32_test.go +++ b/util/bech32/bech32_test.go @@ -5,8 +5,8 @@ package bech32_test import ( - "testing" "github.com/daglabs/btcd/util/bech32" + "testing" ) var checkEncodingStringTests = []struct { diff --git a/util/bech32/doc.go b/util/bech32/doc.go index 7feec5cb4..5807e0983 100644 --- a/util/bech32/doc.go +++ b/util/bech32/doc.go @@ -11,4 +11,4 @@ separator :, then a checksummed data part encoded using the 32 characters More info: https://github.com/daglabs/spec/blob/master/dagcoin.pdf */ -package bech32 \ No newline at end of file +package bech32 diff --git a/util/bech32/internal_test.go b/util/bech32/internal_test.go index e105ffbf8..007b7ac9d 100644 --- a/util/bech32/internal_test.go +++ b/util/bech32/internal_test.go @@ -1,8 +1,8 @@ package bech32 import ( - "testing" "strings" + "testing" ) func TestBech32(t *testing.T) { @@ -20,13 +20,13 @@ func TestBech32(t *testing.T) { {"abcdef:qpzry9x8gf2tvdw0s3jn54khce6mua7:nw2t26kg", true}, {"::qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq40ku0e3z", true}, {"split:checkupstagehandshakeupstreamerranterredcaperred3za27wc5", true}, - {"aaa:bbb", false}, // too short - {"split:checkupstagehandshakeupstreamerranterredCaperred3za27wc5", false}, // mixed uppercase and lowercase - {"split:checkupstagehandshakeupstreamerranterredcaperred3za28wc5", false}, // invalid checksum - {"s lit:checkupstagehandshakeupstreamerranterredcaperred3za27wc5", false}, // invalid character (space) in prefix - {"spl" + string(127) + "t:checkupstagehandshakeupstreamerranterredcaperred3za27wc5", false}, // invalid character (DEL) in prefix - {"split:cheosgds2s3c", false}, // invalid character (o) in data part - {"split:te5peu7", false}, // too short data part + {"aaa:bbb", false}, // too short + {"split:checkupstagehandshakeupstreamerranterredCaperred3za27wc5", false}, // mixed uppercase and lowercase + {"split:checkupstagehandshakeupstreamerranterredcaperred3za28wc5", false}, // invalid checksum + {"s lit:checkupstagehandshakeupstreamerranterredcaperred3za27wc5", false}, // invalid character (space) in prefix + {"spl" + string(127) + "t:checkupstagehandshakeupstreamerranterredcaperred3za27wc5", false}, // invalid character (DEL) in prefix + {"split:cheosgds2s3c", false}, // invalid character (o) in data part + {"split:te5peu7", false}, // too short data part {":checkupstagehandshakeupstreamerranterredcaperred3za27wc5", false}, // empty prefix {"::qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq40ku0e3z", false}, // too long {"bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2", true}, diff --git a/util/bloom/example_test.go b/util/bloom/example_test.go index aa0825758..a48225601 100644 --- a/util/bloom/example_test.go +++ b/util/bloom/example_test.go @@ -9,9 +9,9 @@ import ( "math/rand" "time" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/util/bloom" + "github.com/daglabs/btcd/wire" ) // This example demonstrates how to create a new bloom filter, add a transaction diff --git a/util/bloom/filter.go b/util/bloom/filter.go index 3da709871..70d740f13 100644 --- a/util/bloom/filter.go +++ b/util/bloom/filter.go @@ -9,10 +9,10 @@ import ( "math" "sync" - "github.com/daglabs/btcd/txscript" - "github.com/daglabs/btcd/wire" - "github.com/daglabs/btcd/util" "github.com/daglabs/btcd/dagconfig/daghash" + "github.com/daglabs/btcd/txscript" + "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // ln2Squared is simply the square of the natural log of 2. diff --git a/util/bloom/merkleblock.go b/util/bloom/merkleblock.go index 98aeebdbf..7324ef06f 100644 --- a/util/bloom/merkleblock.go +++ b/util/bloom/merkleblock.go @@ -7,8 +7,8 @@ package bloom import ( "github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/dagconfig/daghash" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // merkleBlock is used to house intermediate information needed to generate a diff --git a/util/bloom/murmurhash3_test.go b/util/bloom/murmurhash3_test.go index 0df98f8a5..bfaef5fc7 100644 --- a/util/bloom/murmurhash3_test.go +++ b/util/bloom/murmurhash3_test.go @@ -5,8 +5,8 @@ package bloom_test import ( - "testing" "github.com/daglabs/btcd/util/bloom" + "testing" ) // TestMurmurHash3 ensure the MurmurHash3 function produces the correct hash diff --git a/util/btcmath.go b/util/btcmath.go index 04602dc0f..c5a6a98cb 100644 --- a/util/btcmath.go +++ b/util/btcmath.go @@ -17,4 +17,4 @@ func FastLog2Floor(n uint32) uint8 { exponent >>= 1 } return rv -} \ No newline at end of file +} diff --git a/util/certgen.go b/util/certgen.go index 3ffee65a4..6643aa0a5 100644 --- a/util/certgen.go +++ b/util/certgen.go @@ -110,7 +110,7 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, - IsCA: true, // so can sign self. + IsCA: true, // so can sign self. BasicConstraintsValid: true, DNSNames: dnsNames, diff --git a/util/coinset/coins.go b/util/coinset/coins.go index b760dd4cc..16b7b18f9 100644 --- a/util/coinset/coins.go +++ b/util/coinset/coins.go @@ -10,8 +10,8 @@ import ( "sort" "github.com/daglabs/btcd/dagconfig/daghash" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" + "github.com/daglabs/btcd/wire" ) // Coin represents a spendable transaction outpoint diff --git a/util/coinset/coins_test.go b/util/coinset/coins_test.go index c4cfe7cf6..e3b50dcec 100644 --- a/util/coinset/coins_test.go +++ b/util/coinset/coins_test.go @@ -12,9 +12,9 @@ import ( "testing" "github.com/daglabs/btcd/dagconfig/daghash" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util" "github.com/daglabs/btcd/util/coinset" + "github.com/daglabs/btcd/wire" ) type TestCoin struct { diff --git a/util/doc.go b/util/doc.go index 68a6f1742..1355929b7 100644 --- a/util/doc.go +++ b/util/doc.go @@ -43,4 +43,4 @@ To decode/encode an address: } fmt.Println(addr.EncodeAddress()) */ -package util \ No newline at end of file +package util diff --git a/util/gcs/builder/builder.go b/util/gcs/builder/builder.go index 2a8564af0..398c520cd 100644 --- a/util/gcs/builder/builder.go +++ b/util/gcs/builder/builder.go @@ -9,10 +9,10 @@ import ( "crypto/rand" "encoding/binary" - "github.com/daglabs/btcd/txscript" - "github.com/daglabs/btcd/wire" - "github.com/daglabs/btcd/util/gcs" "github.com/daglabs/btcd/dagconfig/daghash" + "github.com/daglabs/btcd/txscript" + "github.com/daglabs/btcd/util/gcs" + "github.com/daglabs/btcd/wire" ) // DefaultP is the default collision probability (2^-20) diff --git a/util/gcs/doc.go b/util/gcs/doc.go index f8a9d98d0..780fd7663 100644 --- a/util/gcs/doc.go +++ b/util/gcs/doc.go @@ -21,4 +21,4 @@ a full node would send an SPV node the GCS filter for a block, which the SPV node would check against its list of relevant items. The suggested collision probability for Bitcoin use is 2^-20. */ -package gcs \ No newline at end of file +package gcs diff --git a/util/gcs/gcs_test.go b/util/gcs/gcs_test.go index 35aef2e99..fc1613618 100644 --- a/util/gcs/gcs_test.go +++ b/util/gcs/gcs_test.go @@ -8,9 +8,9 @@ package gcs_test import ( "bytes" "encoding/binary" + "github.com/daglabs/btcd/util/gcs" "math/rand" "testing" - "github.com/daglabs/btcd/util/gcs" ) var ( diff --git a/util/gcs/gcsbench_test.go b/util/gcs/gcsbench_test.go index 55997b1b7..930e2c29e 100644 --- a/util/gcs/gcsbench_test.go +++ b/util/gcs/gcsbench_test.go @@ -7,9 +7,9 @@ package gcs_test import ( "encoding/binary" + "github.com/daglabs/btcd/util/gcs" "math/rand" "testing" - "github.com/daglabs/btcd/util/gcs" ) func genRandFilterElements(numElements uint) ([][]byte, error) { diff --git a/util/hdkeychain/bench_test.go b/util/hdkeychain/bench_test.go index a2b989e05..6b6d525a5 100644 --- a/util/hdkeychain/bench_test.go +++ b/util/hdkeychain/bench_test.go @@ -5,8 +5,8 @@ package hdkeychain_test import ( - "testing" "github.com/daglabs/btcd/util/hdkeychain" + "testing" ) // bip0032MasterPriv1 is the master private extended key from the first set of diff --git a/util/hdkeychain/doc.go b/util/hdkeychain/doc.go index 191eea0e4..652eb8ca0 100644 --- a/util/hdkeychain/doc.go +++ b/util/hdkeychain/doc.go @@ -81,4 +81,4 @@ bytes which tie them to a specific network. The SetNet and IsForNet functions are provided to set and determinine which network an extended key is associated with. */ -package hdkeychain \ No newline at end of file +package hdkeychain diff --git a/util/hdkeychain/extendedkey.go b/util/hdkeychain/extendedkey.go index ded5a4e33..19615afd2 100644 --- a/util/hdkeychain/extendedkey.go +++ b/util/hdkeychain/extendedkey.go @@ -634,4 +634,4 @@ func init() { RegisterHDKeyIDPair(HDKeyPairTestNet) RegisterHDKeyIDPair(HDKeyPairRegressionNet) RegisterHDKeyIDPair(HDKeyPairSimNet) -} \ No newline at end of file +} diff --git a/util/txsort/doc.go b/util/txsort/doc.go index a1a92fe82..e89c4d23d 100644 --- a/util/txsort/doc.go +++ b/util/txsort/doc.go @@ -17,4 +17,4 @@ then on the index as a tie breaker. The order for outputs is defined as first sorting on the amount and then on the raw public key script bytes as a tie breaker. */ -package txsort \ No newline at end of file +package txsort diff --git a/util/txsort/txsort_test.go b/util/txsort/txsort_test.go index 6795c89db..fcc5a230b 100644 --- a/util/txsort/txsort_test.go +++ b/util/txsort/txsort_test.go @@ -11,8 +11,8 @@ import ( "path/filepath" "testing" - "github.com/daglabs/btcd/wire" "github.com/daglabs/btcd/util/txsort" + "github.com/daglabs/btcd/wire" ) // TestSort ensures the transaction sorting works according to the BIP. diff --git a/wire/doc.go b/wire/doc.go index 73ba5c7ed..b8b8c56ff 100644 --- a/wire/doc.go +++ b/wire/doc.go @@ -159,4 +159,4 @@ This package includes spec changes outlined by the following BIPs: BIP0130 (https://github.com/bitcoin/bips/blob/master/bip-0130.mediawiki) BIP0133 (https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki) */ -package wire \ No newline at end of file +package wire