Commit 3faf2dca authored by harrylee's avatar harrylee Committed by vipwzw

update code for autotest

parent a7821a40
...@@ -26,12 +26,7 @@ build/para.sh ...@@ -26,12 +26,7 @@ build/para.sh
build/system-test-rpc.sh build/system-test-rpc.sh
build/ci build/ci
build/autotest/* build/autotest/*
!build/autotest/copy-autotest.sh
!build/autotest/build.sh !build/autotest/build.sh
!build/autotest/local/local-autotest.sh
!build/autotest/jerkinsci/*.yml
!build/autotest/jerkinsci/*.sh
!build/autotest/jerkinsci/Dockerfile-autotest
.DS_Store .DS_Store
logs/ logs/
build/wallet build/wallet
...@@ -52,4 +47,3 @@ build/sendstock ...@@ -52,4 +47,3 @@ build/sendstock
build/sendstock.toml build/sendstock.toml
build/*.csv build/*.csv
...@@ -46,20 +46,23 @@ vet: ...@@ -46,20 +46,23 @@ vet:
autotest: ## build autotest binary autotest: ## build autotest binary
@cd build/autotest && bash ./build.sh ${CHAIN33_PATH} && cd ../../ @cd build/autotest && bash ./build.sh ${CHAIN33_PATH} && cd ../../
@if [ -n "$(dapp)" ]; then \ @if [ -n "$(dapp)" ]; then \
# && rm -rf build/autotest/local \ chmod -R 755 build/autotest/local \
# && cp -r $(CHAIN33_PATH)/build/autotest/local $(CHAIN33_PATH)/build/autotest/*.sh build/autotest \ && rm -rf build/autotest/local \
cd build/autotest && chmod 755 local && bash ./copy-autotest.sh local \ && cp -r $(CHAIN33_PATH)/build/autotest/local $(CHAIN33_PATH)/build/autotest/*.sh build/autotest \
&& cd local && chmod 640 *.toml && bash ./local-autotest.sh $(dapp) \ && cd build/autotest && chmod -R 755 local && chmod 755 *.sh && bash ./copy-autotest.sh local \
&& cd local && bash ./local-autotest.sh $(dapp) \
&& cd ../../../; fi && cd ../../../; fi
autotest_ci: autotest ## autotest ci autotest_ci: autotest ## autotest ci
# @rm -rf build/autotest/jerkinsci \ @chmod -R 755 build/autotest/jerkinsci \
# && cp -r $(CHAIN33_PATH)/build/autotest/jerkinsci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \ && rm -rf build/autotest/jerkinsci \
cd build/autotest && bash ./copy-autotest.sh jerkinsci/temp$(proj) \ && cp -r $(CHAIN33_PATH)/build/autotest/jerkinsci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \
cd build/autotest &&chmod -R 755 jerkinsci && chmod 755 *.sh && bash ./copy-autotest.sh jerkinsci/temp$(proj) \
&& cd jerkinsci && bash ./jerkins-ci-autotest.sh $(proj) && cd ../../../ && cd jerkinsci && bash ./jerkins-ci-autotest.sh $(proj) && cd ../../../
autotest_tick: autotest ## run with ticket mining autotest_tick: autotest ## run with ticket mining
@rm -rf build/autotest/gitlabci \ @chmod -R 755 build/autotest/gitlabci \
&& rm -rf build/autotest/gitlabci \
&& cp -r $(CHAIN33_PATH)/build/autotest/gitlabci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \ && cp -r $(CHAIN33_PATH)/build/autotest/gitlabci $(CHAIN33_PATH)/build/autotest/*.sh build/autotest/ \
&& cd build/autotest && bash ./copy-autotest.sh gitlabci \ && cd build/autotest &&chmod -R 755 gitlabci && chmod 755 *.sh && bash ./copy-autotest.sh gitlabci \
&& cd gitlabci && bash ./gitlab-ci-autotest.sh build && cd ../../../ && cd gitlabci && bash ./gitlab-ci-autotest.sh build && cd ../../../
updatemod: updatemod:
......
...@@ -20,14 +20,20 @@ https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/6874 ...@@ -20,14 +20,20 @@ https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/6874
#### 支持make file的平台 #### 支持make file的平台
``` ```
// 开启mod功能
export GO111MODULE=on export GO111MODULE=on
//国内用户需要导入阿里云代理,用于下载依赖包
export GOPROXY=https://mirrors.aliyun.com/goproxy export GOPROXY=https://mirrors.aliyun.com/goproxy
make make
``` ```
就可以完成编译安装 就可以完成编译安装
```
注意:国内用户需要导入一下代理,才能获取依赖包,mod功能在Makefile中默认开启
```
## 运行 ## 运行
``` ```
......
#!/usr/bin/env bash
set -e
set -o pipefail
#set -o verbose
#set -o xtrace
# os: ubuntu16.04 x64
#chain33 dapp autotest root directory
declare -a Chain33AutoTestDirs=("system" "plugin" "vendor/github.com/33cn/chain33/system" "vendor/github.com/33cn/plugin/plugin")
#copy auto test to specific directory
# check args
if [ "$#" -lt 1 ]; then
echo "Usage: $0 directory list"
exit 1
fi
function copyAutoTestConfig() {
echo "#copy auto test config to path \"$1\""
local AutoTestConfigFile="$1/autotest.toml"
#pre config auto test
{
echo 'cliCmd="./chain33-cli"'
echo "checkTimeout=60"
} >"${AutoTestConfigFile}"
#copy all the dapp test case config file
for rootDir in "${Chain33AutoTestDirs[@]}"; do
if [ ! -d ../../"${rootDir}" ]; then
continue
fi
testDirArr=$(find ../../"${rootDir}" -type d -name autotest)
for autotest in ${testDirArr}; do
dapp=$(basename "$(dirname "${autotest}")")
dappConfig=${autotest}/${dapp}.toml
#make sure dapp have auto test config
if [ -e "${dappConfig}" ]; then
cp "${dappConfig}" "$1"/
#add dapp test case config
{
echo "[[TestCaseFile]]"
echo "dapp=\"$dapp\""
echo "filename=\"$dapp.toml\""
} >>"${AutoTestConfigFile}"
fi
done
done
}
function copyChain33() {
echo "# copy chain33 bin to path \"$1\", make sure build chain33"
cp ../chain33 ../chain33-cli ../chain33.toml "$1"
cp "${CHAIN33_PATH}"/cmd/chain33/chain33.test.toml "$1"
}
echo "=======CHAIN33_PATH:${CHAIN33_PATH}===="
for dir in "$@"; do
#check dir exist
if [ ! -d "${dir}" ]; then
mkdir "${dir}"
fi
cp autotest "${dir}"
copyAutoTestConfig "${dir}"
copyChain33 "${dir}"
echo "# all copy have done!"
done
...@@ -33,6 +33,7 @@ function down() { ...@@ -33,6 +33,7 @@ function down() {
# shellchk not recommend the first way # shellchk not recommend the first way
# remains=( $(docker-compose ps -q | awk '{print $1}') ) # remains=( $(docker-compose ps -q | awk '{print $1}') )
mapfile -t remains < <(docker-compose ps -q | awk '{print $1}') mapfile -t remains < <(docker-compose ps -q | awk '{print $1}')
# shellcheck disable=SC2154
num=${#remains[@]} num=${#remains[@]}
echo "container num=$num" echo "container num=$num"
if [ "$num" -gt 0 ]; then if [ "$num" -gt 0 ]; then
......
...@@ -3,7 +3,7 @@ module github.com/33cn/plugin ...@@ -3,7 +3,7 @@ module github.com/33cn/plugin
go 1.12 go 1.12
require ( require (
github.com/33cn/chain33 v0.0.0-20190818024326-42774b0804be github.com/33cn/chain33 v0.0.0-20190823042135-d05c4b3b53e3
github.com/BurntSushi/toml v0.3.1 github.com/BurntSushi/toml v0.3.1
github.com/NebulousLabs/Sia v1.3.7 github.com/NebulousLabs/Sia v1.3.7
github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac github.com/btcsuite/btcd v0.0.0-20181013004428-67e573d211ac
......
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v0.0.0-20190818024326-42774b0804be h1:CAwVuwS6AuKpws0EcughQYmwiplFcSF4WvAGSwtijQI= github.com/33cn/chain33 v0.0.0-20190823042135-d05c4b3b53e3 h1:MU2A1//oeTZPYXdn0kvwMDevQpboK469+xre8t5VYH4=
github.com/33cn/chain33 v0.0.0-20190818024326-42774b0804be/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ= github.com/33cn/chain33 v0.0.0-20190823042135-d05c4b3b53e3/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo= github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
......
...@@ -27,7 +27,7 @@ InitLog() { ...@@ -27,7 +27,7 @@ InitLog() {
Log() { Log() {
if [ -e ${log_file} ]; then if [ -e ${log_file} ]; then
$(touch ${log_file}) touch ${log_file}
fi fi
# get current time # get current time
local curtime local curtime
...@@ -46,35 +46,37 @@ GetInputFile() { ...@@ -46,35 +46,37 @@ GetInputFile() {
PackageFiles() { PackageFiles() {
Log "Begin to package the files: ${file}" Log "Begin to package the files: ${file}"
$(tar zcf ${package} $file) tar zcf "${package}" "$file"
} }
GetUserNamePasswdAndPath() { GetUserNamePasswdAndPath() {
echo "Which way to get environment? 1) Input 2) Config file" echo "Which way to get environment? 1) Input 2) Config file"
read choice read choice
if [ ${choice} -eq 1 ]; then if [ "${choice}" -eq 1 ]; then
echo 'Please input the username, password and path of the destination: (such as "ubuntu 123456 /home/ubuntu/chain33")' echo 'Please input the username, password and path of the destination: (such as "ubuntu 123456 /home/ubuntu/chain33")'
read destInfo read destInfo
username=$(echo ${destInfo} | awk -F ' ' '{print $1}') username=$(echo "${destInfo}" | awk -F ' ' '{print $1}')
password=$(echo ${destInfo} | awk -F ' ' '{print $2}') password=$(echo "${destInfo}" | awk -F ' ' '{print $2}')
remote_dir=$(echo ${destInfo} | awk -F ' ' '{print $3}') remote_dir=$(echo "${destInfo}" | awk -F ' ' '{print $3}')
echo 'Please input ip list of your destination: (such as "192.168.3.143 192.168.3.144 192.168.3.145 192.168.3.146")' echo 'Please input ip list of your destination: (such as "192.168.3.143 192.168.3.144 192.168.3.145 192.168.3.146")'
read iplist read iplist
index=0 index=0
CreateNewConfigFile CreateNewConfigFile
for ip in $(echo ${iplist}); do for ip in "${iplist}"; do
index=$(expr $index + 1) index=$((index + 1))
echo "[servers.${index}]" >>${config_file} {
echo "userName:${username}" >>${config_file} echo "[servers.${index}]"
echo "password:${password}" >>${config_file} echo "userName:${username}"
echo "hostIp:${ip}" >>${config_file} echo "password:${password}"
echo "path:${remote_dir}" >>${config_file} echo "hostIp:${ip}"
echo "path:${remote_dir}"
} >>${config_file}
done done
Log "The dest ip is ${ip} and path is ${remote_dir}" Log "The dest ip is ${ip} and path is ${remote_dir}"
elif [ ${choice} -eq 2 ]; then elif [ "${choice}" -eq 2 ]; then
ShowConfigInfo ShowConfigInfo
echo "Does the config of destination right?(yes/no)" echo "Does the config of destination right?(yes/no)"
...@@ -83,7 +85,7 @@ GetUserNamePasswdAndPath() { ...@@ -83,7 +85,7 @@ GetUserNamePasswdAndPath() {
echo "The config file is wrong. You can config it manually." echo "The config file is wrong. You can config it manually."
return 1 return 1
fi fi
elif [ ${choice} -eq 3 ]; then elif [ "${choice}" -eq 3 ]; then
echo "Wrong input..." echo "Wrong input..."
return 2 return 2
fi fi
...@@ -96,14 +98,14 @@ SendFileAndDecompressFile() { ...@@ -96,14 +98,14 @@ SendFileAndDecompressFile() {
for line in $sections; do for line in $sections; do
if [[ $line =~ $serverStr ]]; then if [[ $line =~ $serverStr ]]; then
index=$(echo $line | awk -F '.' '{print $2}' | awk -F ']' '{print$1}') index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey $index "userName" getInfoByIndexAndKey "$index" "userName"
username=${info} username=${info}
getInfoByIndexAndKey $index "password" getInfoByIndexAndKey "$index" "password"
password=${info} password=${info}
getInfoByIndexAndKey $index "hostIp" getInfoByIndexAndKey "$index" "hostIp"
ip=${info} ip=${info}
getInfoByIndexAndKey $index "path" getInfoByIndexAndKey "$index" "path"
remote_dir=${info} remote_dir=${info}
ExpectCmd "scp ${package} ${username}@${ip}:${remote_dir}" ExpectCmd "scp ${package} ${username}@${ip}:${remote_dir}"
...@@ -125,8 +127,8 @@ ExpectCmd() { ...@@ -125,8 +127,8 @@ ExpectCmd() {
expect -c " expect -c "
spawn ${cmd} spawn ${cmd}
expect { expect {
"yes" { send "yes\\r"; exp_continue } \"yes\" { send \"yes\\r\"; exp_continue }
"password" { send "$password\\r" } \"password\" { send \"${password}\\r\"}
} }
expect eof" expect eof"
} }
...@@ -149,14 +151,14 @@ ShowConfigInfo() { ...@@ -149,14 +151,14 @@ ShowConfigInfo() {
for line in $sections; do for line in $sections; do
if [[ $line =~ $serverStr ]]; then if [[ $line =~ $serverStr ]]; then
index=$(echo $line | awk -F '.' '{print $2}' | awk -F ']' '{print$1}') index=$(echo "$line" | awk -F '.' '{print $2}' | awk -F ']' '{print$1}')
getInfoByIndexAndKey $index "userName" getInfoByIndexAndKey "$index" "userName"
echo "servers.$index: userName->$info" echo "servers.$index: userName->$info"
getInfoByIndexAndKey $index "password" getInfoByIndexAndKey "$index" "password"
echo "servers.$index: password->$info" echo "servers.$index: password->$info"
getInfoByIndexAndKey $index "hostIp" getInfoByIndexAndKey "$index" "hostIp"
echo "servers.$index: hostIp->$info" echo "servers.$index: hostIp->$info"
getInfoByIndexAndKey $index "path" getInfoByIndexAndKey "$index" "path"
echo "servers.$index: path->$info" echo "servers.$index: path->$info"
fi fi
done done
...@@ -168,15 +170,15 @@ getSections() { ...@@ -168,15 +170,15 @@ getSections() {
getInfoByIndex() { getInfoByIndex() {
index=$1 index=$1
nextIndex=$(expr ${index} + 1) nextIndex=$((index + 1))
info=$(cat ${config_file} | sed -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p") info=$(sed <${config_file} -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p")
} }
getInfoByIndexAndKey() { getInfoByIndexAndKey() {
index=$1 index=$1
nextIndex=$(expr ${index} + 1) nextIndex=$((index + 1))
key=$2 key=$2
info=$(cat ${config_file} | sed -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p" | grep -i $key | awk -F ':' '{print $2}') info=$(sed <${config_file} -n "/^[# ]*\[servers.${index}/,/^[# ]*\[servers.${nextIndex}/p" | grep -i "$key" | awk -F ':' '{print $2}')
} }
help() { help() {
......
...@@ -515,7 +515,7 @@ func TestListProposalComment(t *testing.T) { ...@@ -515,7 +515,7 @@ func TestListProposalComment(t *testing.T) {
} }
for _, tcase := range testcase { for _, tcase := range testcase {
key := calcCommentHeight(tcase.propID, key := calcCommentHeight(tcase.propID,
dapp.HeightIndexStr(tcase.height, int64(tcase.index))) dapp.HeightIndexStr(tcase.height, tcase.index))
cur.Height = tcase.height cur.Height = tcase.height
cur.Index = int32(tcase.index) cur.Index = int32(tcase.index)
value := types.Encode(cur) value := types.Encode(cur)
......
...@@ -565,7 +565,7 @@ func TestDelMavlData(t *testing.T) { ...@@ -565,7 +565,7 @@ func TestDelMavlData(t *testing.T) {
db := store.GetDB() db := store.GetDB()
db.Set([]byte(mvccPrefix), []byte("value1")) db.Set(mvccPrefix, []byte("value1"))
db.Set([]byte(fmt.Sprintf("%s123", mvccPrefix)), []byte("value2")) db.Set([]byte(fmt.Sprintf("%s123", mvccPrefix)), []byte("value2"))
db.Set([]byte(fmt.Sprintf("%s546", mvccPrefix)), []byte("value3")) db.Set([]byte(fmt.Sprintf("%s546", mvccPrefix)), []byte("value3"))
db.Set([]byte(fmt.Sprintf("123%s", mvccPrefix)), []byte("value4")) db.Set([]byte(fmt.Sprintf("123%s", mvccPrefix)), []byte("value4"))
...@@ -582,7 +582,7 @@ func TestDelMavlData(t *testing.T) { ...@@ -582,7 +582,7 @@ func TestDelMavlData(t *testing.T) {
} }
} }
v, err := db.Get([]byte(mvccPrefix)) v, err := db.Get(mvccPrefix)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, []byte("value1"), v) require.Equal(t, []byte("value1"), v)
v, err = db.Get([]byte(fmt.Sprintf("%s123", mvccPrefix))) v, err = db.Get([]byte(fmt.Sprintf("%s123", mvccPrefix)))
...@@ -760,7 +760,7 @@ func TestDeletePrunedMavl(t *testing.T) { ...@@ -760,7 +760,7 @@ func TestDeletePrunedMavl(t *testing.T) {
v1, err = store.GetDB().Get([]byte(fmt.Sprintln(hashNodePrefix, "456"))) v1, err = store.GetDB().Get([]byte(fmt.Sprintln(hashNodePrefix, "456")))
require.Error(t, err) require.Error(t, err)
require.Equal(t, v1, []uint8([]byte(nil))) require.Equal(t, v1, []byte(nil))
v2, err := store.GetDB().Get([]byte(fmt.Sprintln(hashNodePrefix, "123"))) v2, err := store.GetDB().Get([]byte(fmt.Sprintln(hashNodePrefix, "123")))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, v2, []byte("v1")) require.Equal(t, v2, []byte("v1"))
......
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