Commit 217f2cae authored by madengji's avatar madengji

plugin add ci

parent 223d3d25
#image: chain33-build:latest
before_script:
- export GO_PROJECT_NAMESPACE="$GOPATH/src/gitlab.33.cn/$CI_PROJECT_NAMESPACE"
- echo $GO_PROJECT_NAMESPACE
- mkdir -p $GO_PROJECT_NAMESPACE
- ln -srf $(pwd) $GO_PROJECT_NAMESPACE
- export GO_PROJECT_PATH="$GO_PROJECT_NAMESPACE/$CI_PROJECT_NAME"
- echo $GO_PROJECT_PATH
- cd $GO_PROJECT_PATH
- make clean
after_script:
- make clean
stages:
- build
- test
- deploy
- fork_test
- autotest
go_fmt:
stage: build
tags:
- 33cn
script:
- make checkgofmt
- make fmt
only:
- master
- bty_develop
go_lint:
stage: build
tags:
- 33cn
script:
- make linter
only:
- master
- bty_develop
go_test:
stage: test
tags:
- 33cn
script:
- make docker-compose-down DAPP=all
- make test
only:
- master
- bty_develop
#memory_sanitizer:
# stage: test
# script:
# - export CC=clang-5.0 && make msan
# only:
# - master
# - develop
# - bty_develop
code_coverage:
stage: test
script:
- make coverage
only:
- master
- bty_develop
#code_coverage_report:
# stage: test
# script:
# - make coverhtml
# only:
# - master
# - develop
# - bty_develop
deploy:
stage: deploy
tags:
- 33cn
script:
- make build_ci
- make docker-compose
- make docker-compose-down
only:
- master
- bty_develop
deploy_relay:
stage: deploy
tags:
- 33cn
script:
- make build_ci
- make docker-compose PROJ=relay DAPP=relay
- make docker-compose-down PROJ=relay DAPP=relay
only:
- master
deploy_paracross:
stage: deploy
tags:
- 33cn
script:
- make build_ci
- make docker-compose PROJ=paracross DAPP=paracross
- make docker-compose-down PROJ=paracross DAPP=paracross
only:
- master
fork_test:
stage: fork_test
tags:
- 33cn
script:
- if [ -n "${onceEveryday}" ]; then
- make build_ci
- make fork-test
- make docker-compose-down
- fi
only:
- master
- forkTest
fork_test_privacy:
stage: fork_test
tags:
- 33cn
script:
- if [ -n "${onceEveryday}" ]; then
- make build_ci
- make fork-test PROJ=privacy DAPP=privacy
- make docker-compose-down PROJ=privacy DAPP=privacy
- fi
only:
- master
- forkTest
fork_test_paracross:
stage: fork_test
tags:
- 33cn
script:
- if [ -n "${onceEveryday}" ]; then
- make build_ci
- make fork-test PROJ=paracross DAPP=paracross
- make docker-compose-down PROJ=paracross DAPP=paracross
- fi
only:
- master
- forkTest
##serial run all dapp
fork_test_all:
stage: fork_test
tags:
- 33cn
script:
- if [ -n "${onceEveryday}" ]; then
- make build_ci
- make fork-test PROJ=fork DAPP=all
- make docker-compose-down PROJ=fork DAPP=all
- fi
only:
- master
- forkTest
##serial run all dapp
deploy_test_all:
stage: fork_test
tags:
- 33cn
script:
- if [ -n "${onceEveryday}" ]; then
- make build_ci
- make docker-compose PROJ=deploy DAPP=all
- make docker-compose-down PROJ=deploy DAPP=all
- fi
only:
- master
- forkTest
autotest:
stage: autotest
tags:
- 33cn
script:
- if [ -n "${onceEveryday}" ]; then
- make build_ci
- make autotest
- cd build/tools/autotest && ./run-autotest.sh build
- cd $GO_PROJECT_PATH
- fi
when: always
only:
- master
// ci server: http://39.98.41.13:8080
// user/pass: jenkins/33fuzamei123
pipeline {
agent any
environment {
GOPATH = "${WORKSPACE}"
PROJ_DIR = "${WORKSPACE}/src/gitlab.33.cn/chain33/chain33"
}
options {
timeout(time: 2,unit: 'HOURS')
retry(1)
timestamps()
gitLabConnection('gitlab33')
gitlabBuilds(builds: ['check', 'build', 'test', 'deploy'])
checkoutToSubdirectory "src/gitlab.33.cn/chain33/chain33"
}
stages {
stage('check') {
steps {
dir("${PROJ_DIR}"){
gitlabCommitStatus(name: 'check'){
sh "make auto_ci branch=${env.gitlabSourceBranch}"
}
}
}
}
stage('build') {
steps {
dir("${env.PROJ_DIR}"){
gitlabCommitStatus(name: 'build'){
sh 'make checkgofmt'
sh 'make linter'
}
}
}
}
stage('test'){
agent {
docker{
image 'suyanlong/chain33-run:latest'
}
}
environment {
GOPATH = "${WORKSPACE}"
PROJ_DIR = "${WORKSPACE}/src/gitlab.33.cn/chain33/chain33"
}
steps {
dir("${env.PROJ_DIR}"){
gitlabCommitStatus(name: 'test'){
sh 'make test'
//sh 'export CC=clang-5.0 && make msan'
}
}
}
}
stage('deploy') {
steps {
dir("${PROJ_DIR}"){
gitlabCommitStatus(name: 'deploy'){
sh 'make build_ci'
sh "cd build && mkdir ${env.BUILD_NUMBER} && cp ci/* ${env.BUILD_NUMBER} -r && cp chain33* Dockerfile* docker* *.sh ${env.BUILD_NUMBER}/ && cd ${env.BUILD_NUMBER}/ && ./docker-compose-pre.sh run ${env.BUILD_NUMBER} all "
}
}
}
post {
always {
dir("${PROJ_DIR}"){
sh "cd build/${env.BUILD_NUMBER} && ./docker-compose-pre.sh down ${env.BUILD_NUMBER} all && cd .. && rm -rf ${env.BUILD_NUMBER} && cd .. && make clean "
}
}
}
}
}
post {
always {
echo 'One way or another, I have finished'
// clean up our workspace
deleteDir()
}
success {
echo 'I succeeeded!'
echo "email user: ${gitlabUserEmail}"
mail to: "${gitlabUserEmail}",
subject: "Successed Pipeline: ${currentBuild.fullDisplayName}",
body: "this is success with ${env.BUILD_URL}"
}
failure {
echo 'I failed '
echo "email user: ${gitlabUserEmail}"
mail to: "${gitlabUserEmail}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}"
}
}
}
# golang1.9 or latest
# 1. make help
# 2. make dep
# 3. make build
# ...
CLI := build/chain33-cli
SRC_CLI := gitlab.33.cn/chain33/plugin/cli
APP := build/chain33
CHAIN33=gitlab.33.cn/chain33/chain33 CHAIN33=gitlab.33.cn/chain33/chain33
CHAIN33_PATH=vendor/gitlab.33.cn/chain33/chain33
AUTO_TEST := build/tools/autotest/autotest
SRC_AUTO_TEST := gitlab.33.cn/chain33/chain/cmd/autotest
LDFLAGS := -ldflags "-w -s"
PKG_LIST := `go list ./... | grep -v "vendor" | grep -v "chain33/test" | grep -v "mocks" | grep -v "pbft"`
PKG_LIST_Q := `go list ./... | grep -v "vendor" | grep -v "chain33/test" | grep -v "mocks" | grep -v "blockchain" | grep -v "pbft"`
BUILD_FLAGS = -ldflags "-X gitlab.33.cn/chain33/chain33/common/version.GitCommit=`git rev-parse --short=8 HEAD`"
MKPATH=$(abspath $(lastword $(MAKEFILE_LIST))) MKPATH=$(abspath $(lastword $(MAKEFILE_LIST)))
MKDIR=$(dir $(MKPATH)) MKDIR=$(dir $(MKPATH))
PKG_LIST := `go list ./... | grep -v "vendor" | grep -v "chain33/test" | grep -v "mocks" | grep -v "pbft"` DAPP := ""
PROJ := "build"
.PHONY: default dep all build release cli linter race test fmt vet bench msan coverage coverhtml docker docker-compose protobuf clean help autotest
default: build depends
all: build build:
@go build $(BUILD_FLAGS) -v -i -o $(APP)
@go build -v -i -o $(CLI) $(SRC_CLI)
@cp chain33.toml build/
build:vendor build_ci: depends ## Build the binary file for CI
go build -i -o chain33 @go build -v -i -o $(CLI) $(SRC_CLI)
go build -i -o chain33-cli gitlab.33.cn/chain33/plugin/cli @go build $(BUILD_FLAGS) -v -o $(APP)
@cp chain33.toml build/
para:
@go build -v -o build/$(NAME) -ldflags "-X $(SRC_CLI)/buildflags.ParaName=user.p.$(NAME). -X $(SRC_CLI)/buildflags.RPCAddr=http://localhost:8901" $(SRC_CLI)
autotest:## build autotest binary
@go build -v -i -o $(AUTO_TEST) $(SRC_AUTO_TEST)
@cp cmd/autotest/*.toml build/tools/autotest/
@if [ -n "$(dapp)" ]; then \
cd build/tools/autotest && bash ./local-autotest.sh $(dapp) && cd ../../../; \
fi
update: update:
rm -rf vendor/${CHAIN33} rm -rf ${CHAIN33_PATH}
git clone --depth 1 -b master https://${CHAIN33}.git vendor/${CHAIN33} git clone --depth 1 -b master https://${CHAIN33}.git ${CHAIN33_PATH}
rm -rf vendor/${CHAIN33}/.git rm -rf vendor/${CHAIN33}/.git
cp -R vendor/${CHAIN33}/vendor/* vendor/ cp -R vendor/${CHAIN33}/vendor/* vendor/
rm -rf vendor/${CHAIN33}/vendor rm -rf vendor/${CHAIN33}/vendor
...@@ -26,16 +62,169 @@ updatevendor: ...@@ -26,16 +62,169 @@ updatevendor:
dep: dep:
dep init -v dep init -v
clean:
@rm -rf chain33 linter: ## Use gometalinter check code, ignore some unserious warning
@rm -rf chain33-cli @res=$$(gometalinter.v2 -t --sort=linter --enable-gc --deadline=2m --disable-all \
@rm -rf tool --enable=gofmt \
@rm -rf plugin/init.go --enable=gosimple \
@rm -rf plugin/consensus/init --enable=deadcode \
@rm -rf plugin/dapp/init --enable=unconvert \
@rm -rf plugin/crypto/init --enable=interfacer \
@rm -rf plugin/store/init --enable=varcheck \
--enable=structcheck \
--enable=goimports \
--vendor ./...) \
# --enable=vet \
# --enable=staticcheck \
# --enable=gocyclo \
# --enable=staticcheck \
# --enable=golint \
# --enable=unused \
# --enable=gotype \
# --enable=gotypex \
if [ -n "$$res" ]; then \
echo "$${res}"; \
exit 1; \
fi;
@find . -name '*.sh' -not -path "./vendor/*" | xargs shellcheck
race: ## Run data race detector
@go test -race -short $(PKG_LIST)
test: ## Run unittests test: ## Run unittests
@go test -race $(PKG_LIST) @go test -race $(PKG_LIST)
fmt: fmt_proto fmt_shell ## go fmt
@go fmt ./...
@find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w
.PHONY: fmt_proto fmt_shell
fmt_proto: ## go fmt protobuf file
@find . -name '*.proto' -not -path "./vendor/*" | xargs clang-format -i
fmt_shell: ## check shell file
@find . -name '*.sh' -not -path "./vendor/*" | xargs shfmt -w -s -i 4 -ci -bn
coverage: ## Generate global code coverage report
@./build/tools/coverage.sh;
coverhtml: ## Generate global code coverage report in HTML
@./build/tools/coverage.sh html;
docker: ## build docker image for chain33 run
@sudo docker build . -f ./build/Dockerfile-run -t chain33:latest
docker-compose: ## build docker-compose for chain33 run
@cd build && if ! [ -d ci ]; then \
make -C ../ ; \
fi; \
cp chain33* Dockerfile docker-compose* ci/ && cd ci/ && ./docker-compose-pre.sh run $(PROJ) $(DAPP) && cd ../..
docker-compose-down: ## build docker-compose for chain33 run
@cd build && if [ -d ci ]; then \
cp chain33* Dockerfile docker-compose* ci/ && cd ci/ && ./docker-compose-pre.sh down $(PROJ) $(DAPP) && cd .. ; \
fi; \
cd ..
fork-test: ## build fork-test for chain33 run
@cd build && cp chain33* Dockerfile system-fork-test.sh docker-compose* ci/ && cd ci/ && ./docker-compose-pre.sh forktest $(PROJ) $(DAPP) && cd ../..
clean: ## Remove previous build
@rm -rf $(shell find . -name 'datadir' -not -path "./vendor/*")
@rm -rf build/chain33*
@rm -rf build/relayd*
@rm -rf build/*.log
@rm -rf build/logs
@rm -rf build/tools/autotest/autotest
@rm -rf build/ci
@rm -rf tool
@go clean
proto:protobuf
protobuf: ## Generate protbuf file of types package
# @cd ${CHAIN33_PATH}/types/proto && ./create_protobuf.sh && cd ../..
@find ./plugin/dapp -maxdepth 2 -type d -name proto -exec make -C {} \;
depends: ## Generate depends file of types package
@find ./plugin/dapp -maxdepth 2 -type d -name cmd -exec make -C {} OUT="$(MKDIR)build/ci" FLAG= \;
@find ./vendor/gitlab.33.cn/chain33/chain33/system/dapp -maxdepth 2 -type d -name cmd -exec make -C {} OUT="$(MKDIR)build/ci" FLAG= \;
help: ## Display this help screen
@printf "Help doc:\nUsage: make [command]\n"
@printf "[command]\n"
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
cleandata:
rm -rf build/datadir/addrbook
rm -rf build/datadir/blockchain.db
rm -rf build/datadir/mavltree
rm -rf build/chain33.log
.PHONY: checkgofmt
checkgofmt: ## get all go files and run go fmt on them
@files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -l -s); if [ -n "$$files" ]; then \
echo "Error: 'make fmt' needs to be run on:"; \
echo "${files}"; \
exit 1; \
fi;
@files=$$(find . -name '*.go' -not -path "./vendor/*" | xargs goimports -l -w); if [ -n "$$files" ]; then \
echo "Error: 'make fmt' needs to be run on:"; \
echo "${files}"; \
exit 1; \
fi;
.PHONY: mock
mock:
@cd client && mockery -name=QueueProtocolAPI && mv mocks/QueueProtocolAPI.go mocks/api.go && cd -
@cd queue && mockery -name=Client && mv mocks/Client.go mocks/client.go && cd -
@cd common/db && mockery -name=KV && mv mocks/KV.go mocks/kv.go && cd -
@cd common/db && mockery -name=KVDB && mv mocks/KVDB.go mocks/kvdb.go && cd -
@cd types/ && mockery -name=Chain33Client && mv mocks/Chain33Client.go mocks/chain33client.go && cd -
.PHONY: auto_ci_before auto_ci_after auto_ci
auto_ci_before: clean fmt protobuf mock
@echo "auto_ci"
@go version
@protoc --version
@mockery -version
@docker version
@docker-compose version
@git version
@git status
.PHONY: auto_ci_after
auto_ci_after: clean fmt protobuf mock
@git add *.go *.sh *.proto
@git status
@files=$$(git status -suno);if [ -n "$$files" ]; then \
git add *.go *.sh *.proto; \
git status; \
git commit -m "auto ci [ci-skip]"; \
git push origin HEAD:$(branch); \
fi;
.PHONY: auto_ci
auto_fmt := find . -name '*.go' -not -path './vendor/*' | xargs goimports -l -w
auto_ci: clean fmt_proto fmt_shell protobuf mock
@-find . -name '*.go' -not -path './vendor/*' | xargs gofmt -l -w -s
@-${auto_fmt}
@-find . -name '*.go' -not -path './vendor/*' | xargs gofmt -l -w -s
@${auto_fmt}
@git add *.go *.sh *.proto
@git status
@files=$$(git status -suno);if [ -n "$$files" ]; then \
git add *.go *.sh *.proto; \
git status; \
git commit -m "auto ci"; \
git push origin HEAD:$(branch); \
exit 1; \
fi;
FROM ubuntu:16.04
WORKDIR /root
COPY chain33 chain33
COPY chain33-cli chain33-cli
COPY chain33.toml ./
CMD ["/root/chain33", "-f", "/root/chain33.toml"]
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
export COMPOSE_PROJECT_NAME="$1"
DAPP=""
if [ -n "${2}" ]; then
DAPP=$2
fi
if [ -n "${DAPP}" ]; then
DAPP_COMPOSE_FILE="docker-compose-${DAPP}.yml"
if [ -e "$DAPP_COMPOSE_FILE" ]; then
export COMPOSE_FILE="docker-compose.yml:${DAPP_COMPOSE_FILE}"
fi
fi
echo "=========== # down docker-compose ============="
echo "=========== # env setting ============="
echo "DAPP=$DAPP"
echo "COMPOSE_FILE=$COMPOSE_FILE"
echo "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME"
####################
function down() {
echo "=========== # docker-compose ps ============="
docker-compose ps
# shellchk not recommend the first way
# remains=( $(docker-compose ps -q | awk '{print $1}') )
mapfile -t remains < <(docker-compose ps -q | awk '{print $1}')
num=${#remains[@]}
echo "container num=$num"
if [ "$num" -gt 0 ]; then
# remove exsit container
echo "=========== # docker-compose down ============="
docker-compose down --rmi local
fi
}
# run script
down
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
sedfix=""
if [ "$(uname)" == "Darwin" ]; then
sedfix=".bak"
fi
OP="${1}"
PROJ="${2}"
DAPP="${3}"
TESTCASEFILE="testcase.sh"
FORKTESTFILE="fork-test.sh"
DOCKER_COMPOSE_SH="docker-compose.sh"
function down_dapp() {
app=$1
if [ -d "${app}" ] && [ "${app}" != "system" ] && [ -d "${app}-ci" ]; then
cd "${app}"-ci/ && pwd
echo "============ down dapp=$app start ================="
./docker-compose-down.sh "${PROJ}" "${app}"
echo "============ down dapp=$app end ================="
cd .. && rm -rf ./"${app}"-ci
fi
}
function run_dapp() {
app=$1
test=$2
echo "============ run dapp=$app start ================="
rm -rf "${app}"-ci && mkdir -p "${app}"-ci && cp ./"${app}"/* ./"${app}"-ci && echo $?
cp -n ./* ./"${app}"-ci/ && echo $?
cd "${app}"-ci/ && pwd
if [ "$test" == "$FORKTESTFILE" ]; then
sed -i $sedfix 's/^system_coins_file=.*/system_coins_file="..\/system\/coins\/fork-test.sh"/g' system-fork-test.sh
if ! ./system-fork-test.sh "${PROJ}" "${app}"; then
exit 1
fi
elif [ "$test" == "$TESTCASEFILE" ]; then
if ! ./${DOCKER_COMPOSE_SH} "${PROJ}" "${app}"; then
exit 1
fi
fi
cd ..
echo "============ run dapp=$app end ================="
}
function run_single_app() {
app=$1
testfile=$2
if [ -d "${app}" ] && [ "${app}" != "system" ]; then
if [ -e "$app/$testfile" ]; then
run_dapp "${app}" "$testfile"
if [ "$#" -gt 2 ]; then
down_dapp "${app}"
fi
else
echo "#### dapp=$app not exist the test file: $testfile ####"
fi
else
echo "#### dapp=$app not exist or is system dir ####"
fi
}
function main() {
if [ "${OP}" == "run" ]; then
if [ "${DAPP}" == "all" ] || [ "${DAPP}" == "ALL" ]; then
echo "============ run main start ================="
if ! ./${DOCKER_COMPOSE_SH} "$PROJ"; then
exit 1
fi
./docker-compose-down.sh "$PROJ"
echo "============ run main end ================="
find . -maxdepth 1 -type d -name "*-ci" -exec rm -rf {} \;
dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///')
for app in $dir; do
run_single_app "${app}" "$TESTCASEFILE" "down"
done
elif [ -n "${DAPP}" ]; then
run_single_app "${DAPP}" "$TESTCASEFILE"
else
./${DOCKER_COMPOSE_SH} "${PROJ}"
fi
elif [ "${OP}" == "down" ]; then
if [ "${DAPP}" == "all" ] || [ "${DAPP}" == "ALL" ]; then
dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///')
for app in $dir; do
down_dapp "${app}"
done
./docker-compose-down.sh "${PROJ}"
elif [ -n "${DAPP}" ]; then
down_dapp "${DAPP}"
else
./docker-compose-down.sh "${PROJ}"
fi
elif [ "${OP}" == "forktest" ]; then
if [ "${DAPP}" == "all" ] || [ "${DAPP}" == "ALL" ]; then
echo "============ run main start ================="
if ! ./system-fork-test.sh "$PROJ"; then
exit 1
fi
echo "============ down main test ================="
./docker-compose-down.sh "$PROJ"
echo "============ run main end ================="
# remove all the *-ci folders
find . -maxdepth 1 -type d -name "*-ci" -exec rm -rf {} \;
dir=$(find . -maxdepth 1 -type d ! -name system ! -name . | sed 's/^\.\///')
for app in $dir; do
run_single_app "${app}" "$FORKTESTFILE" "down"
done
elif [ -n "${DAPP}" ]; then
run_single_app "${DAPP}" "$FORKTESTFILE"
else
./system-fork-test.sh "${PROJ}"
fi
fi
}
# run script
main
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
# os: ubuntu16.04 x64
# first, you must install jq tool of json
# sudo apt-get install jq
# sudo apt-get install shellcheck, in order to static check shell script
# sudo apt-get install parallel
# ./docker-compose.sh build
PWD=$(cd "$(dirname "$0")" && pwd)
export PATH="$PWD:$PATH"
NODE3="${1}_chain33_1"
CLI="docker exec ${NODE3} /root/chain33-cli"
NODE2="${1}_chain32_1"
NODE1="${1}_chain31_1"
NODE4="${1}_chain30_1"
NODE5="${1}_chain29_1"
CLI5="docker exec ${NODE5} /root/chain33-cli"
containers=("${NODE1}" "${NODE2}" "${NODE3}" "${NODE4}")
export COMPOSE_PROJECT_NAME="$1"
## global config ###
sedfix=""
if [ "$(uname)" == "Darwin" ]; then
sedfix=".bak"
fi
DAPP=""
if [ -n "${2}" ]; then
DAPP=$2
fi
DAPP_TEST_FILE=""
if [ -n "${DAPP}" ]; then
DAPP_TEST_FILE="testcase.sh"
if [ -e "$DAPP_TEST_FILE" ]; then
# shellcheck source=/dev/null
source "${DAPP_TEST_FILE}"
fi
DAPP_COMPOSE_FILE="docker-compose-${DAPP}.yml"
if [ -e "$DAPP_COMPOSE_FILE" ]; then
export COMPOSE_FILE="docker-compose.yml:${DAPP_COMPOSE_FILE}"
fi
fi
echo "=========== # env setting ============="
echo "DAPP=$DAPP"
echo "DAPP_TEST_FILE=$DAPP_TEST_FILE"
echo "COMPOSE_FILE=$COMPOSE_FILE"
echo "COMPOSE_PROJECT_NAME=$COMPOSE_PROJECT_NAME"
echo "CLI=$CLI"
####################
function base_init() {
# update test environment
sed -i $sedfix 's/^Title.*/Title="local"/g' chain33.toml
sed -i $sedfix 's/^TestNet=.*/TestNet=true/g' chain33.toml
# p2p
sed -i $sedfix 's/^seeds=.*/seeds=["chain33:13802","chain32:13802","chain31:13802"]/g' chain33.toml
#sed -i $sedfix 's/^enable=.*/enable=true/g' chain33.toml
sed -i $sedfix '0,/^enable=.*/s//enable=true/' chain33.toml
sed -i $sedfix 's/^isSeed=.*/isSeed=true/g' chain33.toml
sed -i $sedfix 's/^innerSeedEnable=.*/innerSeedEnable=false/g' chain33.toml
sed -i $sedfix 's/^useGithub=.*/useGithub=false/g' chain33.toml
# rpc
sed -i $sedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8801"/g' chain33.toml
sed -i $sedfix 's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8802"/g' chain33.toml
sed -i $sedfix 's/^whitelist=.*/whitelist=["localhost","127.0.0.1","0.0.0.0"]/g' chain33.toml
# wallet
sed -i $sedfix 's/^minerdisable=.*/minerdisable=false/g' chain33.toml
}
function start() {
echo "=========== # docker-compose ps ============="
docker-compose ps
# remove exsit container
docker-compose down
# create and run docker-compose container
#docker-compose -f docker-compose.yml -f docker-compose-paracross.yml -f docker-compose-relay.yml up --build -d
docker-compose up --build -d
local SLEEP=30
echo "=========== sleep ${SLEEP}s ============="
sleep ${SLEEP}
docker-compose ps
# query node run status
check_docker_status
${CLI} block last_header
${CLI} net info
${CLI} net peer_info
peersCount=$(${CLI} net peer_info | jq '.[] | length')
echo "${peersCount}"
if [ "${peersCount}" -lt 2 ]; then
sleep 20
peersCount=$(${CLI} net peer_info | jq '.[] | length')
echo "${peersCount}"
if [ "${peersCount}" -lt 2 ]; then
echo "peers error"
exit 1
fi
fi
#echo "=========== # create seed for wallet ============="
#seed=$(${CLI} seed generate -l 0 | jq ".seed")
#if [ -z "${seed}" ]; then
# echo "create seed error"
# exit 1
#fi
echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}"
exit 1
fi
sleep 1
echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then
exit 1
fi
sleep 1
echo "=========== # import private key returnAddr ============="
result=$(${CLI} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
sleep 1
echo "=========== # import private key mining ============="
result=$(${CLI} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
sleep 1
echo "=========== # close auto mining ============="
result=$(${CLI} wallet auto_mine -f 0 | jq ".isok")
if [ "${result}" = "false" ]; then
exit 1
fi
block_wait "${CLI}" 1
echo "=========== check genesis hash ========== "
${CLI} block hash -t 0
res=$(${CLI} block hash -t 0 | jq ".hash")
count=$(echo "$res" | grep -c "0x67c58d6ba9175313f0468ae4e0ddec946549af7748037c2fdd5d54298afd20b6")
if [ "${count}" != 1 ]; then
echo "genesis hash error!"
exit 1
fi
echo "=========== query height ========== "
${CLI} block last_header
result=$(${CLI} block last_header | jq ".height")
if [ "${result}" -lt 1 ]; then
block_wait "${CLI}" 2
fi
sync_status "${CLI}"
${CLI} wallet status
${CLI} account list
${CLI} mempool list
}
function block_wait() {
if [ "$#" -lt 2 ]; then
echo "wrong block_wait params"
exit 1
fi
cur_height=$(${1} block last_header | jq ".height")
expect=$((cur_height + ${2}))
count=0
while true; do
new_height=$(${1} block last_header | jq ".height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s, cur height=$expect,old=$cur_height"
}
function check_docker_status() {
status=$(docker-compose ps | grep chain33_1 | awk '{print $6}')
if [ "${status}" == "Exit" ]; then
echo "=========== chain33 service Exit logs ========== "
docker-compose logs chain33
echo "=========== chain33 service Exit logs End========== "
fi
}
function check_docker_container() {
echo "============== check_docker_container ==============================="
for con in "${containers[@]}"; do
runing=$(docker inspect "${con}" | jq '.[0].State.Running')
if [ ! "${runing}" ]; then
docker inspect "${con}"
echo "check ${con} not actived!"
exit 1
fi
done
}
function sync_status() {
echo "=========== query sync status========== "
local sync_status
local count=100
local wait_sec=0
while [ $count -gt 0 ]; do
sync_status=$(${1} net is_sync)
if [ "${sync_status}" = "true" ]; then
break
fi
((count--))
wait_sec=$((wait_sec + 1))
sleep 1
done
echo "sync wait ${wait_sec} s"
echo "=========== query clock sync status========== "
sync_status=$(${1} net is_clock_sync)
if [ "${sync_status}" = "false" ]; then
exit 1
fi
}
function sync() {
echo "=========== stop ${NODE5} node========== "
docker stop "${NODE5}"
sleep 10
echo "=========== start ${NODE5} node========== "
docker start "${NODE5}"
sleep 1
sync_status "${CLI5}"
}
function transfer() {
echo "=========== # transfer ============="
hashes=()
for ((i = 0; i < 10; i++)); do
hash=$(${CLI} send coins transfer -a 1 -n test -t 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01)
hashes=("${hashes[@]}" "$hash")
done
block_wait "${CLI}" 1
echo "len: ${#hashes[@]}"
if [ "${#hashes[@]}" != 10 ]; then
echo "tx number wrong"
exit 1
fi
for ((i = 0; i < ${#hashes[*]}; i++)); do
txs=$(${CLI} tx query_hash -s "${hashes[$i]}" | jq ".txs")
if [ -z "${txs}" ]; then
echo "cannot find tx"
exit 1
fi
done
echo "=========== # withdraw ============="
hash=$(${CLI} send coins transfer -a 2 -n deposit -t 1wvmD6RNHzwhY4eN75WnM6JcaAvNQ4nHx -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
echo "${hash}"
block_wait "${CLI}" 1
before=$(${CLI} account balance -a 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -e retrieve | jq -r ".balance")
if [ "${before}" == "0.0000" ]; then
echo "wrong ticket balance, should not be zero"
exit 1
fi
hash=$(${CLI} send coins withdraw -a 1 -n withdraw -e retrieve -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
echo "${hash}"
block_wait "${CLI}" 1
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "withdraw cannot find tx"
exit 1
fi
}
function base_config() {
sync
transfer
}
function dapp_run() {
if [ -e "$DAPP_TEST_FILE" ]; then
${DAPP} "${CLI}" "${1}"
fi
}
function main() {
echo "==============================DAPP=$DAPP main begin========================================================"
### init para ####
base_init
dapp_run init
### start docker ####
start
### config env ###
base_config
dapp_run config
### test cases ###
dapp_run test
### finish ###
check_docker_container
echo "===============================DAPP=$DAPP main end========================================================="
}
# run script
main
version: '3'
services:
chain33:
build:
context: .
chain32:
build:
context: .
chain31:
build:
context: .
chain30:
build:
context: .
chain29:
build:
context: .
chain28:
build:
context: .
This diff is collapsed.
FROM ubuntu:16.04
WORKDIR /root
COPY chain33 ./
COPY chain33-cli ./
COPY autotest ./
COPY *.toml ./
CMD ["/root/chain33", "-f", "/root/chain33.toml"]
version: '3'
services:
chain33:
build:
context: .
dockerfile: Dockerfile-autotest
container_name: autotest-chain33
chain32:
build:
context: .
dockerfile: Dockerfile-autotest
container_name: autotest-chain32
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
# os: ubuntu16.04 x64
# first, you must install jq tool of json
# sudo apt-get install jq
# sudo apt-get install shellcheck, in order to static check shell script
# sudo apt-get install parallel
PWD=$(cd "$(dirname "$0")" && pwd)
export PATH="$PWD:$PATH"
CLI="./chain33-cli"
sedfix=""
if [ "$(uname)" == "Darwin" ]; then
sedfix=".bak"
fi
chain33Config="chain33.test.toml"
chain33BlockTime=2
function init() {
# update test environment
echo "# copy chain33 for solo test"
cp ../../chain33 ./
cp ../../chain33-cli ./
cp ../../../cmd/chain33/chain33.test.toml ./
}
function config_chain33() {
# shellcheck disable=SC2015
echo "# config chain33 solo test"
# update test environment
sed -i $sedfix 's/^Title.*/Title="local"/g' ${chain33Config}
# grep -q '^TestNet' ${chain33Config} && sed -i $sedfix 's/^TestNet.*/TestNet=true/' ${chain33Config} || sed -i '/^Title/a TestNet=true' ${chain33Config}
if grep -q '^TestNet' ${chain33Config}; then
sed -i $sedfix 's/^TestNet.*/TestNet=true/' ${chain33Config}
else
sed -i $sedfix '/^Title/a TestNet=true' ${chain33Config}
fi
#update fee
sed -i $sedfix 's/Fee=.*/Fee=100000/' ${chain33Config}
#update block time
#update wallet store driver
sed -i $sedfix '/^\[wallet\]/,/^\[wallet./ s/^driver.*/driver="leveldb"/' ${chain33Config}
}
autotestConfig="autotest.toml"
autotestTempConfig="autotest.temp.toml"
function config_autotest() {
#delete all blank lines
echo "# config autotest"
sed -i $sedfix '/^\s*$/d' ${autotestConfig}
if [[ $1 == "" ]] || [[ $1 == "all" ]]; then
cp ${autotestConfig} ${autotestTempConfig}
else
#copy config before [
sed -n '/^\[/!p;//q' ${autotestConfig} >${autotestTempConfig}
#copy specific dapp cofig
for dapp in "$@"; do
{
echo "[[TestCaseFile]]"
echo "contract=\"$dapp\""
echo "filename=\"$dapp.toml\""
} >>${autotestTempConfig}
done
fi
sed -i $sedfix 's/^checkSleepTime.*/checkSleepTime='${chain33BlockTime}'/' ${autotestTempConfig}
}
function start_chain33() {
echo "# start solo chain33, make sure there is no chain33 instance running"
rm -rf ../autotest/datadir ../autotest/logs ../autotest/grpc33.log
./chain33 -f chain33.test.toml >/dev/null 2>&1 &
local SLEEP=5
echo "=========== sleep ${SLEEP}s ============="
sleep ${SLEEP}
# query node run status
${CLI} block last_header
echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}"
exit 1
fi
echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then
exit 1
fi
echo "=========== # import private key returnAddr ============="
result=$(${CLI} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import private key mining ============="
result=$(${CLI} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import test addr1 ============="
result=$(${CLI} account import_key -k 0x88b2fb90411935872f0501dd13345aba19b5fac9b00eb0dddd7df977d4d5477e -l test_addr1 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import test addr2 ============="
result=$(${CLI} account import_key -k 0xa0c6f46de8d275ce21e935afa5363e9b8a087fe604e05f7a9eef1258dc781c3a -l test_addr2 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import test addr3 ============="
result=$(${CLI} account import_key -k 0x9d4f8ab11361be596468b265cb66946c87873d4a119713fd0c3d8302eae0a8e4 -l test_addr3 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== #transfer to miner addr ============="
hash=$(${CLI} send coins transfer -a 10000 -n test -t 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
exit 1
fi
echo "=========== #transfer to token amdin ============="
hash=$(${CLI} send coins transfer -a 10 -n test -t 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944)
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
exit 1
fi
echo "=========== #config token blacklist ============="
rawData=$(${CLI} config config_tx -k token-blacklist -o add -v BTC)
signData=$(${CLI} wallet sign -d "${rawData}" -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
hash=$(${CLI} wallet send -d "${signData}")
sleep ${chain33BlockTime}
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
exit 1
fi
${CLI} wallet status
${CLI} account list
${CLI} mempool list
}
function start_autotest() {
echo "=========== #run autotest, make sure saving autotest.log.last file============="
if [ -e autotest.log ]; then
cat autotest.log >autotest.log.last
rm autotest.log
fi
./autotest -f ${autotestTempConfig}
}
function stop_chain33() {
echo "=========== #stop chain33 ============="
${CLI} close
#wait close
sleep ${chain33BlockTime}
}
function main() {
echo "==========================================main begin========================================================"
config_autotest "$@"
init
config_chain33
start_chain33
start_autotest
stop_chain33
echo "==========================================main end========================================================="
}
main "$@"
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
# os: ubuntu16.04 x64
# first, you must install jq tool of json
# sudo apt-get install jq
# sudo apt-get install shellcheck, in order to static check shell script
# sudo apt-get install parallel
# ./run-autotest.sh build
PWD=$(cd "$(dirname "$0")" && pwd)
export PATH="$PWD:$PATH"
PROJECT_NAME="${1}"
NODE3="autotest-chain33"
CLI="docker exec ${NODE3} /root/chain33-cli"
NODE2="autotest-chain32"
CLI2="docker exec ${NODE2} /root/chain33-cli"
sedfix=""
if [ "$(uname)" == "Darwin" ]; then
sedfix=".bak"
fi
function init() {
# update test environment
cp ../../chain33.toml ./
cp ../../chain33 ./
cp ../../chain33-cli ./
sed -i $sedfix 's/^Title.*/Title="local"/g' chain33.toml
sed -i $sedfix 's/^TestNet=.*/TestNet=true/g' chain33.toml
# p2p
sed -i $sedfix 's/^seeds=.*/seeds=["chain33:13802","chain32:13802"]/g' chain33.toml
#sed -i $sedfix 's/^enable=.*/enable=true/g' chain33.toml
sed -i $sedfix '0,/^enable=.*/s//enable=true/' chain33.toml
sed -i $sedfix 's/^isSeed=.*/isSeed=true/g' chain33.toml
sed -i $sedfix 's/^innerSeedEnable=.*/innerSeedEnable=false/g' chain33.toml
sed -i $sedfix 's/^useGithub=.*/useGithub=false/g' chain33.toml
# rpc
sed -i $sedfix 's/^jrpcBindAddr=.*/jrpcBindAddr="0.0.0.0:8801"/g' chain33.toml
sed -i $sedfix 's/^grpcBindAddr=.*/grpcBindAddr="0.0.0.0:8802"/g' chain33.toml
sed -i $sedfix 's/^whitelist=.*/whitelist=["localhost","127.0.0.1","0.0.0.0"]/g' chain33.toml
# wallet
sed -i $sedfix 's/^minerdisable=.*/minerdisable=false/g' chain33.toml
}
function start() {
# remove exsit container
docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml down --remove-orphans
# create and run docker-compose container
docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml up --build -d
local SLEEP=60
echo "=========== sleep ${SLEEP}s ============="
sleep ${SLEEP}
# docker-compose ps
docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml ps
# query node run status
${CLI} block last_header
${CLI} net info
${CLI} net peer_info
peersCount=$(${CLI} net peer_info | jq '.[] | length')
echo "${peersCount}"
if [ "${peersCount}" -lt 2 ]; then
echo "peers error"
exit 1
fi
#echo "=========== # create seed for wallet ============="
#seed=$(${CLI} seed generate -l 0 | jq ".seed")
#if [ -z "${seed}" ]; then
# echo "create seed error"
# exit 1
#fi
echo "=========== # save seed to wallet ============="
result=$(${CLI} seed save -p 1314 -s "tortoise main civil member grace happy century convince father cage beach hip maid merry rib" | jq ".isok")
if [ "${result}" = "false" ]; then
echo "save seed to wallet error seed, result: ${result}"
exit 1
fi
sleep 1
echo "=========== # unlock wallet ============="
result=$(${CLI} wallet unlock -p 1314 -t 0 | jq ".isok")
if [ "${result}" = "false" ]; then
exit 1
fi
echo "=========== # import private key returnAddr ============="
result=$(${CLI} account import_key -k CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944 -l returnAddr | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import private key mining ============="
result=$(${CLI} account import_key -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01 -l minerAddr | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import test addr1 ============="
result=$(${CLI} account import_key -k 0x88b2fb90411935872f0501dd13345aba19b5fac9b00eb0dddd7df977d4d5477e -l test_addr1 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import test addr2 ============="
result=$(${CLI} account import_key -k 0xa0c6f46de8d275ce21e935afa5363e9b8a087fe604e05f7a9eef1258dc781c3a -l test_addr2 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # import test addr3 ============="
result=$(${CLI} account import_key -k 0x9d4f8ab11361be596468b265cb66946c87873d4a119713fd0c3d8302eae0a8e4 -l test_addr3 | jq ".label")
echo "${result}"
if [ -z "${result}" ]; then
exit 1
fi
echo "=========== # close auto mining ============="
result=$(${CLI} wallet auto_mine -f 0 | jq ".isok")
if [ "${result}" = "false" ]; then
exit 1
fi
echo "=========== sleep ${SLEEP}s ============="
sleep ${SLEEP}
echo "=========== check genesis hash ========== "
${CLI} block hash -t 0
res=$(${CLI} block hash -t 0 | jq ".hash")
count=$(echo "$res" | grep -c "0x67c58d6ba9175313f0468ae4e0ddec946549af7748037c2fdd5d54298afd20b6")
if [ "${count}" != 1 ]; then
echo "genesis hash error!"
exit 1
fi
echo "=========== query height ========== "
${CLI} block last_header
result=$(${CLI} block last_header | jq ".height")
if [ "${result}" -lt 1 ]; then
exit 1
fi
sync_status "${CLI}"
${CLI} wallet status
${CLI} account list
${CLI} mempool list
}
function block_wait() {
if [ "$#" -lt 2 ]; then
echo "wrong block_wait params"
exit 1
fi
cur_height=$(${1} block last_header | jq ".height")
expect=$((cur_height + ${2}))
count=0
while true; do
new_height=$(${1} block last_header | jq ".height")
if [ "${new_height}" -ge "${expect}" ]; then
break
fi
count=$((count + 1))
sleep 1
done
echo "wait new block $count s"
}
function sync_status() {
echo "=========== query sync status========== "
local sync_status
local count=100
local wait_sec=0
while [ $count -gt 0 ]; do
sync_status=$(${1} net is_sync)
if [ "${sync_status}" = "true" ]; then
break
fi
((count--))
wait_sec=$((wait_sec + 1))
sleep 1
done
echo "sync wait ${wait_sec} s"
echo "=========== query clock sync status========== "
sync_status=$(${1} net is_clock_sync)
if [ "${sync_status}" = "false" ]; then
exit 1
fi
}
function sync() {
echo "=========== stop ${NODE2} node========== "
docker stop "${NODE2}"
sleep 20
echo "=========== start ${NODE2} node========== "
docker start "${NODE2}"
sleep 1
sync_status "${CLI2}"
}
function auto_test() {
echo "=========== #run auto test ============="
echo "=========== #transfer to token amdin ============="
hash=$(${CLI} send coins transfer -a 10 -n test -t 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK -k 4257D8692EF7FE13C68B65D6A52F03933DB2FA5CE8FAF210B5B8B80C721CED01)
block_wait "${CLI}" 2
txs=$(${CLI} tx query_hash -s "${hash}" | jq ".txs")
if [ "${txs}" == "null" ]; then
echo "transferTokenAdmin cannot find tx"
exit 1
fi
echo "=========== #config token blacklist ============="
rawData=$(${CLI} config config_tx -k token-blacklist -o add -v BTC)
signData=$(${CLI} wallet sign -d "${rawData}" -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc)
hash=$(${CLI} wallet send -d "${signData}")
block_wait "${CLI}" 2
echo "=========== #start auto-test program ============="
docker exec "${NODE3}" /root/autotest
}
function stop() {
echo "=========== #stop docker-compose ============="
docker cp "${NODE3}":/root/autotest.log ./
docker-compose -p "${PROJECT_NAME}" -f compose-autotest.yml down && rm ./chain33* && rm ./*.toml
}
function main() {
echo "==========================================main begin========================================================"
init
start
auto_test
stop
echo "==========================================main end========================================================="
}
# check args
if [ "$#" -ne 1 ]; then
echo "Suggest Usage: $0 build"
exit 1
fi
# run script
main
#!/bin/bash
#
# Code coverage generation
set -e -o pipefail
COVERAGE_DIR="${COVERAGE_DIR:-build/coverage}"
PKG_LIST=$(go list ./... | grep -v "vendor" | grep -v "chain33/test" | grep -v "mock" | grep -v "mocks" \
| grep -v "types" | grep -v "cmd" | grep -v "nat" | grep -v "pbft")
# Create the coverage files directory
mkdir -p "$COVERAGE_DIR"
# Create a coverage file for each package
for package in ${PKG_LIST}; do
go test -covermode=count -coverprofile "${COVERAGE_DIR}/${package##*/}.cov" "$package"
done
# Merge the coverage profile files
echo 'mode: count' >./coverage.cov
tail -q -n +2 "${COVERAGE_DIR}"/*.cov >>./coverage.cov
# Display the global code coverage
go tool cover -func=./coverage.cov
# If needed, generate HTML report
if [ "$1" == "html" ]; then
go tool cover -html=./coverage.cov -o coverage.html
fi
# Remove the coverage files directory
rm -rf "$COVERAGE_DIR"
package buildflags
var ParaName string
var RPCAddr string
...@@ -6,8 +6,13 @@ import ( ...@@ -6,8 +6,13 @@ import (
_ "gitlab.33.cn/chain33/chain33/system" _ "gitlab.33.cn/chain33/chain33/system"
"gitlab.33.cn/chain33/chain33/util/cli" "gitlab.33.cn/chain33/chain33/util/cli"
_ "gitlab.33.cn/chain33/plugin/plugin" _ "gitlab.33.cn/chain33/plugin/plugin"
"gitlab.33.cn/chain33/plugin/cli/buildflags"
) )
func main() { func main() {
cli.Run("", "") if buildflags.RPCAddr == "" {
buildflags.RPCAddr = "http://localhost:8801"
}
cli.Run(buildflags.RPCAddr, buildflags.ParaName)
} }
...@@ -8,7 +8,7 @@ OUT_DIR="${1}/$strapp" ...@@ -8,7 +8,7 @@ OUT_DIR="${1}/$strapp"
PARACLI="${OUT_DIR}/chain33-para-cli" PARACLI="${OUT_DIR}/chain33-para-cli"
PARANAME=para PARANAME=para
SRC_CLI=gitlab.33.cn/chain33/chain33/cmd/cli SRC_CLI=gitlab.33.cn/chain33/plugin/cli
go build -v -o "${PARACLI}" -ldflags "-X ${SRC_CLI}/buildflags.ParaName=user.p.${PARANAME}. -X ${SRC_CLI}/buildflags.RPCAddr=http://localhost:8901" "${SRC_CLI}" go build -v -o "${PARACLI}" -ldflags "-X ${SRC_CLI}/buildflags.ParaName=user.p.${PARANAME}. -X ${SRC_CLI}/buildflags.RPCAddr=http://localhost:8901" "${SRC_CLI}"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment